Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
#https://python.langchain.com/docs/integrations/tools/search_tools
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
from langchain.agents import Tool
|
|
@@ -25,7 +28,7 @@ GS_tool =Tool(
|
|
| 25 |
)
|
| 26 |
|
| 27 |
|
| 28 |
-
|
| 29 |
#tools = load_tools(["google-search"], llm=llm)
|
| 30 |
#load_tools要么针对自定义的tools有效,要么针对Langchain预定义的tools有效,但是对于后者,其名称是给定的!比如GoogleSearchAPIWrapper必须是"google-search"
|
| 31 |
#如果想以自定义名称的方式引用tools,则必须使用类似tools = [search, random_tool, life_tool]这种格式
|
|
@@ -36,10 +39,11 @@ GS_tool =Tool(
|
|
| 36 |
|
| 37 |
|
| 38 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 39 |
-
llm=ChatOpenAI(temperature=0)
|
| 40 |
#tools = load_tools(["google-search"], llm=llm)
|
| 41 |
tools = [GS_tool]
|
| 42 |
-
my_agent = initialize_agent(tools, llm, agent="chat-conversational-react-description", verbose=True, memory=memory) #有记忆功能!
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
#agent_response = my_agent.run("Who is older in 2023? Biden or Putin?")
|
|
|
|
| 1 |
#https://python.langchain.com/docs/integrations/tools/search_tools
|
| 2 |
+
#https://python.langchain.com/docs/modules/agents/agent_types/chat_conversation_agent
|
| 3 |
+
#根据这个,llm也可以和记忆搭配使用啊?!
|
| 4 |
+
|
| 5 |
import os
|
| 6 |
import gradio as gr
|
| 7 |
from langchain.agents import Tool
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
+
llm=OpenAI()
|
| 32 |
#tools = load_tools(["google-search"], llm=llm)
|
| 33 |
#load_tools要么针对自定义的tools有效,要么针对Langchain预定义的tools有效,但是对于后者,其名称是给定的!比如GoogleSearchAPIWrapper必须是"google-search"
|
| 34 |
#如果想以自定义名称的方式引用tools,则必须使用类似tools = [search, random_tool, life_tool]这种格式
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 42 |
+
#llm=ChatOpenAI(temperature=0)
|
| 43 |
#tools = load_tools(["google-search"], llm=llm)
|
| 44 |
tools = [GS_tool]
|
| 45 |
+
#my_agent = initialize_agent(tools, llm, agent="chat-conversational-react-description", verbose=True, memory=memory) #有记忆功能!
|
| 46 |
+
my_agent = initialize_agent(tools, llm, agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION, verbose=True, memory=memory)
|
| 47 |
|
| 48 |
|
| 49 |
#agent_response = my_agent.run("Who is older in 2023? Biden or Putin?")
|