Refresh IQ3 client context and compaction settings for 262K

This commit is contained in:
Mikei386 committed 2026-10-13 19:19:28 +02:00
1 parent 0c0af6894a
commit eda684eb83
7 files changed
+623 -2

No files matched your search

@@ -0,0 +1,30 @@
"""Targeted live correction; run inside OpenWebUI. Never reads chats or logs."""
import datetime,json,os,sqlite3,time
from pathlib import Path
c=sqlite3.connect('/app/backend/data/webui.db');c.row_factory=sqlite3.Row
c.execute('BEGIN IMMEDIATE')
model=c.execute('select params from model where id=?',('flash-next-strata-iq3',)).fetchone();assert model,'IQ3 model missing'
params=json.loads(model['params'] or '{}');threshold=262144*85//100
before={'model_params':params.copy(),'functions':{}}
changes=[]
for ident in ('athena_context_display','athena_tool_context_guard'):
row=c.execute('select valves from function where id=?',(ident,)).fetchone()
if not row:continue
valves=json.loads(row['valves'] or '{}');before['functions'][ident]=dict(valves)
raw=valves.get('profile_windows',{})
windows=json.loads(raw) if isinstance(raw,str) else dict(raw)
windows['flash-next-strata-iq3']=262144
valves['profile_windows']=json.dumps(windows,sort_keys=True) if isinstance(raw,str) else windows
changes.append((ident,valves))
folder=Path('/app/backend/data/settings-backups');folder.mkdir(exist_ok=True)
p=folder/('strata-context-'+datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S%fZ')+'.json')
fd=os.open(p,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
with os.fdopen(fd,'w') as f:json.dump(before,f)
params['compact_token_threshold']=threshold
c.execute('update model set params=?,updated_at=? where id=?',(json.dumps(params),int(time.time()),'flash-next-strata-iq3'))
for ident,valves in changes:c.execute('update function set valves=?,updated_at=? where id=?',(json.dumps(valves),int(time.time()),ident))
c.commit()
assert json.loads(c.execute('select params from model where id=?',('flash-next-strata-iq3',)).fetchone()[0])['compact_token_threshold']==threshold
for ident,valves in changes:
assert json.loads(c.execute('select valves from function where id=?',(ident,)).fetchone()[0])==valves
print(json.dumps({'model':'flash-next-strata-iq3','context':262144,'compact_token_threshold':threshold,'updated_filters':[i for i,v in changes],'saved_and_verified':True,'backup':str(p)}))