Remote Copilot models (italdesign BYOK + AI credits) for shots/report

This commit is contained in:
Stefano Zini
2026-11-03 16:55:59 +01:00
parent f855768f1f
commit ca4a61d17e
6 changed files with 62 additions and 25 deletions
+4 -6
View File
@@ -3,9 +3,7 @@ import base64, difflib, json, re, unicodedata, urllib.request
import db, llama
from shots import CONTENT_KINDS
API = f"http://127.0.0.1:{llama.PORT}/v1/chat/completions"
JIRA_BROWSE = "https://italdesign.atlassian.net/browse"
_open = urllib.request.build_opener(urllib.request.ProxyHandler({})).open
TICKET = re.compile(r"\b[A-Z][A-Z0-9]{1,9}-\d{1,6}\b")
SYS_A = ('Dividi la trascrizione in argomenti discussi. Rispondi SOLO JSON: {"topics":[{"title":str,"start":"mm:ss","end":"mm:ss","summary":[str],"shown":[str],"decisions":[str],"actions":[{"who":str,"what":str,"when":str}],"open_questions":[str]}]}. '
'Le righe [SCHERMO] riportano cosa era visibile sullo schermo condiviso (tipo, titolo, testo letto): usale come fonte di fatti complementare al parlato. '
@@ -52,18 +50,18 @@ def _strip_junk(o):
def chat(system, user, max_tokens, retries=2, think=False):
"""think=True only for the report passes (topics, docs merge, overview); docs queries and memory stay fast."""
body = {"model": llama.current(False), "temperature": 0.2, "max_tokens": max_tokens + (THINK if think else 0),
body = {"temperature": 0.2, "max_tokens": max_tokens + (THINK if think else 0),
"chat_template_kwargs": {"enable_thinking": think}, "response_format": {"type": "json_object"},
"messages": [{"role": "system", "content": system}, {"role": "user", "content": user}]}
for _ in range(retries):
try:
try:
r = _open(urllib.request.Request(API, json.dumps(body).encode(), {"Content-Type": "application/json"}), timeout=1800)
r = llama.post(body, False, 1800)
except urllib.error.HTTPError as e:
if e.code != 400: raise
body.pop("response_format", None)
r = _open(urllib.request.Request(API, json.dumps(body).encode(), {"Content-Type": "application/json"}), timeout=1800)
t = llama.content(json.load(r), f"report ({max_tokens} max)")
r = llama.post(body, False, 1800)
t = llama.content(r, f"report ({max_tokens} max)")
t = re.sub(r"<think>.*?</think>", "", t, flags=re.S)
d = _strip_junk(json.loads(t[t.find("{"):t.rfind("}") + 1]))
if isinstance(d, dict): return d