Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GEMINI Pro langchain genai support #207

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions backend/app/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class AgentType(str, Enum):
AZURE_OPENAI = "GPT 4 (Azure OpenAI)"
CLAUDE2 = "Claude 2"
BEDROCK_CLAUDE2 = "Claude 2 (Amazon Bedrock)"
GEMINI = "GEMINI"
GEMINI = "GEMINI (VertexAI)"
GEMINI_GENAI = "GEMINI (GenAI)"


DEFAULT_SYSTEM_MESSAGE = "You are a helpful assistant."
Expand Down Expand Up @@ -81,6 +82,11 @@ def get_agent_executor(
return get_google_agent_executor(
tools, llm, system_message, interrupt_before_action, CHECKPOINTER
)
elif agent == AgentType.GEMINI_GENAI:
llm = get_google_llm(genai=True)
return get_google_agent_executor(
tools, llm, system_message, interrupt_before_action, CHECKPOINTER
)
else:
raise ValueError("Unexpected agent type")

Expand Down Expand Up @@ -143,7 +149,8 @@ class LLMType(str, Enum):
AZURE_OPENAI = "GPT 4 (Azure OpenAI)"
CLAUDE2 = "Claude 2"
BEDROCK_CLAUDE2 = "Claude 2 (Amazon Bedrock)"
GEMINI = "GEMINI"
GEMINI = "GEMINI (VertexAI)"
GEMINI_GENAI = "GEMINI (GenAI)"
MIXTRAL = "Mixtral"


Expand All @@ -163,6 +170,8 @@ def get_chatbot(
llm = get_anthropic_llm(bedrock=True)
elif llm_type == LLMType.GEMINI:
llm = get_google_llm()
elif llm_type == LLMType.GEMINI_GENAI:
llm = get_google_llm(genai=True)
elif llm_type == LLMType.MIXTRAL:
llm = get_mixtral_fireworks()
else:
Expand Down Expand Up @@ -236,6 +245,8 @@ def __init__(
llm = get_anthropic_llm(bedrock=True)
elif llm_type == LLMType.GEMINI:
llm = get_google_llm()
elif llm_type == LLMType.GEMINI_GENAI:
llm = get_google_llm(genai=True)
elif llm_type == LLMType.MIXTRAL:
llm = get_mixtral_fireworks()
else:
Expand Down
7 changes: 6 additions & 1 deletion backend/app/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import boto3
from langchain_community.chat_models import BedrockChat, ChatAnthropic, ChatFireworks
from langchain_google_vertexai import ChatVertexAI
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_openai import AzureChatOpenAI, ChatOpenAI

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -66,7 +67,11 @@ def get_anthropic_llm(bedrock: bool = False):


@lru_cache(maxsize=1)
def get_google_llm():
def get_google_llm(genai: bool = False):
if genai:
return ChatGoogleGenerativeAI(
model="gemini-pro", convert_system_message_to_human=True
)
return ChatVertexAI(
model_name="gemini-pro", convert_system_message_to_human=True, streaming=True
)
Expand Down
57 changes: 56 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 83 additions & 82 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
[tool.poetry]
name = "opengpts"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{include = "app"}]

[tool.poetry.dependencies]
python = "^3.9.0"
sse-starlette = "^1.6.5"
tomli-w = "^1.0.0"
uvicorn = "^0.23.2"
fastapi = "^0.103.2"
langserve = "0.0.32"
# Uncomment if you need to work from a development branch
# This will only work for local development though!
# langchain = { git = "[email protected]:langchain-ai/langchain.git/", branch = "nc/subclass-runnable-binding" , subdirectory = "libs/langchain"}
orjson = "^3.9.10"
redis = "^5.0.1"
python-multipart = "^0.0.6"
tiktoken = "^0.5.1"
langchain = ">=0.0.338"
langgraph = "^0.0.23"
pydantic = "<2.0"
python-magic = "^0.4.27"
langchain-openai = "^0.0.5"
beautifulsoup4 = "^4.12.3"
boto3 = "^1.34.28"
duckduckgo-search = "^4.2"
arxiv = "^2.1.0"
kay = "^0.1.2"
xmltodict = "^0.13.0"
wikipedia = "^1.4.0"
langchain-google-vertexai = "^0.0.3"
setuptools = "^69.0.3"
pdfminer-six = "^20231228"
langchain-robocorp = "^0.0.3"
fireworks-ai = "^0.11.2"
anthropic = "^0.13.0"
httpx = { version = "0.25.2", extras = ["socks"] }

[tool.poetry.group.dev.dependencies]
uvicorn = "^0.23.2"
pygithub = "^2.1.1"

[tool.poetry.group.lint.dependencies]
ruff = "^0.1.4"
codespell = "^2.2.0"

[tool.poetry.group.test.dependencies]
pytest = "^7.2.1"
pytest-cov = "^4.0.0"
pytest-asyncio = "^0.21.1"
pytest-mock = "^3.11.1"
pytest-socket = "^0.6.0"
pytest-watch = "^4.2.0"
pytest-timeout = "^2.2.0"

[tool.coverage.run]
omit = [
"tests/*",
]

[tool.pytest.ini_options]
# --strict-markers will raise errors on unknown marks.
# https://docs.pytest.org/en/7.1.x/how-to/mark.html#raising-errors-on-unknown-marks
#
# https://docs.pytest.org/en/7.1.x/reference/reference.html
# --strict-config any warnings encountered while parsing the `pytest`
# section of the configuration file raise errors.
addopts = "--strict-markers --strict-config --durations=5 -vv"
# Use global timeout of 30 seconds for now.
# Most tests should be closer to ~100 ms, but some of the tests involve
# parsing files. We can adjust on a per test basis later on.
timeout = 30
asyncio_mode = "auto"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "opengpts"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{include = "app"}]

[tool.poetry.dependencies]
python = "^3.9.0"
sse-starlette = "^1.6.5"
tomli-w = "^1.0.0"
uvicorn = "^0.23.2"
fastapi = "^0.103.2"
langserve = "0.0.32"
# Uncomment if you need to work from a development branch
# This will only work for local development though!
# langchain = { git = "[email protected]:langchain-ai/langchain.git/", branch = "nc/subclass-runnable-binding" , subdirectory = "libs/langchain"}
orjson = "^3.9.10"
redis = "^5.0.1"
python-multipart = "^0.0.6"
tiktoken = "^0.5.1"
langchain = ">=0.0.338"
langgraph = "^0.0.23"
pydantic = "<2.0"
python-magic = "^0.4.27"
langchain-openai = "^0.0.5"
beautifulsoup4 = "^4.12.3"
boto3 = "^1.34.28"
duckduckgo-search = "^4.2"
arxiv = "^2.1.0"
kay = "^0.1.2"
xmltodict = "^0.13.0"
wikipedia = "^1.4.0"
langchain-google-vertexai = "^0.0.3"
setuptools = "^69.0.3"
pdfminer-six = "^20231228"
langchain-robocorp = "^0.0.3"
fireworks-ai = "^0.11.2"
anthropic = "^0.13.0"
httpx = { version = "0.25.2", extras = ["socks"] }
langchain-google-genai = "0.0.9"

[tool.poetry.group.dev.dependencies]
uvicorn = "^0.23.2"
pygithub = "^2.1.1"

[tool.poetry.group.lint.dependencies]
ruff = "^0.1.4"
codespell = "^2.2.0"

[tool.poetry.group.test.dependencies]
pytest = "^7.2.1"
pytest-cov = "^4.0.0"
pytest-asyncio = "^0.21.1"
pytest-mock = "^3.11.1"
pytest-socket = "^0.6.0"
pytest-watch = "^4.2.0"
pytest-timeout = "^2.2.0"

[tool.coverage.run]
omit = [
"tests/*",
]

[tool.pytest.ini_options]
# --strict-markers will raise errors on unknown marks.
# https://docs.pytest.org/en/7.1.x/how-to/mark.html#raising-errors-on-unknown-marks
#
# https://docs.pytest.org/en/7.1.x/reference/reference.html
# --strict-config any warnings encountered while parsing the `pytest`
# section of the configuration file raise errors.
addopts = "--strict-markers --strict-config --durations=5 -vv"
# Use global timeout of 30 seconds for now.
# Most tests should be closer to ~100 ms, but some of the tests involve
# parsing files. We can adjust on a per test basis later on.
timeout = 30
asyncio_mode = "auto"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a wholesale replacement of pyproject.toml. Can you limit it to only necessary changes or explain why a wholesale replacement is needed?