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
+2 -5
View File
@@ -2,8 +2,6 @@
import base64, collections, json, re, subprocess, urllib.error, urllib.request
import db, llama
API = f"http://127.0.0.1:{llama.PORT}/v1/chat/completions"
_open = urllib.request.build_opener(urllib.request.ProxyHandler({})).open # corp proxy must not see localhost
EMPTY = {"kind": "other", "title": None, "app": None, "summary": "", "text": "", "entities": {}, "people": [], "presenter": None, "meeting_title": None, "content_box": None}
CONTENT_KINDS = {"slide", "code", "terminal", "browser", "document", "spreadsheet", "diagram", "dashboard", "ticket"}
CROP_BOX = True
@@ -39,13 +37,12 @@ EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
def _ask(path, json_mode=True):
img = base64.b64encode(path.read_bytes()).decode()
body = {"model": llama.current(True), "max_tokens": 1200, "temperature": 0.1,
body = {"max_tokens": 1200, "temperature": 0.1,
"chat_template_kwargs": {"enable_thinking": False},
"messages": [{"role": "user", "content": [{"type": "text", "text": PROMPT},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + img}}]}]}
if json_mode: body["response_format"] = {"type": "json_schema", "json_schema": {"name": "shot", "schema": SCHEMA}} if SCHEMA else {"type": "json_object"}
req = urllib.request.Request(API, json.dumps(body).encode(), {"Content-Type": "application/json"})
return llama.content(json.load(_open(req, timeout=900)), f"shot {path.name}")
return llama.content(llama.post(body, True, 900), f"shot {path.name}")
def read_shot(path):