13 lines
1.8 KiB
Python
13 lines
1.8 KiB
Python
"""Inside existing OpenWebUI: only connection settings and synthetic requests."""
|
|
import sqlite3,json,urllib.request,time
|
|
c=sqlite3.connect('file:/app/backend/data/webui.db?mode=ro',uri=True)
|
|
def setting(n):return json.loads(c.execute('select value from config where key=?',(n,)).fetchone()[0])
|
|
urls=setting('openai.api_base_urls');keys=setting('openai.api_keys');i=next(i for i,u in enumerate(urls) if '192.168.1.212:8120' in u);base=urls[i].rstrip('/');ident='qwen3-8-flash-next-unsloth-q3-k-xl'
|
|
def call(path,body=None):
|
|
r=urllib.request.Request(base+path,data=json.dumps(body).encode() if body else None,headers={'Authorization':'Bearer '+keys[i],'Content-Type':'application/json'})
|
|
with urllib.request.urlopen(r,timeout=600) as response:return response.status,json.load(response)
|
|
status,models=call('/models');present=any(x['id']==ident for x in models['data'])
|
|
body={'model':ident,'messages':[{'role':'user','content':'Synthetischer Test. Rufe ausschließlich lookup_demo mit station="Demo Hbf" auf. Keine Textantwort.'}],'tools':[{'type':'function','function':{'name':'lookup_demo','description':'Synthetische Stationssuche ohne externe Wirkung','parameters':{'type':'object','properties':{'station':{'type':'string'}},'required':['station']}}}],'max_tokens':256,'temperature':0,'chat_template_kwargs':{'enable_thinking':False}}
|
|
t=time.monotonic();http,response=call('/chat/completions',body);calls=response['choices'][0]['message'].get('tool_calls',[]);passed=bool(calls and calls[0]['function']['name']=='lookup_demo' and json.loads(calls[0]['function']['arguments'])=={'station':'Demo Hbf'})
|
|
print(json.dumps({'models_http_status':status,'model_listed':present,'tool_http_status':http,'tool_passed':passed,'seconds':time.monotonic()-t,'response':response},indent=2,ensure_ascii=False));assert present and passed
|