Spaces:
Running
Running
fix: ssr_mode=False + messages-format history (Gradio 6 runtime error)
Browse files
app.py
CHANGED
|
@@ -92,7 +92,7 @@ else:
|
|
| 92 |
|
| 93 |
def respond(
|
| 94 |
message: str,
|
| 95 |
-
history: list[
|
| 96 |
model: str,
|
| 97 |
system_prompt: str,
|
| 98 |
temperature: float,
|
|
@@ -116,14 +116,17 @@ def respond(
|
|
| 116 |
|
| 117 |
is_first_response = not (history or [])
|
| 118 |
|
|
|
|
|
|
|
|
|
|
| 119 |
messages: list[dict[str, str]] = []
|
| 120 |
if system_prompt.strip():
|
| 121 |
messages.append({"role": "system", "content": system_prompt.strip()})
|
| 122 |
-
for
|
| 123 |
-
if
|
| 124 |
-
|
| 125 |
-
if
|
| 126 |
-
messages.append({"role":
|
| 127 |
messages.append({"role": "user", "content": message})
|
| 128 |
|
| 129 |
try:
|
|
@@ -200,6 +203,7 @@ with gr.Blocks(title="QuickSilver Pro Chat") as demo:
|
|
| 200 |
# keeps this compatible with both 5.x and 6.x.
|
| 201 |
gr.ChatInterface(
|
| 202 |
fn=respond,
|
|
|
|
| 203 |
additional_inputs=[model_dropdown, system_prompt, temperature, max_tokens],
|
| 204 |
examples=[
|
| 205 |
["Write a concise git commit message for: fixed off-by-one error in pagination"],
|
|
@@ -214,4 +218,9 @@ with gr.Blocks(title="QuickSilver Pro Chat") as demo:
|
|
| 214 |
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
def respond(
|
| 94 |
message: str,
|
| 95 |
+
history: list[dict[str, str]],
|
| 96 |
model: str,
|
| 97 |
system_prompt: str,
|
| 98 |
temperature: float,
|
|
|
|
| 116 |
|
| 117 |
is_first_response = not (history or [])
|
| 118 |
|
| 119 |
+
# Gradio 5+ ChatInterface(type="messages") gives history as
|
| 120 |
+
# [{"role": "user"|"assistant", "content": str}, ...] — same shape the
|
| 121 |
+
# OpenAI SDK wants, so we can pass it through with light filtering.
|
| 122 |
messages: list[dict[str, str]] = []
|
| 123 |
if system_prompt.strip():
|
| 124 |
messages.append({"role": "system", "content": system_prompt.strip()})
|
| 125 |
+
for turn in history or []:
|
| 126 |
+
role = turn.get("role") if isinstance(turn, dict) else None
|
| 127 |
+
content = turn.get("content") if isinstance(turn, dict) else None
|
| 128 |
+
if role in ("user", "assistant") and content:
|
| 129 |
+
messages.append({"role": role, "content": content})
|
| 130 |
messages.append({"role": "user", "content": message})
|
| 131 |
|
| 132 |
try:
|
|
|
|
| 203 |
# keeps this compatible with both 5.x and 6.x.
|
| 204 |
gr.ChatInterface(
|
| 205 |
fn=respond,
|
| 206 |
+
type="messages",
|
| 207 |
additional_inputs=[model_dropdown, system_prompt, temperature, max_tokens],
|
| 208 |
examples=[
|
| 209 |
["Write a concise git commit message for: fixed off-by-one error in pagination"],
|
|
|
|
| 218 |
|
| 219 |
|
| 220 |
if __name__ == "__main__":
|
| 221 |
+
# ssr_mode=False — Gradio 6.x ships an experimental SSR path that runs a
|
| 222 |
+
# localhost reachability check at launch. Inside HF Spaces' container that
|
| 223 |
+
# check fails ("When localhost is not accessible, a shareable link must
|
| 224 |
+
# be created."), crashing the Space with RUNTIME_ERROR. Disabling SSR
|
| 225 |
+
# restores classic CSR rendering, which is what the Space ran on before.
|
| 226 |
+
demo.queue(default_concurrency_limit=4, max_size=64).launch(ssr_mode=False)
|