skkjodhpur commited on
Commit
7d3f212
·
verified ·
1 Parent(s): 74125bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  from langchain_google_genai import GoogleGenerativeAIEmbeddings, ChatGoogleGenerativeAI
4
  from langchain_community.agent_toolkits.load_tools import load_tools
5
  from langchain.agents import create_react_agent
6
- from langchain.prompts import PromptTemplate # Import PromptTemplate
7
 
8
  # Set up Google API keys from environment variables
9
  GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
@@ -20,10 +20,16 @@ llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro")
20
  # Load tools
21
  tools = load_tools(["serpapi", "llm-math"], llm=llm, serpapi_api_key=SERPER_API_KEY)
22
 
23
- # Define a prompt using PromptTemplate
24
  prompt = PromptTemplate(
25
- input_variables=["query"],
26
- template="You are a helpful assistant that answers questions based on the provided tools. Question: {query}"
 
 
 
 
 
 
27
  )
28
 
29
  # Initialize the agent with the prompt
 
3
  from langchain_google_genai import GoogleGenerativeAIEmbeddings, ChatGoogleGenerativeAI
4
  from langchain_community.agent_toolkits.load_tools import load_tools
5
  from langchain.agents import create_react_agent
6
+ from langchain.prompts import PromptTemplate
7
 
8
  # Set up Google API keys from environment variables
9
  GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
 
20
  # Load tools
21
  tools = load_tools(["serpapi", "llm-math"], llm=llm, serpapi_api_key=SERPER_API_KEY)
22
 
23
+ # Define a prompt using PromptTemplate with required variables
24
  prompt = PromptTemplate(
25
+ input_variables=["query", "agent_scratchpad", "tools", "tool_names"],
26
+ template=(
27
+ "You are a helpful assistant that answers questions based on the provided tools.\n"
28
+ "Tools available: {tool_names}\n"
29
+ "Current tools: {tools}\n"
30
+ "Scratchpad: {agent_scratchpad}\n"
31
+ "Question: {query}"
32
+ )
33
  )
34
 
35
  # Initialize the agent with the prompt