Spaces:
Sleeping
Sleeping
| import OpenAI from 'openai' | |
| const client = new OpenAI({ | |
| baseURL: process.env.OLLAMA_BASE_URL ?? 'http://localhost:11434/v1', | |
| apiKey: process.env.OPENAI_API_KEY ?? 'ollama', | |
| }) | |
| export const DEFAULT_MODEL = process.env.LLM_MODEL ?? 'llama3.1:8b' | |
| export async function chat(params: { | |
| system: string | |
| user: string | |
| model?: string | |
| jsonMode?: boolean | |
| }) { | |
| const response = await client.chat.completions.create({ | |
| model: params.model ?? DEFAULT_MODEL, | |
| messages: [ | |
| { role: 'system', content: params.system }, | |
| { role: 'user', content: params.user }, | |
| ], | |
| ...(params.jsonMode ? { response_format: { type: 'json_object' } } : {}), | |
| }) | |
| return response | |
| } | |