-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenai.js
More file actions
88 lines (81 loc) · 1.89 KB
/
Copy pathopenai.js
File metadata and controls
88 lines (81 loc) · 1.89 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* OpenAI streaming adapter.
* Chat Completions by default; Responses API when hosted web_search is present.
*/
import { hasHostedWebSearch } from "./hosted-tools.js";
import {
filterFunctionTools,
streamOpenAICompatChat,
} from "./openai-compat-stream.js";
import { streamOpenAIResponsesChat } from "./openai-responses.js";
const OPENAI_URL = "https://api.openai.com/v1/chat/completions";
/** Curated chat models for the Options/approval UI — not a live OpenAI catalog. */
export const OPENAI_MODELS = Object.freeze([
"gpt-5.6-luna",
"gpt-5.6-terra",
"gpt-5.6-sol",
"gpt-5.4-nano",
"gpt-5.4-mini",
"gpt-5.4",
"gpt-5-nano",
"gpt-5-mini",
"gpt-4.1-nano",
"gpt-4.1-mini",
"gpt-4.1",
"gpt-4o-mini",
"gpt-4o",
]);
/** @typedef {import("./types.js").Provider} Provider */
/** @type {Provider} */
export const openaiProvider = {
id: "openai",
label: "OpenAI",
requiresApiKey: true,
models: OPENAI_MODELS,
defaultModel: "gpt-5.6-luna",
supportsFunctionTools: true,
hostedTools: Object.freeze(["web_search"]),
async streamChat({
apiKey,
model,
messages,
tools,
toolChoice,
options,
signal,
onDelta,
onReasoningDelta,
}) {
if (hasHostedWebSearch(tools)) {
return streamOpenAIResponsesChat({
apiKey,
model,
messages,
tools,
toolChoice,
...(options ? { options } : {}),
signal,
onDelta,
onReasoningDelta,
});
}
const functionTools = filterFunctionTools(tools);
return streamOpenAICompatChat({
url: OPENAI_URL,
apiKey,
model,
messages,
...(functionTools
? {
tools: functionTools,
...(toolChoice !== undefined ? { toolChoice } : {}),
}
: {}),
...(options ? { options } : {}),
signal,
onDelta,
onReasoningDelta,
label: "OpenAI",
});
},
};