@convo-lang/convo-lang
Version:
The language of AI
69 lines • 3.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAnthropicConvoConverterFromScope = exports.createAnthropicConvoServiceFromScope = exports.convoAnthropicModule = void 0;
const common_1 = require("@iyio/common");
const BaseOpenAiConvoCompletionService_1 = require("../BaseOpenAiConvoCompletionService");
const BaseOpenAiConvoConverter_1 = require("../BaseOpenAiConvoConverter");
const convo_deps_1 = require("../convo.deps");
const anthropic_lib_1 = require("./anthropic-lib");
const anthropic_models_1 = require("./anthropic-models");
const anthropic_params_1 = require("./anthropic-params");
const convoAnthropicModule = (scope) => {
scope.implementService(convo_deps_1.convoCompletionService, exports.createAnthropicConvoServiceFromScope);
scope.addProvider(convo_deps_1.convoConversationConverterProvider, exports.createAnthropicConvoConverterFromScope);
};
exports.convoAnthropicModule = convoAnthropicModule;
const createAnthropicConvoServiceFromScope = (scope) => {
return new BaseOpenAiConvoCompletionService_1.BaseOpenAiConvoCompletionService({
serviceId: 'anthropic',
apiKey: scope.to(anthropic_params_1.anthropicApiKeyParam).get(),
apiBaseUrl: scope.to(anthropic_params_1.anthropicBaseUrlParam).get(),
completionsEndpoint: '/v1/messages',
secretManager: scope.to(common_1.secretManager).get(),
secretsName: scope.to(anthropic_params_1.anthropicSecretsParam).get(),
inputType: anthropic_lib_1.convoAnthropicInputType,
outputType: anthropic_lib_1.convoAnthropicOutputType,
models: anthropic_models_1.knownConvoAnthropicModels,
apiKeyHeader: 'x-api-key',
apiKeyHeaderValuePrefix: null,
headers: {
'content-type': 'application/json',
'anthropic-version': '2023-06-01',
},
updateRequest: (body) => {
body['max_tokens'] = 8000;
}
});
};
exports.createAnthropicConvoServiceFromScope = createAnthropicConvoServiceFromScope;
const createAnthropicConvoConverterFromScope = (scope) => {
return new BaseOpenAiConvoConverter_1.BaseOpenAiConvoConverter({
chatModel: scope.to(anthropic_params_1.anthropicChatModelParam).get() ?? anthropic_models_1.defaultAnthropicChatModel.name,
visionModel: scope.to(anthropic_params_1.anthropicVisionModelParam).get(),
supportedInputTypes: [anthropic_lib_1.convoAnthropicInputType],
supportedOutputTypes: [anthropic_lib_1.convoAnthropicOutputType],
models: anthropic_models_1.knownConvoAnthropicModels,
transformOutput: (output) => {
const co = output;
const out = { ...output };
out.choices = [{
index: 0,
message: {
role: co.role,
content: co.content.filter?.((c) => c.type === 'text').map?.((c) => c.text)?.join('\n') ?? null,
refusal: null,
},
logprobs: null,
finish_reason: co.stop_reason ?? 'stop',
}];
out.usage = {
prompt_tokens: co.usage.input_tokens,
completion_tokens: co.usage.output_tokens,
total_tokens: co.usage.input_tokens + co.usage.output_tokens
};
return out;
}
});
};
exports.createAnthropicConvoConverterFromScope = createAnthropicConvoConverterFromScope;
//# sourceMappingURL=anthropic-service.js.map