Skip to content

Commit 9659106

Browse files
authored
fix(js/plugins/compat-oai): Add missing exports for defining compat models (#3357)
1 parent a0fda3a commit 9659106

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

js/plugins/compat-oai/src/index.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ import { genkitPlugin } from 'genkit/plugin';
1919
import { ActionType } from 'genkit/registry';
2020
import { OpenAI, type ClientOptions } from 'openai';
2121

22+
export {
23+
SpeechConfigSchema,
24+
TranscriptionConfigSchema,
25+
compatOaiSpeechModelRef,
26+
compatOaiTranscriptionModelRef,
27+
defineCompatOpenAISpeechModel,
28+
defineCompatOpenAITranscriptionModel,
29+
type SpeechRequestBuilder,
30+
type TranscriptionRequestBuilder,
31+
} from './audio.js';
32+
export { defineCompatOpenAIEmbedder } from './embedder.js';
33+
export {
34+
ImageGenerationCommonConfigSchema,
35+
compatOaiImageModelRef,
36+
defineCompatOpenAIImageModel,
37+
type ImageRequestBuilder,
38+
} from './image.js';
39+
export {
40+
ChatCompletionCommonConfigSchema,
41+
compatOaiModelRef,
42+
defineCompatOpenAIModel,
43+
openAIModelRunner,
44+
type ModelRequestBuilder,
45+
} from './model.js';
46+
2247
export interface PluginOptions extends Partial<ClientOptions> {
2348
name: string;
2449
initializer?: (ai: Genkit, client: OpenAI) => Promise<void>;
@@ -98,13 +123,13 @@ export const openAICompatible = (options: PluginOptions) => {
98123
await options.resolver(ai, client, actionType, actionName);
99124
}
100125
},
101-
async () => {
102-
if (options.listActions) {
103-
if (listActionsCache) return listActionsCache;
104-
listActionsCache = await options.listActions(client);
105-
return listActionsCache;
106-
}
107-
}
126+
options.listActions
127+
? async () => {
128+
if (listActionsCache) return listActionsCache;
129+
listActionsCache = await options.listActions!(client);
130+
return listActionsCache;
131+
}
132+
: undefined
108133
);
109134
};
110135

js/testapps/compat-oai/src/index.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
* limitations under the License.
1616
*/
1717

18+
import {
19+
compatOaiModelRef,
20+
defineCompatOpenAIModel,
21+
openAICompatible,
22+
} from '@genkit-ai/compat-oai';
1823
import { deepSeek } from '@genkit-ai/compat-oai/deepseek';
1924
import { openAI } from '@genkit-ai/compat-oai/openai';
2025
import { xAI } from '@genkit-ai/compat-oai/xai';
@@ -24,8 +29,31 @@ import { genkit, z } from 'genkit';
2429

2530
dotenv.config();
2631

32+
const DECLARED_MODELS = ['gemini-2.0-flash'];
33+
2734
const ai = genkit({
28-
plugins: [openAI(), deepSeek(), xAI()],
35+
plugins: [
36+
openAI(),
37+
deepSeek(),
38+
xAI(),
39+
openAICompatible({
40+
name: 'goog-oai',
41+
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
42+
apiKey: process.env['GEMINI_API_KEY'],
43+
initializer: async (ai, client) => {
44+
for (const model of DECLARED_MODELS) {
45+
defineCompatOpenAIModel({
46+
ai,
47+
name: `goog-oai/${model}`,
48+
client,
49+
modelRef: compatOaiModelRef({
50+
name: 'goog-oai/gemini-2.0-flash',
51+
}),
52+
});
53+
}
54+
},
55+
}),
56+
],
2957
});
3058

3159
export const jokeFlow = ai.defineFlow(
@@ -37,9 +65,8 @@ export const jokeFlow = ai.defineFlow(
3765
async (subject) => {
3866
const llmResponse = await ai.generate({
3967
prompt: `tell me a joke about ${subject}`,
40-
model: xAI.model('grok-3-mini', {
41-
temperature: 0.5,
42-
reasoningEffort: 'low',
68+
model: compatOaiModelRef({
69+
name: 'goog-oai/gemini-2.0-flash',
4370
}),
4471
});
4572
return llmResponse.text;
@@ -86,8 +113,6 @@ export const webSearchFlow = ai.defineFlow(
86113
}
87114
);
88115

89-
// genkit flow:run embedFlow \"hello world\"
90-
91116
export const embedFlow = ai.defineFlow(
92117
{
93118
name: 'embedFlow',

0 commit comments

Comments
 (0)