From c54d81b492f575a7da67d096157545927ac84d5a Mon Sep 17 00:00:00 2001 From: Magdiel Campelo Date: Fri, 6 Sep 2024 22:35:58 +0000 Subject: [PATCH 1/2] feat: add support to custom base URL and models --- plugins/openai/src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/openai/src/index.ts b/plugins/openai/src/index.ts index a7cdee1e..c0a159c5 100644 --- a/plugins/openai/src/index.ts +++ b/plugins/openai/src/index.ts @@ -36,6 +36,8 @@ import { } from './gpt.js'; import { SUPPORTED_TTS_MODELS, ttsModel, tts1, tts1Hd } from './tts.js'; import { whisper1, whisper1Model } from './whisper.js'; +import { ModelAction } from '@genkit-ai/ai/model'; +import z from 'zod'; export { dallE3, gpt35Turbo, @@ -52,8 +54,12 @@ export { textEmbeddingAda002, }; +export type OpenAICustomModelActionn = (client: OpenAI) => ModelAction + export interface PluginOptions { apiKey?: string; + baseURL?: string; + customModels?: Array; } /** @@ -106,7 +112,8 @@ export const openAI: Plugin<[PluginOptions] | []> = genkitPlugin( throw new Error( 'please pass in the API key or set the OPENAI_API_KEY environment variable' ); - const client = new OpenAI({ apiKey }); + const baseURL = options?.baseURL || process.env.OPENAI_BASE_URL; + const client = new OpenAI({ apiKey, baseURL }); return { models: [ ...Object.keys(SUPPORTED_GPT_MODELS).map((name) => @@ -117,6 +124,7 @@ export const openAI: Plugin<[PluginOptions] | []> = genkitPlugin( ), dallE3Model(client), whisper1Model(client), + ...(options?.customModels?.map(model => model(client)) || []), ], embedders: Object.keys(SUPPORTED_EMBEDDING_MODELS).map((name) => openaiEmbedder(name, options) From ce3059de80563cb89e90ef6c74f9af87b433db9f Mon Sep 17 00:00:00 2001 From: Magdiel Campelo Date: Sat, 7 Sep 2024 21:18:19 -0300 Subject: [PATCH 2/2] fix wrong name of type --- plugins/openai/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/openai/src/index.ts b/plugins/openai/src/index.ts index c0a159c5..3192c87a 100644 --- a/plugins/openai/src/index.ts +++ b/plugins/openai/src/index.ts @@ -54,12 +54,12 @@ export { textEmbeddingAda002, }; -export type OpenAICustomModelActionn = (client: OpenAI) => ModelAction +export type OpenAICustomModelAction = (client: OpenAI) => ModelAction export interface PluginOptions { apiKey?: string; baseURL?: string; - customModels?: Array; + customModels?: Array; } /**