- Fix critical await bug in extract-stream endpoint - Add comprehensive logging to LLM and parser modules - Implement fallback to standard completion for incompatible models - Create enhanced v2.0 prompts with social media handling and few-shot examples - Add LLM health check endpoint - Decompose share page into 6 focused Svelte 5 snippets Resolves LM Studio integration issues and improves code maintainability
43 lines
987 B
TypeScript
43 lines
987 B
TypeScript
import OpenAI from 'openai';
|
|
import { env } from '$env/dynamic/private';
|
|
|
|
export const createLLM = () => {
|
|
// Detect if we are using Ollama or OpenAI based on URL
|
|
const baseURL = env.OPENAI_BASE_URL;
|
|
const apiKey = env.OPENAI_API_KEY;
|
|
const model = env.LLM_MODEL || 'gpt-4o';
|
|
|
|
console.log('[LLM] Initializing client...');
|
|
console.log('[LLM] Base URL:', baseURL);
|
|
console.log('[LLM] Model:', model);
|
|
|
|
if (!baseURL) {
|
|
throw new Error('OPENAI_BASE_URL environment variable is not set');
|
|
}
|
|
|
|
if (!apiKey) {
|
|
throw new Error('OPENAI_API_KEY environment variable is not set');
|
|
}
|
|
|
|
const client = new OpenAI({
|
|
apiKey,
|
|
baseURL
|
|
});
|
|
|
|
return { client, model };
|
|
};
|
|
|
|
/**
|
|
* Health check for LLM service
|
|
*/
|
|
export async function checkLLMHealth(): Promise<boolean> {
|
|
try {
|
|
const { client } = createLLM();
|
|
await client.models.list();
|
|
console.log('[LLM] Health check passed');
|
|
return true;
|
|
} catch (e) {
|
|
console.error('[LLM] Health check failed:', e);
|
|
return false;
|
|
}
|
|
} |