Files

29 lines
1.8 KiB
Python

import sqlite3,json,asyncio,urllib.request
from datetime import timedelta
from open_webui.utils.auth import create_token
from open_webui.models.models import Models
from open_webui.utils.payload import apply_params_to_form_data,apply_model_params_to_body_openai
c=sqlite3.connect('/app/backend/data/webui.db');uid=c.execute("select id from user where role='admin' limit 1").fetchone()[0]
token=create_token({'id':uid},timedelta(minutes=5))
request=urllib.request.Request('http://127.0.0.1:8080/api/chat/completions',data=json.dumps({'model':'re_registry','messages':[{'role':'user','content':'configuration'}],'stream':False}).encode(),headers={'Authorization':'Bearer '+token,'Content-Type':'application/json'})
with urllib.request.urlopen(request,timeout=30) as r:response=json.load(r)
registry=json.loads(response['choices'][0]['message']['content'])
assert not registry.get('error'),registry
assert not c.execute("select id from function where id in ('athena_thinking','athena_thinking_control')").fetchall()
async def main():
count=0
for ident,rule in registry['models'].items():
if not rule.get('thinking'):continue
stored=await Models.get_model_by_id(ident)
m=stored.model_dump() if stored else {'meta':{},'params':{}}
assert not any(x.startswith('athena_thinking') for x in (m['meta'].get('filterIds') or []))
for level in rule['mappings']:
body={'model':ident,'messages':[{'role':'user','content':'synthetic'}],'params':{'custom_params':rule['mappings'][level]}}
body=apply_params_to_form_data(body,{'owned_by':'openai'})
body=apply_model_params_to_body_openai(dict(m['params']),body)
assert body['reasoning_effort']==level
assert body['chat_template_kwargs']['enable_thinking'] is (level!='none')
count+=1
print('Registry API response and',count,'OpenWebUI provider payloads passed; no GPU inference')
asyncio.run(main())