Closed mrunhap closed 6 months ago
@mrunhap Can you try with latest version : langchain-google-genai-1.0.5 ?
I'm able to successfully run the below code
I try google's package and langchain_google_genai for chat and embedding, only langchain's embedding not work, here my example code:
import google.generativeai as genai from langchain_google_genai import GoogleGenerativeAI, GoogleGenerativeAIEmbeddings key = "my-key" genai.configure(api_key=key) def gemini_chat(): model = genai.GenerativeModel("gemini-pro") response = model.generate_content("Write a story about a magic backpack.") print(response.text) def gemini_embed(): result = genai.embed_content( model="models/embedding-001", content="What is the meaning of life?", task_type="retrieval_document", title="Embedding of single string", ) # 1 input > 1 vector output print(str(result["embedding"])[:50], "... TRIMMED]") def langchain_chat(): chat_model = GoogleGenerativeAI(model="gemini-pro", google_api_key=key) res = chat_model.invoke("Write a story about a magic backpack.") print(res) def langchain_embed(): embeddings = GoogleGenerativeAIEmbeddings( model="models/embedding-001", google_api_key=key, ) print("------------------") print(embeddings.embed_query("What is the meaning of life?")) # # print("------------------") # print(embeddings.embed_documents( # [ # "Today is Monday", # "Today is Tuesday", # "Today is April Fools day", # ] # )) # gemini_chat() # gemini_embed() # langchain_chat() # FIXME 504 langchain_embed()
@Adi8885 I checked pip freeze
and langchain-google-genai
version is 1.0.5
, maybe it's a network problem? But google's python package ebmedding worked 🤔
And I see other people get this error too:
https://www.reddit.com/r/AskProgramming/comments/1bk0e4h/gemini_api_giving_504_deadline_exceeded/
I give up on this, have to create a custom class with genai instead.
I try google's package and langchain_google_genai for chat and embedding, only langchain's embedding not work, here my example code:
And log:
I also try add request option and config a larger timeout but it won't work too.