UNPKG

navigation-equipment-manuals-mcp-server

Version:

Navigation Equipment Manuals MCP Server for create, update, delete, and search navigation equipment manuals

56 lines 1.83 kB
export class LLMClient { constructor(apiKey) { this.apiKey = apiKey; } async ask(query, systemPrompt, options = {}) { const { model = 'gpt-4o', temperature = 0.7, max_tokens = 2000, json_mode = false } = options; const messages = []; if (systemPrompt) { messages.push({ role: 'system', content: systemPrompt }); } messages.push({ role: 'user', content: query }); const requestBody = { model, messages, temperature, max_tokens }; if (json_mode) { requestBody.response_format = { type: 'json_object' }; } try { const response = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}` }, body: JSON.stringify(requestBody) }); if (!response.ok) { throw new Error(`OpenAI API error: ${response.status}`); } const data = await response.json(); const content = data.choices[0]?.message?.content || ''; if (json_mode) { try { return JSON.parse(content); } catch (e) { throw new Error(`Failed to parse JSON response: ${content}`); } } return { content }; } catch (error) { throw new Error(`LLM request failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } } } //# sourceMappingURL=llm.js.map