feat(settings): configure Jev evaluation and model transitions
This commit is contained in:
1 parent
369f6c2ca8
commit
883b1dc824
20 files changed
+1195
-37
No files matched your search
@@ -18,6 +18,7 @@ import json
|
||||
import os
|
||||
import re
|
||||
import urllib.request
|
||||
import jev_settings
|
||||
|
||||
ADRES = "https://api.typesafe.ai/v1/systemone"
|
||||
MODEL = "jev-1.13.0"
|
||||
@@ -32,26 +33,44 @@ SORU = {
|
||||
_ANAHTAR = {"okundu": False, "deger": ""}
|
||||
|
||||
def muaf_mi(hedef):
|
||||
"""12 Ekim 2026: yalnız çözülmüş exact sesli combo hedefi Jev'den muaftır.
|
||||
"""Settings' always-pass list matches exact resolved model IDs.
|
||||
|
||||
Taşıma hatalarının katman sırasını değiştirmez; yedek model kendi adına denetlenir.
|
||||
"""
|
||||
return hedef == "Sesli-Hizli-Zeki"
|
||||
return hedef in jev_settings.read()[0]['exemptModels']
|
||||
|
||||
|
||||
def sonrakiler(hedef):
|
||||
"""Jev gecirmezse sirayla denenecek katmanlar. Secili model bir katmansa ondan sonrakiler; katman degilse
|
||||
butun katmanlar bastan (once Katman-1). Son katman (Katman-4) kendisi gelince bos doner: sorgulanmadan gecer."""
|
||||
"""Model-specific rejection edges take precedence over the general fallback.
|
||||
|
||||
Stop at an always-pass model or before revisiting any target.
|
||||
"""
|
||||
settings = jev_settings.read()[0]
|
||||
ad = str(hedef or "")
|
||||
if not ad or ad == KATMAN[-1]:
|
||||
if not settings['enabled'] or not ad:
|
||||
return []
|
||||
if ad in KATMAN:
|
||||
return list(KATMAN[KATMAN.index(ad) + 1:])
|
||||
return list(KATMAN)
|
||||
routes = {r['from']: r['to'] for r in settings['rejectionRules']}
|
||||
result, seen = [], {ad}
|
||||
# An exempt model can still use the general fallback on transport failure.
|
||||
# Repeated targets stop the walk even if a file was edited outside Settings.
|
||||
while len(result) < 65:
|
||||
target = routes.get(ad, settings['fallbackModel'])
|
||||
if target in seen:
|
||||
break
|
||||
seen.add(target)
|
||||
result.append(target)
|
||||
if target in settings['exemptModels']:
|
||||
break
|
||||
ad = target
|
||||
return result
|
||||
|
||||
|
||||
def anahtar(ortam=None, dosyalar=None):
|
||||
"""TypeSafe anahtari: ortam degiskeni, sonra ~/.typesafe/typesafe.env. Yoksa ""."""
|
||||
if ortam is None and dosyalar is None:
|
||||
saved = jev_settings.key()
|
||||
if saved:
|
||||
return saved
|
||||
ortam = os.environ if ortam is None else ortam
|
||||
deger = str(ortam.get("TYPESAFE_API_KEY") or "").strip()
|
||||
if deger:
|
||||
@@ -147,24 +166,53 @@ def komutlar(govde):
|
||||
return "\n".join(satirlar)
|
||||
|
||||
|
||||
def _gonder(govde, key):
|
||||
istek = urllib.request.Request(ADRES, data=json.dumps(govde).encode("utf-8"), method="POST",
|
||||
def _gonder(govde, key, settings=None):
|
||||
settings = settings or jev_settings.read()[0]
|
||||
istek = urllib.request.Request(settings['endpoint'], data=json.dumps(govde).encode("utf-8"), method="POST",
|
||||
headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(istek) as yanit:
|
||||
with urllib.request.urlopen(istek, timeout=settings['timeoutSeconds']) as yanit:
|
||||
return json.load(yanit)
|
||||
|
||||
|
||||
class Puan(dict):
|
||||
"""Carry the thresholds used for this evaluation through a settings change."""
|
||||
pass
|
||||
|
||||
|
||||
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": cevap},
|
||||
"questions": {k: {"type": "noul", "instructions": v} for k, v in SORU.items()}}
|
||||
settings = jev_settings.read()[0]
|
||||
govde = {"model": settings['model'], "state": {"user_request": istek, "assistant_reply": cevap},
|
||||
"questions": {k: {"type": "noul", "instructions": v} for k, v in settings['questions'].items()}}
|
||||
for name, criteria in settings.get('criteria', {}).items():
|
||||
values = {k: v for k, v in criteria.items() if v.strip()}
|
||||
if values:
|
||||
govde['questions'][name]['criteria'] = values
|
||||
if not jev_settings.acquire(settings):
|
||||
return None
|
||||
try:
|
||||
yanitlar = (gonder(govde, key) or {}).get("answers") or {}
|
||||
return {k: float(yanitlar[k]["noul"]) for k in SORU}
|
||||
response = gonder(govde, key, settings) if gonder is _gonder else gonder(govde, key)
|
||||
yanitlar = (response or {}).get("answers") or {}
|
||||
result = Puan({k: float(yanitlar[k]["noul"]) for k in SORU})
|
||||
if any(not 0 <= v <= 1 for v in result.values()):
|
||||
return None
|
||||
result.thresholds = settings['thresholds']
|
||||
return result
|
||||
except Exception:
|
||||
return None
|
||||
finally:
|
||||
jev_settings.release()
|
||||
|
||||
|
||||
def karar(puan):
|
||||
"""True: adim gecmez, sonraki katman yapar. Istisna yok."""
|
||||
return puan["ret"] >= ESIK["ret"] or puan["sart"] >= ESIK["sart"]
|
||||
thresholds = getattr(puan, 'thresholds', None) or jev_settings.read()[0]['thresholds']
|
||||
return puan["ret"] >= thresholds["ret"] or puan["sart"] >= thresholds["sart"]
|
||||
|
||||
|
||||
def hata_gecis():
|
||||
return jev_settings.read()[0]['failureAction'] == 'next'
|
||||
|
||||
|
||||
def etkin_mi():
|
||||
return bool(jev_settings.read()[0]['enabled'])
|
||||
Reference in new issue
Block a user