@adminforth/completion-adapter-openai-responses 2.0.21 → 2.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -1
- package/dist/index.js +17 -6
- package/index.ts +50 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,22 @@ import type { AdapterOptions } from "./types.js";
|
|
|
2
2
|
import type { CompletionAdapter, CompletionStreamEvent, CompletionTool } from "adminforth";
|
|
3
3
|
export type { AdapterOptions } from "./types.js";
|
|
4
4
|
type StreamChunkCallback = (chunk: string, event?: CompletionStreamEvent) => void | Promise<void>;
|
|
5
|
+
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
6
|
+
type CompletionRequestInput = {
|
|
7
|
+
content: string;
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
outputSchema?: any;
|
|
10
|
+
reasoningEffort?: ReasoningEffort;
|
|
11
|
+
tools?: CompletionTool[];
|
|
12
|
+
onChunk?: StreamChunkCallback;
|
|
13
|
+
};
|
|
5
14
|
export default class CompletionAdapterOpenAIResponses implements CompletionAdapter {
|
|
6
15
|
options: AdapterOptions;
|
|
7
16
|
private encoding;
|
|
8
17
|
constructor(options: AdapterOptions);
|
|
9
18
|
validate(): void;
|
|
10
19
|
measureTokensCount(content: string): number;
|
|
11
|
-
complete: (
|
|
20
|
+
complete: (requestOrContent: CompletionRequestInput | string, maxTokens?: number, outputSchema?: any, reasoningEffort?: ReasoningEffort, toolsOrOnChunk?: CompletionTool[] | StreamChunkCallback, onChunk?: StreamChunkCallback) => Promise<{
|
|
12
21
|
content?: string;
|
|
13
22
|
finishReason?: string;
|
|
14
23
|
error?: string;
|
package/dist/index.js
CHANGED
|
@@ -82,11 +82,22 @@ function parseSseBlock(block) {
|
|
|
82
82
|
}
|
|
83
83
|
export default class CompletionAdapterOpenAIResponses {
|
|
84
84
|
constructor(options) {
|
|
85
|
-
this.complete = (
|
|
85
|
+
this.complete = (requestOrContent_1, ...args_1) => __awaiter(this, [requestOrContent_1, ...args_1], void 0, function* (requestOrContent, maxTokens = 50, outputSchema, reasoningEffort = "low", toolsOrOnChunk, onChunk) {
|
|
86
86
|
var _a, _b, _c;
|
|
87
|
+
const request = typeof requestOrContent === "string"
|
|
88
|
+
? {
|
|
89
|
+
content: requestOrContent,
|
|
90
|
+
maxTokens,
|
|
91
|
+
outputSchema,
|
|
92
|
+
reasoningEffort,
|
|
93
|
+
tools: Array.isArray(toolsOrOnChunk) ? toolsOrOnChunk : undefined,
|
|
94
|
+
onChunk: typeof toolsOrOnChunk === "function"
|
|
95
|
+
? toolsOrOnChunk
|
|
96
|
+
: onChunk,
|
|
97
|
+
}
|
|
98
|
+
: requestOrContent;
|
|
99
|
+
const { content, maxTokens: requestMaxTokens = 50, outputSchema: requestOutputSchema, reasoningEffort: requestReasoningEffort = "low", tools, onChunk: streamChunkCallback, } = request;
|
|
87
100
|
const model = this.options.model || "gpt-5-nano";
|
|
88
|
-
const tools = Array.isArray(toolsOrOnChunk) ? toolsOrOnChunk : undefined;
|
|
89
|
-
const streamChunkCallback = typeof toolsOrOnChunk === "function" ? toolsOrOnChunk : onChunk;
|
|
90
101
|
const isStreaming = typeof streamChunkCallback === "function";
|
|
91
102
|
const extra = this.options.extraRequestBodyParameters;
|
|
92
103
|
let openAiTools = undefined;
|
|
@@ -99,16 +110,16 @@ export default class CompletionAdapterOpenAIResponses {
|
|
|
99
110
|
strict: true,
|
|
100
111
|
}));
|
|
101
112
|
}
|
|
102
|
-
const body = Object.assign({ model, input: content, max_output_tokens:
|
|
113
|
+
const body = Object.assign({ model, input: content, max_output_tokens: requestMaxTokens, stream: isStreaming, text: requestOutputSchema
|
|
103
114
|
? {
|
|
104
|
-
format: Object.assign({ type: "json_schema" },
|
|
115
|
+
format: Object.assign({ type: "json_schema" }, requestOutputSchema),
|
|
105
116
|
}
|
|
106
117
|
: {
|
|
107
118
|
format: {
|
|
108
119
|
type: "text",
|
|
109
120
|
},
|
|
110
121
|
}, reasoning: {
|
|
111
|
-
effort:
|
|
122
|
+
effort: requestReasoningEffort,
|
|
112
123
|
summary: "auto",
|
|
113
124
|
}, tools: openAiTools }, extra);
|
|
114
125
|
const resp = yield fetch("https://api.openai.com/v1/responses", {
|
package/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { AdapterOptions } from "./types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
CompletionAdapter,
|
|
4
|
+
CompletionStreamEvent,
|
|
5
|
+
CompletionTool,
|
|
6
|
+
} from "adminforth";
|
|
3
7
|
import { encoding_for_model, type TiktokenModel } from "tiktoken";
|
|
4
8
|
import type OpenAI from "openai";
|
|
5
9
|
|
|
@@ -10,6 +14,23 @@ type StreamChunkCallback = (
|
|
|
10
14
|
event?: CompletionStreamEvent,
|
|
11
15
|
) => void | Promise<void>;
|
|
12
16
|
|
|
17
|
+
type ReasoningEffort =
|
|
18
|
+
| "none"
|
|
19
|
+
| "minimal"
|
|
20
|
+
| "low"
|
|
21
|
+
| "medium"
|
|
22
|
+
| "high"
|
|
23
|
+
| "xhigh";
|
|
24
|
+
|
|
25
|
+
type CompletionRequestInput = {
|
|
26
|
+
content: string;
|
|
27
|
+
maxTokens?: number;
|
|
28
|
+
outputSchema?: any;
|
|
29
|
+
reasoningEffort?: ReasoningEffort;
|
|
30
|
+
tools?: CompletionTool[];
|
|
31
|
+
onChunk?: StreamChunkCallback;
|
|
32
|
+
};
|
|
33
|
+
|
|
13
34
|
type ResponseCreateBody = OpenAI.Responses.ResponseCreateParams;
|
|
14
35
|
type OpenAIResponsesSuccess = OpenAI.Responses.Response;
|
|
15
36
|
type OpenAIErrorResponse = {
|
|
@@ -137,10 +158,10 @@ export default class CompletionAdapterOpenAIResponses
|
|
|
137
158
|
}
|
|
138
159
|
|
|
139
160
|
complete = async (
|
|
140
|
-
|
|
161
|
+
requestOrContent: CompletionRequestInput | string,
|
|
141
162
|
maxTokens = 50,
|
|
142
163
|
outputSchema?: any,
|
|
143
|
-
reasoningEffort:
|
|
164
|
+
reasoningEffort: ReasoningEffort = "low",
|
|
144
165
|
toolsOrOnChunk?: CompletionTool[] | StreamChunkCallback,
|
|
145
166
|
onChunk?: StreamChunkCallback,
|
|
146
167
|
): Promise<{
|
|
@@ -148,10 +169,29 @@ export default class CompletionAdapterOpenAIResponses
|
|
|
148
169
|
finishReason?: string;
|
|
149
170
|
error?: string;
|
|
150
171
|
}> => {
|
|
172
|
+
const request =
|
|
173
|
+
typeof requestOrContent === "string"
|
|
174
|
+
? {
|
|
175
|
+
content: requestOrContent,
|
|
176
|
+
maxTokens,
|
|
177
|
+
outputSchema,
|
|
178
|
+
reasoningEffort,
|
|
179
|
+
tools: Array.isArray(toolsOrOnChunk) ? toolsOrOnChunk : undefined,
|
|
180
|
+
onChunk:
|
|
181
|
+
typeof toolsOrOnChunk === "function"
|
|
182
|
+
? toolsOrOnChunk
|
|
183
|
+
: onChunk,
|
|
184
|
+
}
|
|
185
|
+
: requestOrContent;
|
|
186
|
+
const {
|
|
187
|
+
content,
|
|
188
|
+
maxTokens: requestMaxTokens = 50,
|
|
189
|
+
outputSchema: requestOutputSchema,
|
|
190
|
+
reasoningEffort: requestReasoningEffort = "low",
|
|
191
|
+
tools,
|
|
192
|
+
onChunk: streamChunkCallback,
|
|
193
|
+
} = request;
|
|
151
194
|
const model = this.options.model || "gpt-5-nano";
|
|
152
|
-
const tools = Array.isArray(toolsOrOnChunk) ? toolsOrOnChunk : undefined;
|
|
153
|
-
const streamChunkCallback =
|
|
154
|
-
typeof toolsOrOnChunk === "function" ? toolsOrOnChunk : onChunk;
|
|
155
195
|
const isStreaming = typeof streamChunkCallback === "function";
|
|
156
196
|
const extra = this.options.extraRequestBodyParameters;
|
|
157
197
|
let openAiTools: OpenAITool[] | undefined = undefined;
|
|
@@ -168,13 +208,13 @@ export default class CompletionAdapterOpenAIResponses
|
|
|
168
208
|
const body = {
|
|
169
209
|
model,
|
|
170
210
|
input: content,
|
|
171
|
-
max_output_tokens:
|
|
211
|
+
max_output_tokens: requestMaxTokens,
|
|
172
212
|
stream: isStreaming,
|
|
173
|
-
text:
|
|
213
|
+
text: requestOutputSchema
|
|
174
214
|
? {
|
|
175
215
|
format: {
|
|
176
216
|
type: "json_schema",
|
|
177
|
-
...
|
|
217
|
+
...requestOutputSchema,
|
|
178
218
|
},
|
|
179
219
|
}
|
|
180
220
|
: {
|
|
@@ -183,7 +223,7 @@ export default class CompletionAdapterOpenAIResponses
|
|
|
183
223
|
},
|
|
184
224
|
},
|
|
185
225
|
reasoning: {
|
|
186
|
-
effort:
|
|
226
|
+
effort: requestReasoningEffort,
|
|
187
227
|
summary: "auto",
|
|
188
228
|
},
|
|
189
229
|
tools: openAiTools,
|