From e392829ac4f113057fd8020c456d06243a51c596 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Tue, 5 Mar 2024 16:37:22 -0800 Subject: [PATCH 1/9] Add Gemini Provider --- .../jupyter_ai_magics/__init__.py | 1 + .../jupyter_ai_magics/providers.py | 16 ++++++++++++++++ packages/jupyter-ai-magics/pyproject.toml | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py b/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py index a8f4225de..9553efab2 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py @@ -30,6 +30,7 @@ QianfanProvider, SmEndpointProvider, TogetherAIProvider, + GeminiAIProvider, ) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py index eda848b87..996f4b464 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py @@ -39,6 +39,7 @@ SagemakerEndpoint, Together, ) +from langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAI # this is necessary because `langchain.pydantic_v1.main` does not include # `ModelMetaclass`, as it is not listed in `__all__` by the `pydantic.main` @@ -900,3 +901,18 @@ class QianfanProvider(BaseProvider, QianfanChatEndpoint): model_id_key = "model_name" pypi_package_deps = ["qianfan"] auth_strategy = MultiEnvAuthStrategy(names=["QIANFAN_AK", "QIANFAN_SK"]) + + +class GeminiProvider(BaseProvider, GoogleGenerativeAI): + id = "gemini" + name = "Gemini" + models = [ + "gemini-pro", + ] + model_id_key = "model" + pypi_package_deps = ["langchain-google-genai"] + auth_strategy = EnvAuthStrategy(name="GOOGLE_API_KEY") + + @classmethod + def is_api_key_exc(cls, e: Exception): + return False diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index ec0af6ba2..89c0a31d0 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -47,7 +47,7 @@ all = [ "boto3", "qianfan", "together", - + "langchain_google_genai", ] [project.entry-points."jupyter_ai.model_providers"] @@ -66,6 +66,7 @@ amazon-bedrock-chat = "jupyter_ai_magics:BedrockChatProvider" qianfan = "jupyter_ai_magics:QianfanProvider" nvidia-chat = "jupyter_ai_magics.partner_providers.nvidia:ChatNVIDIAProvider" together-ai = "jupyter_ai_magics:TogetherAIProvider" +gemini = "jupyter_ai_magics:GeminiProvider" [project.entry-points."jupyter_ai.embeddings_model_providers"] bedrock = "jupyter_ai_magics:BedrockEmbeddingsProvider" From 81c9ad2f7d92bfbb5be4f14508e4e17fcce3a443 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Tue, 5 Mar 2024 16:38:53 -0800 Subject: [PATCH 2/9] Rename GeminiAI --- packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py b/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py index 9553efab2..8178e1179 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py @@ -30,7 +30,7 @@ QianfanProvider, SmEndpointProvider, TogetherAIProvider, - GeminiAIProvider, + GeminiProvider, ) From c243591360ca034ca55609e5f9e1f6d3ad522ec6 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 2 Mar 2024 23:25:22 -0500 Subject: [PATCH 3/9] Use VertexAI --- packages/jupyter-ai-magics/jupyter_ai_magics/providers.py | 8 ++++---- packages/jupyter-ai-magics/pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py index 996f4b464..099409c53 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py @@ -39,7 +39,7 @@ SagemakerEndpoint, Together, ) -from langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAI +from langchain_google_vertexai import VertexAI # this is necessary because `langchain.pydantic_v1.main` does not include # `ModelMetaclass`, as it is not listed in `__all__` by the `pydantic.main` @@ -903,14 +903,14 @@ class QianfanProvider(BaseProvider, QianfanChatEndpoint): auth_strategy = MultiEnvAuthStrategy(names=["QIANFAN_AK", "QIANFAN_SK"]) -class GeminiProvider(BaseProvider, GoogleGenerativeAI): +class GeminiProvider(BaseProvider, VertexAI): id = "gemini" name = "Gemini" models = [ "gemini-pro", ] - model_id_key = "model" - pypi_package_deps = ["langchain-google-genai"] + model_id_key = "model_name" + pypi_package_deps = ["langchain-google-vertexai"] auth_strategy = EnvAuthStrategy(name="GOOGLE_API_KEY") @classmethod diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index 89c0a31d0..556fe4a7c 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -47,7 +47,7 @@ all = [ "boto3", "qianfan", "together", - "langchain_google_genai", + "langchain-google-vertexai", ] [project.entry-points."jupyter_ai.model_providers"] From ab9e1025e0af931c2a017d4c129c679e8b8187f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Mar 2024 04:27:59 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py b/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py index 8178e1179..a8f4225de 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py @@ -30,7 +30,6 @@ QianfanProvider, SmEndpointProvider, TogetherAIProvider, - GeminiProvider, ) From b6aa5eda4dfaef26948d0d2b2c35ad0f83729976 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Sat, 2 Mar 2024 23:56:13 -0500 Subject: [PATCH 5/9] Change back to langchain-google-genai --- packages/jupyter-ai-magics/jupyter_ai_magics/providers.py | 6 +++--- packages/jupyter-ai-magics/pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py index 099409c53..f787067fd 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py @@ -39,7 +39,7 @@ SagemakerEndpoint, Together, ) -from langchain_google_vertexai import VertexAI +from langchain_google_genai import GoogleGenerativeAI # this is necessary because `langchain.pydantic_v1.main` does not include # `ModelMetaclass`, as it is not listed in `__all__` by the `pydantic.main` @@ -903,14 +903,14 @@ class QianfanProvider(BaseProvider, QianfanChatEndpoint): auth_strategy = MultiEnvAuthStrategy(names=["QIANFAN_AK", "QIANFAN_SK"]) -class GeminiProvider(BaseProvider, VertexAI): +class GeminiProvider(BaseProvider, GoogleGenerativeAI): id = "gemini" name = "Gemini" models = [ "gemini-pro", ] model_id_key = "model_name" - pypi_package_deps = ["langchain-google-vertexai"] + pypi_package_deps = ["langchain-google-genai"] auth_strategy = EnvAuthStrategy(name="GOOGLE_API_KEY") @classmethod diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index 556fe4a7c..4e92bd688 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -47,7 +47,7 @@ all = [ "boto3", "qianfan", "together", - "langchain-google-vertexai", + "langchain-google-genai", ] [project.entry-points."jupyter_ai.model_providers"] From b263690e44948202eecea3092aff429ac7f25606 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Tue, 5 Mar 2024 13:36:26 -0500 Subject: [PATCH 6/9] Add gemini as a partner provider --- .../partner_providers/gemini.py | 13 +++++++++++++ .../jupyter_ai_magics/providers.py | 17 +---------------- packages/jupyter-ai-magics/pyproject.toml | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py new file mode 100644 index 000000000..d56d30e91 --- /dev/null +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py @@ -0,0 +1,13 @@ +from jupyter_ai_magics.providers import BaseProvider, EnvAuthStrategy +from langchain_google_genai import GoogleGenerativeAI + + +class GeminiProvider(BaseProvider, GoogleGenerativeAI): + id = "gemini" + name = "Gemini" + models = [ + "gemini-pro", + ] + model_id_key = "model" + auth_strategy = EnvAuthStrategy(name="GOOGLE_API_KEY") + pypi_package_deps = ["langchain-google-genai"] diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py index f787067fd..dfaaf8356 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py @@ -39,7 +39,7 @@ SagemakerEndpoint, Together, ) -from langchain_google_genai import GoogleGenerativeAI + # this is necessary because `langchain.pydantic_v1.main` does not include # `ModelMetaclass`, as it is not listed in `__all__` by the `pydantic.main` @@ -901,18 +901,3 @@ class QianfanProvider(BaseProvider, QianfanChatEndpoint): model_id_key = "model_name" pypi_package_deps = ["qianfan"] auth_strategy = MultiEnvAuthStrategy(names=["QIANFAN_AK", "QIANFAN_SK"]) - - -class GeminiProvider(BaseProvider, GoogleGenerativeAI): - id = "gemini" - name = "Gemini" - models = [ - "gemini-pro", - ] - model_id_key = "model_name" - pypi_package_deps = ["langchain-google-genai"] - auth_strategy = EnvAuthStrategy(name="GOOGLE_API_KEY") - - @classmethod - def is_api_key_exc(cls, e: Exception): - return False diff --git a/packages/jupyter-ai-magics/pyproject.toml b/packages/jupyter-ai-magics/pyproject.toml index 4e92bd688..f6637d36c 100644 --- a/packages/jupyter-ai-magics/pyproject.toml +++ b/packages/jupyter-ai-magics/pyproject.toml @@ -66,7 +66,7 @@ amazon-bedrock-chat = "jupyter_ai_magics:BedrockChatProvider" qianfan = "jupyter_ai_magics:QianfanProvider" nvidia-chat = "jupyter_ai_magics.partner_providers.nvidia:ChatNVIDIAProvider" together-ai = "jupyter_ai_magics:TogetherAIProvider" -gemini = "jupyter_ai_magics:GeminiProvider" +gemini = "jupyter_ai_magics.partner_providers.gemini:GeminiProvider" [project.entry-points."jupyter_ai.embeddings_model_providers"] bedrock = "jupyter_ai_magics:BedrockEmbeddingsProvider" From 3bd207d2152d9287348f3c08950a04ac23d75de8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:36:45 +0000 Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- packages/jupyter-ai-magics/jupyter_ai_magics/providers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py index dfaaf8356..eda848b87 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/providers.py @@ -40,7 +40,6 @@ Together, ) - # this is necessary because `langchain.pydantic_v1.main` does not include # `ModelMetaclass`, as it is not listed in `__all__` by the `pydantic.main` # subpackage. From 7290ca8daa722ad20c6ad764d74936fa7b026c85 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Tue, 5 Mar 2024 15:30:16 -0500 Subject: [PATCH 8/9] Add more gemini models --- .../jupyter_ai_magics/partner_providers/gemini.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py index d56d30e91..c52e7ebdb 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/partner_providers/gemini.py @@ -6,7 +6,12 @@ class GeminiProvider(BaseProvider, GoogleGenerativeAI): id = "gemini" name = "Gemini" models = [ + "gemini-1.0-pro", + "gemini-1.0-pro-001", + "gemini-1.0-pro-latest", + "gemini-1.0-pro-vision-latest", "gemini-pro", + "gemini-pro-vision", ] model_id_key = "model" auth_strategy = EnvAuthStrategy(name="GOOGLE_API_KEY") From 5aa4151589b31fd9ca7731bd247fd1c62d4fd8b8 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Tue, 5 Mar 2024 18:43:03 -0500 Subject: [PATCH 9/9] Add Gemini to docs --- README.md | 2 +- docs/source/index.md | 2 +- docs/source/users/index.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 407bbef01..3b15e5079 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ in JupyterLab and the Jupyter Notebook. More specifically, Jupyter AI offers: This works anywhere the IPython kernel runs (JupyterLab, Jupyter Notebook, Google Colab, Kaggle, VSCode, etc.). * A native chat UI in JupyterLab that enables you to work with generative AI as a conversational assistant. * Support for a wide range of generative model providers, including AI21, Anthropic, AWS, Cohere, - Hugging Face, NVIDIA, and OpenAI. + Gemini, Hugging Face, NVIDIA, and OpenAI. * Local model support through GPT4All, enabling use of generative AI models on consumer grade machines with ease and privacy. diff --git a/docs/source/index.md b/docs/source/index.md index 8d70538e3..a2c060f6a 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -8,7 +8,7 @@ in JupyterLab and the Jupyter Notebook. More specifically, Jupyter AI offers: This works anywhere the IPython kernel runs (JupyterLab, Jupyter Notebook, Google Colab, VSCode, etc.). * A native chat UI in JupyterLab that enables you to work with generative AI as a conversational assistant. * Support for a wide range of generative model providers and models - (AI21, Anthropic, Cohere, Hugging Face, OpenAI, SageMaker, NVIDIA, etc.). + (AI21, Anthropic, Cohere, Gemini, Hugging Face, OpenAI, SageMaker, NVIDIA, etc.).