Hermes SIQ-1-35B on ZeroGPU (llama-cpp-python recipe)
Browse files
app.py
CHANGED
|
@@ -56,6 +56,7 @@ GGUF_REPO = os.environ.get("GGUF_REPO", "AlexWortega/SIQ-1-35B")
|
|
| 56 |
GGUF_FILE = os.environ.get("GGUF_FILE", "gguf/SIQ-1-35B.Q4_K_M.gguf")
|
| 57 |
N_CTX = int(os.environ.get("N_CTX", "16384")) # keep cold-start init light
|
| 58 |
|
|
|
|
| 59 |
print("Downloading GGUF from the Hub ...", flush=True)
|
| 60 |
MODEL_PATH = hf_hub_download(GGUF_REPO, GGUF_FILE)
|
| 61 |
print("GGUF ready at", MODEL_PATH, flush=True)
|
|
@@ -667,23 +668,43 @@ def _agent_stream(message, history, system_prompt, temperature, max_tokens, use_
|
|
| 667 |
]
|
| 668 |
in_tok += _count_tokens(llm, "\n".join(m.get("content", "") for m in gen_msgs))
|
| 669 |
finish = None
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
if finish == "length" and cont < MAX_CONTINUE:
|
| 688 |
cont += 1
|
| 689 |
continue
|
|
|
|
| 56 |
GGUF_FILE = os.environ.get("GGUF_FILE", "gguf/SIQ-1-35B.Q4_K_M.gguf")
|
| 57 |
N_CTX = int(os.environ.get("N_CTX", "16384")) # keep cold-start init light
|
| 58 |
|
| 59 |
+
print("=== APP BUILD MARKER: chunkfix-v3 ===", flush=True)
|
| 60 |
print("Downloading GGUF from the Hub ...", flush=True)
|
| 61 |
MODEL_PATH = hf_hub_download(GGUF_REPO, GGUF_FILE)
|
| 62 |
print("GGUF ready at", MODEL_PATH, flush=True)
|
|
|
|
| 668 |
]
|
| 669 |
in_tok += _count_tokens(llm, "\n".join(m.get("content", "") for m in gen_msgs))
|
| 670 |
finish = None
|
| 671 |
+
try:
|
| 672 |
+
for chunk in llm.create_chat_completion(
|
| 673 |
+
messages=gen_msgs,
|
| 674 |
+
max_tokens=int(max_tokens),
|
| 675 |
+
temperature=float(temperature),
|
| 676 |
+
stream=True,
|
| 677 |
+
):
|
| 678 |
+
delta, fr = _chunk_fields(chunk)
|
| 679 |
+
if fr:
|
| 680 |
+
finish = fr
|
| 681 |
+
if not delta:
|
| 682 |
+
continue
|
| 683 |
+
out += delta
|
| 684 |
+
out_tok += 1
|
| 685 |
+
ans, think = _split(transcript + out)
|
| 686 |
+
disp = _strip_artifacts(ans)
|
| 687 |
+
doc, name = _current_doc(files, ans)
|
| 688 |
+
yield disp or "…", transcript + out, think, _tools_md(trace), doc, name, in_tok, out_tok
|
| 689 |
+
except Exception as stream_err: # streaming broken in this llama build -> non-stream fallback
|
| 690 |
+
try:
|
| 691 |
+
resp = llm.create_chat_completion(
|
| 692 |
+
messages=gen_msgs, max_tokens=int(max_tokens),
|
| 693 |
+
temperature=float(temperature), stream=False,
|
| 694 |
+
)
|
| 695 |
+
ch0 = (_g(resp, "choices") or [None])[0]
|
| 696 |
+
msg = _g(ch0, "message") or {}
|
| 697 |
+
full = _g(msg, "content", "") or ""
|
| 698 |
+
finish = _g(ch0, "finish_reason")
|
| 699 |
+
out += full
|
| 700 |
+
out_tok += _count_tokens(llm, full)
|
| 701 |
+
ans, think = _split(transcript + out)
|
| 702 |
+
yield _strip_artifacts(ans) or "…", transcript + out, think, _tools_md(trace), \
|
| 703 |
+
*_current_doc(files, ans), in_tok, out_tok
|
| 704 |
+
except Exception as gen_err:
|
| 705 |
+
err = f"⚠️ generation error: {type(gen_err).__name__}: {gen_err}"
|
| 706 |
+
yield err, transcript + "\n" + err, last_thinking, _tools_md(trace), "", "index.html", in_tok, out_tok
|
| 707 |
+
return
|
| 708 |
if finish == "length" and cont < MAX_CONTINUE:
|
| 709 |
cont += 1
|
| 710 |
continue
|