Skip to content

Commit

Permalink
openai PluginOptions should extend ClientOptions (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavidop authored Nov 27, 2024
2 parents a11c66a + eb96f58 commit 937ab51
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions plugins/openai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import type { Genkit } from 'genkit';
import { genkitPlugin } from 'genkit/plugin';
import OpenAI from 'openai';
import {OpenAI, ClientOptions } from 'openai';

import { dallE3, dallE3Model } from './dalle.js';
import {
Expand Down Expand Up @@ -53,9 +53,7 @@ export {
textEmbeddingAda002,
};

export interface PluginOptions {
apiKey?: string;
}
export interface PluginOptions extends ClientOptions {}

/**
* This module provides an interface to the OpenAI models through the Genkit
Expand Down Expand Up @@ -101,13 +99,7 @@ export interface PluginOptions {
*/
export const openAI = (options?: PluginOptions) =>
genkitPlugin('openai', async (ai: Genkit) => {
let apiKey = options?.apiKey || process.env.OPENAI_API_KEY;
if (!apiKey)
throw new Error(
'please pass in the API key or set the OPENAI_API_KEY environment variable'
);
const client = new OpenAI({ apiKey });

const client = new OpenAI(options);
for (const name of Object.keys(SUPPORTED_GPT_MODELS)) {
gptModel(ai, name, client);
}
Expand Down

0 comments on commit 937ab51

Please sign in to comment.