100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.
[Gemini_agentic_rag] [ApiPatch] Migrate deprecated google.generativeai API calls (1 file)
Morad Moqbelbcb0a68290ce
diff --git a/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py b/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.pyindex b27ac888..f906983d 100644--- a/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py+++ b/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py@@ -4,7 +4,7 @@ from datetime import datetimefrom typing import Listimport streamlit as st-import google.generativeai as genai+from google import genaiimport bs4from agno.agent import Agentfrom agno.models.google import Gemini@@ -19,14 +19,17 @@ from agno.tools.exa import ExaToolsclass GeminiEmbedder(Embeddings):def __init__(self, model_name="models/text-embedding-004"):- genai.configure(api_key=st.session_state.google_api_key)+ # Initialize the new genai client here+ if not st.session_state.google_api_key:+ raise ValueError("Google API Key not set in session state.")+ self.client = genai.Client(api_key=st.session_state.google_api_key)self.model = model_namedef embed_documents(self, texts: List[str]) -> List[List[float]]:return [self.embed_query(text) for text in texts]def embed_query(self, text: str) -> List[float]:- response = genai.embed_content(+ response = self.client.models.embed_content(model=self.model,content=text,task_type="retrieval_document"@@ -319,7 +322,6 @@ def check_document_relevance(query: str, vector_store, threshold: float = 0.7) -# Main Application Flowif st.session_state.google_api_key:os.environ["GOOGLE_API_KEY"] = st.session_state.google_api_key- genai.configure(api_key=st.session_state.google_api_key)qdrant_client = init_qdrant()@@ -470,4 +472,4 @@ Please provide a comprehensive answer based on the available information."""st.error(f"❌ Error generating response: {str(e)}")else:- st.warning("⚠️ Please enter your Google API Key to continue")\ No newline at end of file+ st.warning("⚠️ Please enter your Google API Key to continue")