aakash0563 commited on
Commit
70e3e32
1 Parent(s): 8d52d3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -2,27 +2,28 @@ import gradio as gr
2
  from langchain_google_genai import ChatGoogleGenerativeAI
3
  from langchain.memory import ConversationBufferMemory
4
  from langchain.chains import ConversationChain
5
- from langchain.agents import AgentExecutor, Tool, ZeroShotAgent
6
  from langchain.chains import LLMChain
7
  from langchain_community.utilities import GoogleSearchAPIWrapper
8
  import os
9
 
10
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
 
11
 
12
  llm = ChatGoogleGenerativeAI(
13
  google_api_key=GOOGLE_API_KEY,
14
  model="gemini-pro",
15
  temperature=0.7
16
  )
17
-
18
- search = GoogleSearchAPIWrapper()
19
- tools = [
20
- Tool(
21
- name="Search",
22
- func=search.run,
23
- description="useful for when you need to answer questions about current events",
24
- )
25
- ]
26
 
27
  prefix = """Have a conversation with a human, answering the following questions as best you can. You have access to the following tools:"""
28
  suffix = """Begin!"
@@ -53,7 +54,7 @@ agent_chain = AgentExecutor.from_agent_and_tools(
53
  # )
54
  def chat(prompt):
55
  res = agent_chain.run(input=prompt)
56
- return res, agent_chain.memory.chat_memory.messages
57
 
58
  iface = gr.Interface(
59
  fn=chat,
 
2
  from langchain_google_genai import ChatGoogleGenerativeAI
3
  from langchain.memory import ConversationBufferMemory
4
  from langchain.chains import ConversationChain
5
+ from langchain.agents import AgentExecutor, Tool, ZeroShotAgent, load_tools
6
  from langchain.chains import LLMChain
7
  from langchain_community.utilities import GoogleSearchAPIWrapper
8
  import os
9
 
10
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
11
+ SERPAPI_API_KEY = os.getenv("SERPAPI_API_KEY")
12
 
13
  llm = ChatGoogleGenerativeAI(
14
  google_api_key=GOOGLE_API_KEY,
15
  model="gemini-pro",
16
  temperature=0.7
17
  )
18
+ tools = load_tools(['serpapi','wikipedia','llm-math'], llm=llm)
19
+ # search = GoogleSearchAPIWrapper()
20
+ # tools = [
21
+ # Tool(
22
+ # name="Search",
23
+ # func=search.run,
24
+ # description="useful for when you need to answer questions about current events",
25
+ # )
26
+ # ]
27
 
28
  prefix = """Have a conversation with a human, answering the following questions as best you can. You have access to the following tools:"""
29
  suffix = """Begin!"
 
54
  # )
55
  def chat(prompt):
56
  res = agent_chain.run(input=prompt)
57
+ return res,"ChatHistory" #agent_chain.memory.chat_memory.messages
58
 
59
  iface = gr.Interface(
60
  fn=chat,