forked from hwchase17/chat-your-data
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_data.py
44 lines (38 loc) · 1.45 KB
/
query_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from langchain import LLMChain, OpenAI
from langchain.agents import AgentExecutor, ZeroShotAgent
from langchain.chains.conversation.memory import ConversationBufferMemory
def load_front_agent(tools):
prefix = """Answer a question about {interviewee_name} as best you can.
If a question is not about {interviewee_name}, answer 'I think your question is not about {interviewee_name}.
answer very politely so that people will like {interviewee_name}.
You have access to the following tools:"""
suffix = """Begin! Remember to answer very politely so that people will like {interviewee_name}.
Previous conversation history:
{chat_history}
Question: {input}
{agent_scratchpad}"""
prompt = ZeroShotAgent.create_prompt(
tools,
prefix=prefix,
suffix=suffix,
input_variables=[
"input",
"agent_scratchpad",
"interviewee_name",
"chat_history",
],
)
memory = ConversationBufferMemory(
memory_key="chat_history", input_key="input", output_key="output"
)
llm = OpenAI(temperature=0)
llm_chain = LLMChain(llm=llm, prompt=prompt)
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools)
agent_executor = AgentExecutor.from_agent_and_tools(
agent=agent,
tools=tools,
verbose=True,
memory=memory,
return_intermediate_steps=True,
)
return agent_executor