UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

127 lines 5.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOrCreateDefaultGptClient = getOrCreateDefaultGptClient; exports.createClient = createClient; exports.donobuGptClientFixture = donobuGptClientFixture; exports.anthropicClientFixture = anthropicClientFixture; exports.anthropicAwsBedrockClientFixture = anthropicAwsBedrockClientFixture; exports.googleGeminiClientFixture = googleGeminiClientFixture; exports.ollamaClientFixture = ollamaClientFixture; exports.openAiClientFixture = openAiClientFixture; exports.vercelAiClientFixture = vercelAiClientFixture; exports.gptClientFixture = gptClientFixture; const VercelAiGptClient_1 = require("../../../clients/VercelAiGptClient"); const envVars_1 = require("../../../envVars"); const GptApiKeysNotSetupException_1 = require("../../../exceptions/GptApiKeysNotSetupException"); const donobuTestStack_1 = require("../utils/donobuTestStack"); let defaultGptClient = undefined; async function getOrCreateDefaultGptClient() { if (!defaultGptClient) { const donobu = await (0, donobuTestStack_1.getOrCreateDonobuStack)(); const client = await donobu.flowsManager.createGptClient(); if (client.gptClient) { defaultGptClient = client.gptClient; } else { throw new GptApiKeysNotSetupException_1.GptApiKeysNotSetupException(); } } return defaultGptClient; } async function createClient(config) { const donobu = await (0, donobuTestStack_1.getOrCreateDonobuStack)(); const client = await donobu.gptClientFactory.createClient(config); return client; } function donobuGptClientFixture(apiKey = envVars_1.env.data.DONOBU_API_KEY) { if (!apiKey) { throw new Error(`An API key is required to use the Donobu GPT client API. Please provide one as an argument or set it using the ${envVars_1.env.keys.DONOBU_API_KEY} environment variable.`); } return async ({}, use) => { const client = await createClient({ type: 'DONOBU', apiKey: apiKey, }); await use(client); }; } function anthropicClientFixture(modelName, apiKey = envVars_1.env.data.ANTHROPIC_API_KEY) { if (!apiKey) { throw new Error(`An API key is required to use the Anthropic API. Please provide one as an argument or set it using the ${envVars_1.env.keys.ANTHROPIC_API_KEY} environment variable.`); } return async ({}, use) => { const client = await createClient({ type: 'ANTHROPIC', apiKey: apiKey, modelName: modelName, }); await use(client); }; } function anthropicAwsBedrockClientFixture(modelName, region = envVars_1.env.data.AWS_REGION, accessKeyId = envVars_1.env.data.AWS_ACCESS_KEY_ID, secretAccessKey = envVars_1.env.data.AWS_SECRET_ACCESS_KEY) { if (!accessKeyId || !secretAccessKey) { throw new Error(`AWS access key ID and secret access key are required to use the Anthropic AWS Bedrock API. Please provide them as arguments or set them using the ${envVars_1.env.keys.AWS_ACCESS_KEY_ID} and ${envVars_1.env.keys.AWS_SECRET_ACCESS_KEY} environment variables.`); } return async ({}, use) => { const client = await createClient({ type: 'ANTHROPIC_AWS_BEDROCK', region: region, modelName: modelName, accessKeyId: accessKeyId, secretAccessKey: secretAccessKey, }); await use(client); }; } function googleGeminiClientFixture(modelName, apiKey = envVars_1.env.data.GOOGLE_GENERATIVE_AI_API_KEY) { if (!apiKey) { throw new Error(`An API key is required to use the Google Gemini API. Please provide one as an argument or set it using the ${envVars_1.env.keys.GOOGLE_GENERATIVE_AI_API_KEY} environment variable.`); } return async ({}, use) => { const client = await createClient({ type: 'GOOGLE_GEMINI', apiKey: apiKey, modelName: modelName, }); await use(client); }; } function ollamaClientFixture(modelName, apiUrl) { return async ({}, use) => { const client = await createClient({ type: 'OLLAMA', modelName, ...(apiUrl ? { apiUrl } : {}), }); await use(client); }; } function openAiClientFixture(modelName, apiKey = envVars_1.env.data.OPENAI_API_KEY) { if (!apiKey) { throw new Error(`An API key is required to use the OpenAI API. Please provide one as an argument or set it using the ${envVars_1.env.keys.OPENAI_API_KEY} environment variable.`); } return async ({}, use) => { const client = await createClient({ type: 'OPENAI', apiKey: apiKey, modelName: modelName, }); await use(client); }; } function vercelAiClientFixture(model) { return async ({}, use) => { const client = new VercelAiGptClient_1.VercelAiGptClient(model); await use(client); }; } function gptClientFixture() { return async ({}, use) => { const client = await getOrCreateDefaultGptClient(); await use(client); }; } //# sourceMappingURL=gptClients.js.map