Open KallieLev opened 5 months ago
🤖
The error you're encountering is likely due to a change in the LangChain framework or the Google GenerativeAI module between versions. In the provided context, there is no mention of a 'generate_content' attribute in the 'google.generativeai' module.
The GoogleGenerativeAI class in LangChain uses the 'invoke' method to generate text, as shown in the example:
from langchain_google_genai import GoogleGenerativeAI
llm = GoogleGenerativeAI(model="gemini-pro")
llm.invoke("Once upon a time, a library called LangChain")
If you're trying to use a 'generate_content' method, it might have been deprecated or renamed in the newer versions of LangChain or the Google GenerativeAI module. You should check the documentation or source code of these modules to verify the available methods and their usage.
If 'generate_content' was a method in an older version of LangChain or Google GenerativeAI, you might need to update your script to use the 'invoke' method instead, or any other method that replaces 'generate_content' in the newer versions.
Regarding the changes between LangChain versions 0.1.0 and 0.1.1, the AttributeError could have been caused by the relocation of the "create_spark_dataframe_agent" from the main LangChain package to the experimental package. In version 0.1.1, an ImportError is raised when trying to access this agent, indicating that it has been moved to "langchain_experimental".
To resolve this, you need to install the langchain experimental package and update your import statement from the old path to the new path. The old path is "langchain." + here + "." + name and the new path is "langchain_experimental." + here + "." + name.
Here is the relevant code snippet:
if name == "create_spark_dataframe_agent":
HERE = Path(__file__).parents[3]
here = as_import_path(Path(__file__).parent, relative_to=HERE)
old_path = "langchain." + here + "." + name
new_path = "langchain_experimental." + here + "." + name
raise ImportError(
"This agent has been moved to langchain experiment. "
"This agent relies on python REPL tool under the hood, so to use it "
"safely please sandbox the python REPL. "
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
"and https://github.com/langchain-ai/langchain/discussions/11680"
"To keep using this code as is, install langchain experimental and "
f"update your import statement from:\n `{old_path}` to `{new_path}`."
)
You can find more details in the LangChain repository.
Hi @KallieLev ,
I think this is not exactly the issue with Langchain, but rather a wide issue with everyone building on Google APIs. So earlier, for using Google's Palm model the methods used to be different. However with the introduction of Gemini model APIs, Google has updated its method and the way we interact with these LLMs.
Based on what you have mentioned above, I believe these methods are available for Google Gemini models, but not for Palm. In that case either you can try using Gemini models with the above code, or try to update/use the correct LLM wrapper for Palm API's.
In case if the above is the right diagnosis, I can take up and work on this issue further.
I believe this is an issue with Langchain since from a certain Langchain version this functionality doesn't work anymore, while Google's package hasn't changed. This means that the Langchain usage has been broken with Google's package since version 0.1.1. Also, if there's an incompatibility between Langchain and certain Google models, I would have expected this to be mentioned in the docs.
Checked other resources
Example Code
This the prompt template I used -
Error Message and Stack Trace (if applicable)
Description
I'm creating an AgentExecutor with Google GenerativeAI llm, but since version
0.1.1
oflangchain
, I receive this error. Iflangchain <= 0.1.0
, this script works.System Info