@wavequery/conductor
Version:
Modular LLM orchestration framework
73 lines (71 loc) • 2.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnthropicProvider = void 0;
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
class AnthropicProvider {
constructor(config) {
this.client = new sdk_1.default({
apiKey: config.apiKey,
});
this.defaultModel = config.defaultModel || "claude-3-opus-20240229";
}
async complete(prompt, options = {}) {
try {
const response = await this.client.messages.create({
model: options.model || this.defaultModel,
max_tokens: options.maxTokens,
temperature: options.temperature,
messages: [{ role: "user", content: prompt }],
system: options.systemPrompt,
});
return {
content: response.content[0].text,
usage: {
// Anthropic doesn't provide token usage in the same way
promptTokens: 0,
completionTokens: 0,
totalTokens: 0,
},
raw: response,
};
}
catch (error) {
throw new Error(`Anthropic completion error: ${error.message}`);
}
}
async completeWithFunctions(prompt, functions, options = {}) {
try {
// Claude doesn't have native function calling, so we format functions as JSON schema
const functionsPrompt = `
You must respond using one of these functions:
${JSON.stringify(functions, null, 2)}
Your response must be a JSON object with a "name" field indicating the function
and an "arguments" object containing the function parameters.
Original request: ${prompt}
`;
const response = await this.complete(functionsPrompt, options);
// Parse the response as a function call
try {
const parsedResponse = JSON.parse(response.content);
return {
...response,
functionCall: {
name: parsedResponse.name,
arguments: parsedResponse.arguments,
},
};
}
catch (parseError) {
throw new Error("Failed to parse function call response from Anthropic");
}
}
catch (error) {
throw new Error(`Anthropic function completion error: ${error.message}`);
}
}
}
exports.AnthropicProvider = AnthropicProvider;
//# sourceMappingURL=anthropic.js.map