Spaces:
Sleeping
Sleeping
update prompt
Browse files- chatbot_simulator.py +36 -31
chatbot_simulator.py
CHANGED
@@ -95,30 +95,30 @@ Rules:
|
|
95 |
|
96 |
# Update user state using GPT's response
|
97 |
update_prompt = f"""
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
"""
|
123 |
|
124 |
self.conversation.append({"role": "assistant", "content": update_prompt})
|
@@ -129,7 +129,12 @@ Rules:
|
|
129 |
|
130 |
if isinstance(updated_state, list):
|
131 |
reformat_prompt = f'''
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
133 |
'''
|
134 |
reformat_state = self._get_openai_response([{"role": "assistant", "content": reformat_prompt}])
|
135 |
updated_state = json_repair.loads(reformat_state)
|
@@ -153,12 +158,12 @@ Rules:
|
|
153 |
Simulate the agent generating input based on the conversation state.
|
154 |
"""
|
155 |
agent_prompt = f"""
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
"""
|
163 |
|
164 |
messages = [{"role": "system", "content": agent_prompt}]
|
|
|
95 |
|
96 |
# Update user state using GPT's response
|
97 |
update_prompt = f"""
|
98 |
+
Update the user state based on user input: '{user_input}' and task: {self.task}
|
99 |
+
|
100 |
+
Current user state (JSON format): {self.user_state}
|
101 |
+
|
102 |
+
Sitemap: {self.sitemap}
|
103 |
+
|
104 |
+
Instructions:
|
105 |
+
1. If the 'current_page' has changed, update it to a page from the sitemap.
|
106 |
+
2. If the task is finished, update 'task_completed' to 1. Otherwise, leave it unchanged.
|
107 |
+
3. If no updates are needed, return the user state exactly as provided, without modification.
|
108 |
+
4. Preserve the **exact JSON structure** and **format** of the provided user state.
|
109 |
+
5. The output **must be a single JSON dictionary** representing the updated user state—do not wrap it in a list.
|
110 |
+
6. Do not change any other fields unless explicitly required by the instructions.
|
111 |
+
|
112 |
+
Important:
|
113 |
+
- Ensure 'current_page' and 'task_completed' are keys in the returned dictionary.
|
114 |
+
- Return **only the JSON object** without additional output or wrapping.
|
115 |
+
- **AVOID OUTPUT A LIST**, must be JSON!
|
116 |
+
|
117 |
+
Example Format:
|
118 |
+
{{
|
119 |
+
'current_page': 'Home',
|
120 |
+
'task_completed': 0,
|
121 |
+
}}
|
122 |
"""
|
123 |
|
124 |
self.conversation.append({"role": "assistant", "content": update_prompt})
|
|
|
129 |
|
130 |
if isinstance(updated_state, list):
|
131 |
reformat_prompt = f'''
|
132 |
+
Given the {updated_state}, reformat it into a proper JSON.
|
133 |
+
Make sure follow the format:
|
134 |
+
{{
|
135 |
+
'current_page': 'Home',
|
136 |
+
'task_completed': 0,
|
137 |
+
}}
|
138 |
'''
|
139 |
reformat_state = self._get_openai_response([{"role": "assistant", "content": reformat_prompt}])
|
140 |
updated_state = json_repair.loads(reformat_state)
|
|
|
158 |
Simulate the agent generating input based on the conversation state.
|
159 |
"""
|
160 |
agent_prompt = f"""
|
161 |
+
Imagine you are an agent navigate through the Uber environment.
|
162 |
+
Your overarching task is: {self.task}. You may have done some part of the task, or none at all.
|
163 |
+
You will have access to all of your previous actions in the environment, as well as the last message from the assistant giving the current state of the environment.
|
164 |
+
The last message from the assistant was: {self.conversation[-1]['content']}
|
165 |
+
Respond first with a brief "Plan" which suggests what steps you are going to take to accomplish the task, and what your immediate.
|
166 |
+
Then generate an "Action" which is the immediate next step you can take.
|
167 |
"""
|
168 |
|
169 |
messages = [{"role": "system", "content": agent_prompt}]
|