/
Paff
/
declarant
Обзор
Документация
Войти
/
Paff
/
declarant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
test_models.py
63 строки
3 KB
1pash1985-gif
Unified doc list UI + AI prompt for FORM_A
05 авг 2026, 10:09
05 авг 2026, 10:09
e439f08
Код
Авторство
О чём код?
"""Test different models and approaches for the reasoning token issue.""" import sys, os, re, json, time sys.path.insert(0, '/app/web') os.chdir('/app/web') from ai_parser import extract_text_from_excel, client, INVOICE_SYSTEM_PROMPT, _get_corrections_context from config import DEEPSEEK_API_KEY, DEEPSEEK_BASE_URL from openai import OpenAI xls_path = '/app/web/uploads/reports/2026-07-27/444/sources/invoice_444_1.xls' raw_text = extract_text_from_excel(xls_path) # Strip URLs url_pattern = r'https?://\S+' text_clean = re.sub(url_pattern, '', raw_text) text_clean = re.sub(r' +', ' ', text_clean) text_clean = re.sub(r' \| $', '', text_clean) print(f'Raw text: {len(raw_text)} chars') print(f'Clean text: {len(text_clean)} chars') print('---') system_prompt = INVOICE_SYSTEM_PROMPT + _get_corrections_context() # Models to test models = ['deepseek-chat', 'deepseek-v4-pro', 'deepseek-v4-flash'] texts = [('clean', text_clean)] for model_name in models: for text_label, text in texts: print(f'=== {model_name} + {text_label} text (max_tokens=8192) ===') t0 = time.time() try: response = client.chat.completions.create( model=model_name, messages=[ {'role': 'system', 'content': system_prompt}, {'role': 'user', 'content': f'Вот текст инвойса:\n\n{text}'}, ], temperature=0.1, max_tokens=8192, response_format={'type': 'json_object'}, ) elapsed = time.time() - t0 fr = response.choices[0].finish_reason content = response.choices[0].message.content or '' cl = len(content) ct = response.usage.completion_tokens if response.usage else 0 rt = '?' if response.usage and hasattr(response.usage, 'completion_tokens_details'): rt = getattr(response.usage.completion_tokens_details, 'reasoning_tokens', 0) or 0 print(f' finish_reason={fr}, content_len={cl}, completion={ct}, reasoning={rt}, time={elapsed:.1f}s') if cl > 0: print(f' Preview: {content[:200]}') try: parsed = json.loads(content) print(f' PARSED OK! supplier={parsed.get("supplier_name", "N/A")}') except: print(f' JSON parse failed') except Exception as e: elapsed = time.time() - t0 print(f' ERROR ({elapsed:.1f}s): {e}') print()