Files
claude-task-master/src/ai-providers/openai.js
Ralph Khreish 6a8a68e1a3 Feat/add.azure.and.other.providers (#607)
* fix: claude-4 not having the right max_tokens

* feat: add bedrock support

* chore: fix package-lock.json

* fix: rename baseUrl to baseURL

* feat: add azure support

* fix: final touches of azure integration

* feat: add google vertex provider

* chore: fix tests and refactor task-manager.test.js

* chore: move task 92 to 94
2025-05-28 00:42:31 +02:00

40 lines
963 B
JavaScript

/**
* openai.js
* AI provider implementation for OpenAI models using Vercel AI SDK.
*/
import { createOpenAI } from '@ai-sdk/openai';
import { BaseAIProvider } from './base-provider.js';
export class OpenAIProvider extends BaseAIProvider {
constructor() {
super();
this.name = 'OpenAI';
}
/**
* Creates and returns an OpenAI client instance.
* @param {object} params - Parameters for client initialization
* @param {string} params.apiKey - OpenAI API key
* @param {string} [params.baseURL] - Optional custom API endpoint
* @returns {Function} OpenAI client function
* @throws {Error} If API key is missing or initialization fails
*/
getClient(params) {
try {
const { apiKey, baseURL } = params;
if (!apiKey) {
throw new Error('OpenAI API key is required.');
}
return createOpenAI({
apiKey,
...(baseURL && { baseURL })
});
} catch (error) {
this.handleError('client initialization', error);
}
}
}