Spaces:
Running
Running
Fix startup crash from example caching with unset inputs
Browse filesGradio cached the examples at startup by calling respond() with None
for the sliders and dropdown, so int(None) raised. Disable example
caching and fall back to defaults when an input is missing.
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -17,15 +17,15 @@ client = OpenAI(base_url=LLM_BASE_URL, api_key=LLM_API_KEY)
|
|
| 17 |
|
| 18 |
|
| 19 |
def respond(message, history, model, system_prompt, max_tokens, temperature):
|
| 20 |
-
messages = [{"role": "system", "content": system_prompt}]
|
| 21 |
messages += [{"role": m["role"], "content": m["content"]} for m in history]
|
| 22 |
messages.append({"role": "user", "content": message})
|
| 23 |
|
| 24 |
stream = client.chat.completions.create(
|
| 25 |
-
model=model,
|
| 26 |
messages=messages,
|
| 27 |
-
max_tokens=int(max_tokens),
|
| 28 |
-
temperature=float(temperature),
|
| 29 |
stream=True,
|
| 30 |
)
|
| 31 |
|
|
@@ -54,6 +54,7 @@ demo = gr.ChatInterface(
|
|
| 54 |
["Why does a JavaScript `for (var i...)` loop with setTimeout print the same number every time?"],
|
| 55 |
["Explain the difference between a process and a thread."],
|
| 56 |
],
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def respond(message, history, model, system_prompt, max_tokens, temperature):
|
| 20 |
+
messages = [{"role": "system", "content": system_prompt or DEFAULT_SYSTEM_PROMPT}]
|
| 21 |
messages += [{"role": m["role"], "content": m["content"]} for m in history]
|
| 22 |
messages.append({"role": "user", "content": message})
|
| 23 |
|
| 24 |
stream = client.chat.completions.create(
|
| 25 |
+
model=model or LLM_MODEL,
|
| 26 |
messages=messages,
|
| 27 |
+
max_tokens=int(max_tokens or 512),
|
| 28 |
+
temperature=float(temperature or 0.2),
|
| 29 |
stream=True,
|
| 30 |
)
|
| 31 |
|
|
|
|
| 54 |
["Why does a JavaScript `for (var i...)` loop with setTimeout print the same number every time?"],
|
| 55 |
["Explain the difference between a process and a thread."],
|
| 56 |
],
|
| 57 |
+
cache_examples=False,
|
| 58 |
)
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|