ignore queries too long
Browse files
app.py
CHANGED
@@ -87,11 +87,14 @@ def ask(query, timeout=600):
|
|
87 |
attempt_times = 0
|
88 |
while answer is None and time.time()<dead_time and attempt_times<10:
|
89 |
try:
|
|
|
|
|
|
|
|
|
|
|
90 |
answer = openai.ChatCompletion.create(
|
91 |
model="gpt-3.5-turbo",
|
92 |
-
messages=
|
93 |
-
{"role": "user", "content": query}
|
94 |
-
]
|
95 |
)["choices"][0]["message"]["content"]
|
96 |
except Exception as e:
|
97 |
if time.time()<dead_time:
|
|
|
87 |
attempt_times = 0
|
88 |
while answer is None and time.time()<dead_time and attempt_times<10:
|
89 |
try:
|
90 |
+
messages=[
|
91 |
+
{"role": "user", "content": query}
|
92 |
+
]
|
93 |
+
if num_tokens_from_messages(messages)>4096:
|
94 |
+
return None
|
95 |
answer = openai.ChatCompletion.create(
|
96 |
model="gpt-3.5-turbo",
|
97 |
+
messages=messages
|
|
|
|
|
98 |
)["choices"][0]["message"]["content"]
|
99 |
except Exception as e:
|
100 |
if time.time()<dead_time:
|