feat(backend): настраиваемая LLM для конвертации PDF в JSON
- Добавлена переменная LLM_MODEL в конфиг - Увеличен max_tokens до 32768 для крупных выписок - Включен response_format: json_object - Добавлен скрипт test:llm для проверки подключения к LLM-серверу
This commit is contained in:
42
backend/src/scripts/testLlm.ts
Normal file
42
backend/src/scripts/testLlm.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Тестовый запрос к LLM серверу.
|
||||
* Запуск: npm run test:llm
|
||||
*/
|
||||
import OpenAI from 'openai';
|
||||
import { config } from '../config';
|
||||
|
||||
async function main() {
|
||||
if (!config.llmApiKey || config.llmApiKey.trim() === '') {
|
||||
console.error('Ошибка: LLM_API_KEY не задан в .env');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: config.llmApiKey,
|
||||
...(config.llmApiBaseUrl && { baseURL: config.llmApiBaseUrl }),
|
||||
});
|
||||
|
||||
const url = config.llmApiBaseUrl || 'https://api.openai.com/v1';
|
||||
console.log('LLM сервер:', url);
|
||||
console.log('Модель:', config.llmModel);
|
||||
console.log('---');
|
||||
|
||||
try {
|
||||
const completion = await openai.chat.completions.create({
|
||||
model: config.llmModel,
|
||||
messages: [{ role: 'user', content: 'Ответь одним словом: какой цвет у неба?' }],
|
||||
temperature: 0,
|
||||
max_tokens: 50,
|
||||
});
|
||||
|
||||
const content = completion.choices[0]?.message?.content;
|
||||
console.log('Ответ:', content || '(пусто)');
|
||||
console.log('---');
|
||||
console.log('OK');
|
||||
} catch (err) {
|
||||
console.error('Ошибка:', err instanceof Error ? err.message : err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user