sonald commited on
Commit
66dc027
1 Parent(s): 731907d
Files changed (1) hide show
  1. app.py +4 -39
app.py CHANGED
@@ -11,45 +11,7 @@ import os
11
 
12
  from langchain.chains import LLMMathChain, SQLDatabaseChain
13
  from langchain.agents import Tool, load_tools, initialize_agent, AgentType
14
-
15
- def conversation_agent():
16
- model = OpenAI(openai_api_key=os.environ['OPENAI_API_KEY'])
17
- tools = load_tools(['llm-math', 'terminal'], llm=model)
18
-
19
- prompt = PromptTemplate(template="{question}", input_variables=['question'])
20
- llm_chain = LLMChain(llm=model, prompt=prompt)
21
- llm_tool = Tool(name="Search", func=llm_chain.run, description="general QA")
22
- tools.append(llm_tool)
23
-
24
- memory = ConversationBufferMemory(memory_key="chat_history")
25
- conversation_agent = initialize_agent(tools=tools,
26
- llm=model,
27
- max_iterations=3,
28
- verbose=True,
29
- agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
30
- memory=memory)
31
- resp = conversation_agent("what is (4.5*2.1)^2.2?")
32
- print(resp)
33
-
34
- # resp = conversation_agent("if Mary has four apples and Giorgio brings two and a half apple "
35
- # "boxes (apple box contains eight apples), how many apples do we "
36
- # "have?")
37
- # print(resp)
38
-
39
- resp = conversation_agent("what is the capital of Norway?")
40
- print(resp)
41
-
42
- resp = conversation_agent("what's the most famous landmark of this city")
43
- print(resp)
44
-
45
- resp = conversation_agent("free -h")
46
- print(resp)
47
-
48
- print("--------")
49
- print(conversation_agent.agent.llm_chain.prompt.template)
50
-
51
  from langchain.agents.react.base import DocstoreExplorer
52
- from langchain.docstore import Wikipedia
53
 
54
  import gradio as gr
55
 
@@ -77,7 +39,10 @@ def demo8():
77
  print(f"resp: {resp}")
78
  history.append(resp['output'])
79
  dial = [(u, v) for u, v in zip(history[::2], history[1::2])]
80
- return dial, history
 
 
 
81
 
82
 
83
  with gr.Blocks() as demo:
 
11
 
12
  from langchain.chains import LLMMathChain, SQLDatabaseChain
13
  from langchain.agents import Tool, load_tools, initialize_agent, AgentType
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  from langchain.agents.react.base import DocstoreExplorer
 
15
 
16
  import gradio as gr
17
 
 
39
  print(f"resp: {resp}")
40
  history.append(resp['output'])
41
  dial = [(u, v) for u, v in zip(history[::2], history[1::2])]
42
+ return {
43
+ chatbot: dial,
44
+ state: history
45
+ }
46
 
47
 
48
  with gr.Blocks() as demo: