langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.1k stars 14.97k forks source link

Accessing Gemini though Vertex AI SDK #15431

Closed jaymon0703 closed 9 months ago

jaymon0703 commented 9 months ago

Feature request

Gemini API is not available in Canada, but i believe it is available through vertexai.preview.generative_models in pre-GA mode.

Would it be possible to add a feature using the Vertex AI SDK instead of Gemini API, which i assume is what it is using?

Motivation

Canada access to Gemini through Langchain

Your contribution

I could test?

dosubot[bot] commented 9 months ago

🤖

Hello @jaymon0703! :wave: I'm Dosu, a friendly bot here to assist you with any LangChain related queries, bug reports or suggestions while we wait for a human maintainer. I'm here to make your contribution process smoother and faster! :robot: Let's solve some code mysteries together! :detective:

Based on the context provided, it seems that LangChain already has modules for Google Vertex AI, including GoogleVertexAISearchRetriever, GoogleVertexAIMultiTurnSearchRetriever, and GoogleCloudEnterpriseSearchRetriever. These modules can be used to integrate Vertex AI SDK into LangChain. Here is the relevant code:

from langchain_community.retrievers.google_vertex_ai_search import (
    GoogleCloudEnterpriseSearchRetriever,
    GoogleVertexAIMultiTurnSearchRetriever,
    GoogleVertexAISearchRetriever,
)

__all__ = [
    "GoogleVertexAISearchRetriever",
    "GoogleVertexAIMultiTurnSearchRetriever",
    "GoogleCloudEnterpriseSearchRetriever",
]

You can find this in the libs/langchain/langchain/retrievers/google_vertex_ai_search.py file.

As for the Gemini API, LangChain does not currently use it for any of its functionalities. The current method of accessing the Gemini API in LangChain is through the classes provided in the langchain_google_genai module. Here is an example of how it's used:

from langchain_google_genai import ChatGoogleGenerativeAI

llm = ChatGoogleGenerativeAI(model="gemini-pro")
llm.invoke("Sing a ballad of LangChain.")

You can find this in the libs/partners/google-genai/langchain_google_genai/init.py file.

Given this information, it seems feasible to add a feature to LangChain that uses the Vertex AI SDK instead of the Gemini API to allow access from Canada. However, this would require a significant amount of work to ensure compatibility and stability. If you're interested in contributing to this feature, testing would indeed be a valuable contribution. Please let me know if you need any further information or assistance.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

lkuligin commented 9 months ago

You can try it with VertexAI model if you have a GCP project enabled.

Examples: https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm#setting-up https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm#multimodality

jaymon0703 commented 9 months ago

Thank you @lkuligin that works...closing this issue