UNPKG

openlit

Version:

OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects

38 lines 1.52 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.llmResponseAnthropic = llmResponseAnthropic; const sdk_1 = __importDefault(require("@anthropic-ai/sdk")); async function llmResponseAnthropic({ prompt, model, apiKey }) { const client = new sdk_1.default({ apiKey }); const usedModel = model || 'claude-3-opus-20240229'; const response = await client.messages.create({ model: usedModel, max_tokens: 2000, messages: [ { role: 'user', content: prompt } ], temperature: 0.0, // Anthropic does not support response_format, so we expect JSON in text }); // Try to extract JSON from the response content if (typeof response.content === 'string') return response.content; if (Array.isArray(response.content)) { // Try to find a JSON block in the content array for (const part of response.content) { if (part.type === 'text' && typeof part.text === 'string' && part.text.trim().startsWith('{')) { return part.text; } } // Fallback: join all text blocks that have text return response.content .filter((p) => p.type === 'text' && typeof p.text === 'string') .map(p => p.text) .join(' '); } return ''; } //# sourceMappingURL=anthropic.js.map