iShare commited on
Commit
c2e68b6
·
1 Parent(s): 35f4127

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py CHANGED
@@ -100,6 +100,67 @@ agent = initialize_agent(
100
  #handle_parsing_errors="You must take care of the user input query and if you cannot find an answer by yourself, use the tools and then response based on the search results by the tools and make a perfect response to user query.")
101
  #self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  def chat_response(input_text):
104
  print("START PRINTING")
105
  #response = my_agent.run(input=input_text)
 
100
  #handle_parsing_errors="You must take care of the user input query and if you cannot find an answer by yourself, use the tools and then response based on the search results by the tools and make a perfect response to user query.")
101
  #self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
102
 
103
+ B_INST, E_INST = "[INST]", "[/INST]"
104
+ B_SYS, E_SYS = "<>\n", "\n<>\n\n"
105
+
106
+ sys_msg = B_SYS + """Assistant is a expert JSON builder designed to assist with a wide range of tasks.
107
+
108
+ Assistant is able to respond to the User and use tools using JSON strings that contain "action" and "action_input" parameters.
109
+
110
+ All of Assistant's communication is performed using this JSON format.
111
+
112
+ Assistant can also use tools by responding to the user with tool use instructions in the same "action" and "action_input" JSON format. Tools available to Assistant are:
113
+
114
+ - "Calculator": Useful for when you need to answer questions about math.
115
+ - To use the calculator tool, Assistant should write like so:
116
+ ```json
117
+ {{"action": "Calculator",
118
+ "action_input": "sqrt(4)"}}
119
+ ```
120
+
121
+ Here are some previous conversations between the Assistant and User:
122
+
123
+ User: Hey how are you today?
124
+ Assistant: ```json
125
+ {{"action": "Final Answer",
126
+ "action_input": "I'm good thanks, how are you?"}}
127
+ ```
128
+ User: I'm great, what is the square root of 4?
129
+ Assistant: ```json
130
+ {{"action": "Calculator",
131
+ "action_input": "sqrt(4)"}}
132
+ ```
133
+ User: 2.0
134
+ Assistant: ```json
135
+ {{"action": "Final Answer",
136
+ "action_input": "It looks like the answer is 2!"}}
137
+ ```
138
+ User: Thanks could you tell me what 4 to the power of 2 is?
139
+ Assistant: ```json
140
+ {{"action": "Calculator",
141
+ "action_input": "4**2"}}
142
+ ```
143
+ User: 16.0
144
+ Assistant: ```json
145
+ {{"action": "Final Answer",
146
+ "action_input": "It looks like the answer is 16!"}}
147
+ ```
148
+
149
+ Here is the latest conversation between Assistant and User.""" + E_SYS
150
+ new_prompt = agent.agent.create_prompt(
151
+ system_message=sys_msg,
152
+ tools=tools
153
+ )
154
+ agent.agent.llm_chain.prompt = new_prompt
155
+
156
+ instruction = B_INST + " Respond to the following in JSON with 'action' and 'action_input' values " + E_INST
157
+ human_msg = instruction + "\nUser: {input}"
158
+
159
+ agent.agent.llm_chain.prompt.messages[2].prompt.template = human_msg
160
+
161
+ result=agent("hey how are you today?")
162
+ print("Result: "+result)
163
+
164
  def chat_response(input_text):
165
  print("START PRINTING")
166
  #response = my_agent.run(input=input_text)