Kopru: her adim Jev'e gider, sure ve boyut siniri yok
Yazisiz adimda cagrilan komut sorulur; kullanici mesaji bulunamasa da sorulur; Jev'e giden istek ve cevap kesilmez, bekleme suresi siniri yok. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff53cafb5c
commit
7547de1852
3 files changed
+46
-25
No files matched your search
@@ -21,9 +21,6 @@ ADRES = "https://api.typesafe.ai/v1/systemone"
|
||||
MODEL = "jev-1.13.0"
|
||||
KATMAN = ("Katman-1", "Katman-2", "Katman-3", "Katman-4")
|
||||
ESIK = {"ret": 0.5, "sart": 0.7}
|
||||
SURE = 6.0
|
||||
EN_COK_ISTEK = 3000
|
||||
EN_COK_CEVAP = 6000
|
||||
SORU = {
|
||||
"ret": ("The assistant did NOT do what the user asked or did NOT answer the user's question: it refused, declined, "
|
||||
"said it cannot or will not, avoided giving the requested judgment, or redirected to a different topic."),
|
||||
@@ -90,32 +87,44 @@ def son_istek(req):
|
||||
metin = _metin(oge).strip()
|
||||
m = re.search(r"<realtime_delegation>.*?<input>(.*?)</input>", metin, re.S)
|
||||
if m:
|
||||
return m.group(1).strip()[:EN_COK_ISTEK]
|
||||
return m.group(1).strip()
|
||||
if metin and not metin.startswith("<"):
|
||||
return metin[:EN_COK_ISTEK]
|
||||
return metin
|
||||
return ""
|
||||
|
||||
|
||||
def _kisalt(metin, sinir):
|
||||
if len(metin) <= sinir:
|
||||
return metin
|
||||
bas = sinir * 2 // 3
|
||||
return metin[:bas] + "\n[...]\n" + metin[-(sinir - bas):]
|
||||
def komutlar(govde):
|
||||
"""Yazisi olmayan adimda Jev'e giden metin: modelin bu adimda cagirdigi araclar (ad ve arguman).
|
||||
govde: ust kaynagin SSE yaniti (bayt). Arac cagrisi yoksa ""."""
|
||||
satirlar = []
|
||||
for satir in govde.splitlines():
|
||||
if not satir.startswith(b"data:") or b"response.output_item.done" not in satir:
|
||||
continue
|
||||
try:
|
||||
oge = json.loads(satir[5:]).get("item") or {}
|
||||
except (ValueError, AttributeError):
|
||||
continue
|
||||
if isinstance(oge, dict) and str(oge.get("type") or "").endswith("_call"):
|
||||
arguman = oge.get("arguments") or oge.get("input") or oge.get("action") or ""
|
||||
if not isinstance(arguman, str):
|
||||
arguman = json.dumps(arguman, ensure_ascii=False)
|
||||
satirlar.append(f"[komut] {oge.get('name') or oge.get('type')}: {arguman}")
|
||||
return "\n".join(satirlar)
|
||||
|
||||
|
||||
def _gonder(govde, key, sure):
|
||||
def _gonder(govde, key):
|
||||
istek = urllib.request.Request(ADRES, data=json.dumps(govde).encode("utf-8"), method="POST",
|
||||
headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(istek, timeout=sure) as yanit:
|
||||
with urllib.request.urlopen(istek) as yanit:
|
||||
return json.load(yanit)
|
||||
|
||||
|
||||
def sor(istek, cevap, key, sure=SURE, gonder=_gonder):
|
||||
def sor(istek, cevap, key, gonder=_gonder):
|
||||
"""Jev'e sorar. Donus: {"ret", "sart"} olasiliklari | None (sorulamadi)."""
|
||||
govde = {"model": MODEL, "state": {"user_request": istek, "assistant_reply": _kisalt(cevap, EN_COK_CEVAP)},
|
||||
govde = {"model": MODEL, "state": {"user_request": istek, "assistant_reply": cevap},
|
||||
"questions": {k: {"type": "noul", "instructions": v} for k, v in SORU.items()}}
|
||||
try:
|
||||
yanitlar = (gonder(govde, key, sure) or {}).get("answers") or {}
|
||||
yanitlar = (gonder(govde, key) or {}).get("answers") or {}
|
||||
return {k: float(yanitlar[k]["noul"]) for k in SORU}
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
Reference in new issue
Block a user