-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenai-model-client.ts
More file actions
41 lines (37 loc) · 1005 Bytes
/
Copy pathopenai-model-client.ts
File metadata and controls
41 lines (37 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
import {
requireModelCredential,
type ModelClient,
type ModelStreamInput,
} from './model-client';
export const DEFAULT_OPENAI_MODEL = 'gpt-5.4-mini';
/**
* Creates a model client for streaming text with OpenAI.
*
* @param apiKey - OpenAI API key
* @param model - The model to use for generated text
* @returns A model client that streams text using the configured OpenAI model
*/
export function createOpenAIModelClient(
apiKey: string,
model = DEFAULT_OPENAI_MODEL,
): ModelClient {
const openai = createOpenAI({
apiKey: requireModelCredential(apiKey),
});
return {
model,
provider: 'openai',
streamText(input: ModelStreamInput) {
return streamText({
model: openai(model),
messages: input.messages,
system: input.system,
abortSignal: input.abortSignal,
onError: input.onError,
onFinish: input.onFinish,
});
},
};
}