Files
kefu/deploy/knowledge-v3-20260916/05-model-check.sh
T
2026-09-21 10:34:06 +08:00

30 lines
1.8 KiB
Bash

set -euo pipefail
bash -n /home/ps/knowledge-v3-20260916/rollback.sh
docker exec -i im-admin-knowledge-worker-1 python - <<'PY'
from pathlib import Path
import json,time
import admin_backend
from knowledge_models import model_choices
from knowledge_worker import enhance
database=admin_backend.Database(Path('/data/backend.db'))
choices=model_choices(database)
default=next((item for item in choices if item['default']),None)
assert default,'No default text model'
candidate={'title':'测试门店营业时间','question':'虚构测试门店周日几点营业?',
'answer':'虚构测试门店周日九点到十七点营业,仅供测试。',
'conditions':'仅适用于虚构测试门店','category':'测试','kind':'qa','flags':[],'sources':[]}
started=time.monotonic()
try:
result,chars_in,chars_out=enhance(candidate,database,{'model_provider_id':default['id'],'model_timeout_seconds':90})
summary={'synthetic_model_probe':True,'model':default['id'],'seconds':round(time.monotonic()-started,2),
'input_chars':chars_in,'output_chars':chars_out,'valid_fields':all(result[k] for k in ('title','question','answer','conditions','category')),
'available_models':[item['id'] for item in choices]}
except ValueError as error:
summary={'synthetic_model_probe':False,'model':default['id'],'error':str(error)}
print(json.dumps(summary,ensure_ascii=False),flush=True)
with database.connect() as db:
print(json.dumps({'jobs':[dict(row) for row in db.execute('SELECT id,status,processed,model_calls FROM knowledge_job ORDER BY created_at DESC LIMIT 5')],
'knowledge_counts':dict(db.execute('SELECT status,COUNT(*) FROM knowledge_item GROUP BY status'))},ensure_ascii=False),flush=True)
assert summary['synthetic_model_probe'],'Synthetic model extraction failed'
PY