Spaces:
Sleeping
Sleeping
fix error: Invalid type for messages[0]
Browse files- app.py +2 -2
- chatbot_simulator.py +20 -7
app.py
CHANGED
@@ -78,8 +78,8 @@ with gr.Blocks(fill_height=True) as demo:
|
|
78 |
|
79 |
# Input fields for initialization
|
80 |
task_input = gr.Textbox(label="Task", placeholder="Describe your task...")
|
81 |
-
app_name_input = gr.Textbox(label="App Name", placeholder="Enter the app name...")
|
82 |
-
sitemap_input = gr.Textbox(label="Sitemap", placeholder="Enter the Hugging Face link to sitemap...")
|
83 |
initialize_button = gr.Button("Initialize Simulator")
|
84 |
|
85 |
# Status block to display initialization progress with elapsed time
|
|
|
78 |
|
79 |
# Input fields for initialization
|
80 |
task_input = gr.Textbox(label="Task", placeholder="Describe your task...")
|
81 |
+
app_name_input = gr.Textbox(label="App Name", placeholder="Enter the app name... (eg. DoorDash)")
|
82 |
+
sitemap_input = gr.Textbox(label="Sitemap", placeholder="Enter the Hugging Face link to sitemap... (eg.jjz5463/DoorDash_synthetic_sitemap)")
|
83 |
initialize_button = gr.Button("Initialize Simulator")
|
84 |
|
85 |
# Status block to display initialization progress with elapsed time
|
chatbot_simulator.py
CHANGED
@@ -77,13 +77,26 @@ Rules:
|
|
77 |
def _get_openai_response(self, prompt):
|
78 |
"""Fetch response from OpenAI API."""
|
79 |
self._trim_conversation()
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
def _calculate_token_count(self, conversation):
|
89 |
"""Accurately calculate the token count in the conversation using a tokenizer."""
|
|
|
77 |
def _get_openai_response(self, prompt):
|
78 |
"""Fetch response from OpenAI API."""
|
79 |
self._trim_conversation()
|
80 |
+
while True:
|
81 |
+
try:
|
82 |
+
response = self.client.chat.completions.create(
|
83 |
+
model="gpt-4",
|
84 |
+
messages=prompt,
|
85 |
+
max_tokens=self.buffer_tokens, # Adjusted max_tokens if needed
|
86 |
+
temperature=0.7,
|
87 |
+
)
|
88 |
+
return response.choices[0].message.content
|
89 |
+
except RateLimitError as e:
|
90 |
+
# Parse the suggested retry time from the error message, default to 5s if not available
|
91 |
+
wait_time = 5
|
92 |
+
try:
|
93 |
+
# Attempt to get the time from the error message
|
94 |
+
wait_time = float(e.response['error']['message'].split("in ")[1].split("s")[0])
|
95 |
+
except (KeyError, IndexError, ValueError):
|
96 |
+
print("Could not parse wait time from error message. Defaulting to 5 seconds.")
|
97 |
+
|
98 |
+
print(f"Rate limit reached. Retrying in {wait_time} seconds...")
|
99 |
+
time.sleep(wait_time)
|
100 |
|
101 |
def _calculate_token_count(self, conversation):
|
102 |
"""Accurately calculate the token count in the conversation using a tokenizer."""
|