@agentica/core 0.40.0 → 0.41.1
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/lib/events/AgenticaRequestEvent.d.ts +11 -4
- package/lib/events/AgenticaResponseEvent.d.ts +14 -22
- package/lib/factory/events.d.ts +7 -5
- package/lib/factory/events.js +3 -1
- package/lib/factory/events.js.map +1 -1
- package/lib/index.mjs +45 -22
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.js +10 -10
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +4 -4
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/describe.js +2 -2
- package/lib/orchestrate/describe.js.map +1 -1
- package/lib/orchestrate/initialize.js +3 -3
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/select.js +13 -13
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.js +5 -3
- package/lib/utils/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.js +3 -2
- package/lib/utils/ChatGptCompletionStreamingUtil.js.map +1 -1
- package/lib/utils/request.js +22 -1
- package/lib/utils/request.js.map +1 -1
- package/package.json +5 -5
- package/src/events/AgenticaRequestEvent.ts +21 -4
- package/src/events/AgenticaResponseEvent.ts +24 -25
- package/src/factory/events.ts +18 -8
- package/src/orchestrate/call.ts +6 -4
- package/src/orchestrate/cancel.ts +2 -2
- package/src/orchestrate/describe.ts +1 -1
- package/src/orchestrate/initialize.ts +2 -2
- package/src/orchestrate/select.ts +6 -6
- package/src/utils/ChatGptCompletionMessageUtil.ts +3 -3
- package/src/utils/ChatGptCompletionStreamingUtil.ts +2 -2
- package/src/utils/request.ts +22 -1
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
2
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
3
3
|
import type { AgenticaEventSource } from "./AgenticaEventSource";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export type AgenticaRequestEvent = AgenticaRequestEvent.Streaming | AgenticaRequestEvent.NonStreaming;
|
|
5
|
+
export declare namespace AgenticaRequestEvent {
|
|
6
|
+
export type Streaming = Base<true, OpenAI.ChatCompletionCreateParamsStreaming>;
|
|
7
|
+
export type NonStreaming = Base<false, OpenAI.ChatCompletionCreateParamsNonStreaming>;
|
|
8
|
+
interface Base<Stream extends boolean, Body extends object> extends AgenticaEventBase<"request"> {
|
|
9
|
+
source: AgenticaEventSource;
|
|
10
|
+
stream: Stream;
|
|
11
|
+
body: Body;
|
|
12
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
8
15
|
}
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import type OpenAI from "openai";
|
|
2
2
|
import type { AgenticaEventBase } from "./AgenticaEventBase";
|
|
3
3
|
import type { AgenticaEventSource } from "./AgenticaEventSource";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Options for the request.
|
|
20
|
-
*/
|
|
21
|
-
options?: OpenAI.RequestOptions | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Wait the completion.
|
|
24
|
-
*/
|
|
25
|
-
join: () => Promise<OpenAI.ChatCompletion>;
|
|
4
|
+
export type AgenticaResponseEvent = AgenticaResponseEvent.Streaming | AgenticaResponseEvent.NonStreaming;
|
|
5
|
+
export declare namespace AgenticaResponseEvent {
|
|
6
|
+
export type Streaming = Base<true, OpenAI.ChatCompletionCreateParamsStreaming, AsyncGenerator<OpenAI.ChatCompletionChunk, undefined, undefined>>;
|
|
7
|
+
export type NonStreaming = Base<false, OpenAI.ChatCompletionCreateParamsNonStreaming, OpenAI.ChatCompletion>;
|
|
8
|
+
interface Base<Stream extends boolean, Body extends object, Completion extends object> extends AgenticaEventBase<"response"> {
|
|
9
|
+
source: AgenticaEventSource;
|
|
10
|
+
request_id: string;
|
|
11
|
+
stream: Stream;
|
|
12
|
+
body: Body;
|
|
13
|
+
completion: Completion;
|
|
14
|
+
options?: OpenAI.RequestOptions | undefined;
|
|
15
|
+
join: () => Promise<OpenAI.ChatCompletion>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
26
18
|
}
|
package/lib/factory/events.d.ts
CHANGED
|
@@ -65,16 +65,18 @@ export declare function createDescribeEvent(props: {
|
|
|
65
65
|
get: () => string;
|
|
66
66
|
join: () => Promise<string>;
|
|
67
67
|
}): AgenticaDescribeEvent;
|
|
68
|
-
export declare function createRequestEvent(props: {
|
|
68
|
+
export declare function createRequestEvent<Stream extends boolean>(props: {
|
|
69
69
|
source: AgenticaEventSource;
|
|
70
|
-
|
|
70
|
+
stream: Stream;
|
|
71
|
+
body: Stream extends true ? OpenAI.ChatCompletionCreateParamsStreaming : OpenAI.ChatCompletionCreateParamsNonStreaming;
|
|
71
72
|
options?: OpenAI.RequestOptions | undefined;
|
|
72
73
|
}): AgenticaRequestEvent;
|
|
73
|
-
export declare function createResponseEvent(props: {
|
|
74
|
+
export declare function createResponseEvent<Stream extends boolean>(props: {
|
|
74
75
|
request_id: string;
|
|
75
76
|
source: AgenticaEventSource;
|
|
76
|
-
|
|
77
|
+
stream: Stream;
|
|
78
|
+
body: Stream extends true ? OpenAI.ChatCompletionCreateParamsStreaming : OpenAI.ChatCompletionCreateParamsNonStreaming;
|
|
77
79
|
options?: OpenAI.RequestOptions | undefined;
|
|
78
|
-
|
|
80
|
+
completion: Stream extends true ? AsyncGenerator<OpenAI.ChatCompletionChunk, undefined, undefined> : OpenAI.ChatCompletion;
|
|
79
81
|
join: () => Promise<OpenAI.ChatCompletion>;
|
|
80
82
|
}): AgenticaResponseEvent;
|
package/lib/factory/events.js
CHANGED
|
@@ -250,6 +250,7 @@ function createRequestEvent(props) {
|
|
|
250
250
|
id,
|
|
251
251
|
created_at,
|
|
252
252
|
source: props.source,
|
|
253
|
+
stream: props.stream,
|
|
253
254
|
body: props.body,
|
|
254
255
|
options: props.options,
|
|
255
256
|
};
|
|
@@ -263,9 +264,10 @@ function createResponseEvent(props) {
|
|
|
263
264
|
request_id: props.request_id,
|
|
264
265
|
created_at,
|
|
265
266
|
source: props.source,
|
|
267
|
+
stream: props.stream,
|
|
266
268
|
body: props.body,
|
|
269
|
+
completion: props.completion,
|
|
267
270
|
options: props.options,
|
|
268
|
-
stream: props.stream,
|
|
269
271
|
join: props.join,
|
|
270
272
|
};
|
|
271
273
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/factory/events.ts"],"names":[],"mappings":";;AAiCA,sDAYC;AAED,8CAsBC;AAED,8CAiBC;AAKD,0CAoBC;AAED,8DAmBC;AAED,kDA0BC;AAED,gDAqCC;AAKD,wDAsBC;AAED,kEAkCC;AAED,kDAuCC;AAKD,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/factory/events.ts"],"names":[],"mappings":";;AAiCA,sDAYC;AAED,8CAsBC;AAED,8CAiBC;AAKD,0CAoBC;AAED,8DAmBC;AAED,kDA0BC;AAED,gDAqCC;AAKD,wDAsBC;AAED,kEAkCC;AAED,kDAuCC;AAKD,gDAmBC;AAED,kDA2BC;AAnWD,+BAA0B;AAqB1B,2CAIqB;AAErB;;8DAE8D;AAC9D,SAAgB,qBAAqB;IACnC,MAAM,KAAK,GAAmC;QAC5C,EAAE,EAAE,IAAA,SAAE,GAAE;QACR,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACrC,CAAC;IACF,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,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AAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAe;QAC7B,IAAI,EAAE,KAAK,CAAC,IAAqD;QACjE,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CAAyB,KAY3D;IACC,MAAM,EAAE,GAAW,IAAA,SAAE,GAAE,CAAC;IACxB,MAAM,UAAU,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,EAAE;QACF,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,UAAU;QACV,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAe;QAC7B,IAAI,EAAE,KAAK,CAAC,IAAqD;QACjE,UAAU,EAAE,KAAK,CAAC,UAAmC;QACrD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC;AACJ,CAAC"}
|
package/lib/index.mjs
CHANGED
|
@@ -749,6 +749,7 @@ function createRequestEvent(props) {
|
|
|
749
749
|
id,
|
|
750
750
|
created_at,
|
|
751
751
|
source: props.source,
|
|
752
|
+
stream: props.stream,
|
|
752
753
|
body: props.body,
|
|
753
754
|
options: props.options
|
|
754
755
|
};
|
|
@@ -763,9 +764,10 @@ function createResponseEvent(props) {
|
|
|
763
764
|
request_id: props.request_id,
|
|
764
765
|
created_at,
|
|
765
766
|
source: props.source,
|
|
767
|
+
stream: props.stream,
|
|
766
768
|
body: props.body,
|
|
769
|
+
completion: props.completion,
|
|
767
770
|
options: props.options,
|
|
768
|
-
stream: props.stream,
|
|
769
771
|
join: props.join
|
|
770
772
|
};
|
|
771
773
|
}
|
|
@@ -1141,8 +1143,8 @@ function transformCompletionChunk(source) {
|
|
|
1141
1143
|
}
|
|
1142
1144
|
|
|
1143
1145
|
function accumulate(origin, chunk) {
|
|
1144
|
-
const choices = origin.choices;
|
|
1145
|
-
chunk.choices.forEach((choice => {
|
|
1146
|
+
const choices = origin.choices ?? [];
|
|
1147
|
+
(chunk.choices ?? []).forEach((choice => {
|
|
1146
1148
|
const accChoice = choices[choice.index];
|
|
1147
1149
|
if (accChoice != null) {
|
|
1148
1150
|
choices[choice.index] = mergeChoice(accChoice, choice);
|
|
@@ -1204,7 +1206,7 @@ function merge(chunks) {
|
|
|
1204
1206
|
service_tier: firstChunk.service_tier,
|
|
1205
1207
|
system_fingerprint: firstChunk.system_fingerprint
|
|
1206
1208
|
});
|
|
1207
|
-
result.choices
|
|
1209
|
+
result.choices?.forEach((choice => {
|
|
1208
1210
|
choice.message.tool_calls?.filter((tc => tc.type === "function")).forEach((toolCall => {
|
|
1209
1211
|
if (toolCall.function.arguments === "") {
|
|
1210
1212
|
toolCall.function.arguments = "{}";
|
|
@@ -1529,10 +1531,10 @@ async function reduceStreamingWithDispatch(stream, eventProcessor, abortSignal)
|
|
|
1529
1531
|
}
|
|
1530
1532
|
};
|
|
1531
1533
|
if (acc.object === "chat.completion.chunk") {
|
|
1532
|
-
registerContext([ acc, chunk ].flatMap((v => v.choices)));
|
|
1534
|
+
registerContext([ acc, chunk ].flatMap((v => v.choices ?? [])));
|
|
1533
1535
|
return ChatGptCompletionMessageUtil.merge([ acc, chunk ]);
|
|
1534
1536
|
}
|
|
1535
|
-
registerContext(chunk.choices);
|
|
1537
|
+
registerContext(chunk.choices ?? []);
|
|
1536
1538
|
return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
1537
1539
|
}), {
|
|
1538
1540
|
abortSignal
|
|
@@ -1630,9 +1632,9 @@ async function call(ctx, operations) {
|
|
|
1630
1632
|
const event = createAssistantMessageEvent(props);
|
|
1631
1633
|
void ctx.dispatch(event).catch((() => {}));
|
|
1632
1634
|
}));
|
|
1633
|
-
const allAssistantMessagesEmpty = completion.choices.every((v => v.message.tool_calls == null && v.message.content === ""));
|
|
1635
|
+
const allAssistantMessagesEmpty = (completion.choices ?? []).every((v => v.message.tool_calls == null && v.message.content === ""));
|
|
1634
1636
|
if (allAssistantMessagesEmpty) {
|
|
1635
|
-
const firstChoice = completion.choices
|
|
1637
|
+
const firstChoice = completion.choices?.[0];
|
|
1636
1638
|
if (firstChoice?.message?.reasoning != null) {
|
|
1637
1639
|
throw new AssistantMessageEmptyWithReasoningError(firstChoice?.message?.reasoning ?? "");
|
|
1638
1640
|
}
|
|
@@ -1652,7 +1654,7 @@ async function call(ctx, operations) {
|
|
|
1652
1654
|
}
|
|
1653
1655
|
const executes = [];
|
|
1654
1656
|
const retry = ctx.config?.retry ?? AgenticaConstant.RETRY;
|
|
1655
|
-
for (const choice of completion.choices) {
|
|
1657
|
+
for (const choice of completion.choices ?? []) {
|
|
1656
1658
|
for (const tc of choice.message.tool_calls ?? []) {
|
|
1657
1659
|
if (tc.type === "function") {
|
|
1658
1660
|
const operation = operations.find((s => s.name === tc.function.name));
|
|
@@ -1815,7 +1817,7 @@ async function correctError(ctx, props) {
|
|
|
1815
1817
|
}
|
|
1816
1818
|
return ChatGptCompletionMessageUtil.merge(await StreamUtil.readAll(result.value));
|
|
1817
1819
|
})();
|
|
1818
|
-
const toolCall = completion.choices[0]?.message.tool_calls?.filter((tc => tc.type === "function")).find((s => s.function.name === props.operation.name));
|
|
1820
|
+
const toolCall = completion.choices?.[0]?.message.tool_calls?.filter((tc => tc.type === "function")).find((s => s.function.name === props.operation.name));
|
|
1819
1821
|
return toolCall === undefined ? props.giveUp() : predicate(ctx, props.operation, toolCall, props.previousValidationErrors, props.life);
|
|
1820
1822
|
}
|
|
1821
1823
|
|
|
@@ -2068,7 +2070,7 @@ async function step$1(ctx, operations, retry, failures) {
|
|
|
2068
2070
|
})();
|
|
2069
2071
|
if (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)) {
|
|
2070
2072
|
const failures = [];
|
|
2071
|
-
for (const choice of completion.choices) {
|
|
2073
|
+
for (const choice of completion.choices ?? []) {
|
|
2072
2074
|
for (const tc of choice.message.tool_calls ?? []) {
|
|
2073
2075
|
if (tc.type !== "function" || tc.function.name !== "cancelFunctions") {
|
|
2074
2076
|
continue;
|
|
@@ -2148,7 +2150,7 @@ async function step$1(ctx, operations, retry, failures) {
|
|
|
2148
2150
|
return step$1(ctx, operations, retry, failures);
|
|
2149
2151
|
}
|
|
2150
2152
|
}
|
|
2151
|
-
for (const choice of completion.choices) {
|
|
2153
|
+
for (const choice of completion.choices ?? []) {
|
|
2152
2154
|
if (choice.message.tool_calls != null) {
|
|
2153
2155
|
for (const tc of choice.message.tool_calls) {
|
|
2154
2156
|
if (tc.type !== "function") {
|
|
@@ -2211,7 +2213,7 @@ async function describe(ctx, histories) {
|
|
|
2211
2213
|
} ]
|
|
2212
2214
|
});
|
|
2213
2215
|
if (result.type === "none-stream") {
|
|
2214
|
-
const message = result.value.choices[0]?.message.content ?? "";
|
|
2216
|
+
const message = result.value.choices?.[0]?.message.content ?? "";
|
|
2215
2217
|
const event = createDescribeEvent({
|
|
2216
2218
|
executes: histories,
|
|
2217
2219
|
stream: toAsyncGenerator(message),
|
|
@@ -3096,7 +3098,7 @@ async function initialize(ctx) {
|
|
|
3096
3098
|
tool_choice: "auto"
|
|
3097
3099
|
});
|
|
3098
3100
|
if (result.type === "none-stream") {
|
|
3099
|
-
const message = result.value.choices[0]?.message.content ?? "";
|
|
3101
|
+
const message = result.value.choices?.[0]?.message.content ?? "";
|
|
3100
3102
|
const event = createAssistantMessageEvent({
|
|
3101
3103
|
stream: toAsyncGenerator(message),
|
|
3102
3104
|
done: () => true,
|
|
@@ -3113,7 +3115,7 @@ async function initialize(ctx) {
|
|
|
3113
3115
|
if (completion === null) {
|
|
3114
3116
|
throw new Error("No completion received");
|
|
3115
3117
|
}
|
|
3116
|
-
if (completion.choices
|
|
3118
|
+
if (completion.choices?.some((c => c.message.tool_calls != null && c.message.tool_calls.some((tc => tc.type === "function" && tc.function.name === FUNCTION.name))))) {
|
|
3117
3119
|
await ctx.initialize();
|
|
3118
3120
|
}
|
|
3119
3121
|
}
|
|
@@ -3313,9 +3315,9 @@ async function step(ctx, operations, retry, failures) {
|
|
|
3313
3315
|
});
|
|
3314
3316
|
if (result.type === "none-stream") {
|
|
3315
3317
|
const completion = result.value;
|
|
3316
|
-
const allAssistantMessagesEmpty = completion.choices
|
|
3318
|
+
const allAssistantMessagesEmpty = !!completion.choices?.every((v => v.message.tool_calls == null && v.message.content === ""));
|
|
3317
3319
|
if (allAssistantMessagesEmpty) {
|
|
3318
|
-
const firstChoice = completion.choices
|
|
3320
|
+
const firstChoice = completion.choices?.at(0);
|
|
3319
3321
|
if (firstChoice?.message?.reasoning != null) {
|
|
3320
3322
|
throw new AssistantMessageEmptyWithReasoningError(firstChoice?.message?.reasoning ?? "");
|
|
3321
3323
|
}
|
|
@@ -3327,9 +3329,9 @@ async function step(ctx, operations, retry, failures) {
|
|
|
3327
3329
|
const event = createAssistantMessageEvent(props);
|
|
3328
3330
|
void ctx.dispatch(event).catch((() => {}));
|
|
3329
3331
|
}), ctx.abortSignal);
|
|
3330
|
-
const allAssistantMessagesEmpty = completion.choices
|
|
3332
|
+
const allAssistantMessagesEmpty = !!completion.choices?.every((v => v.message.tool_calls == null && v.message.content === ""));
|
|
3331
3333
|
if (allAssistantMessagesEmpty) {
|
|
3332
|
-
const firstChoice = completion.choices
|
|
3334
|
+
const firstChoice = completion.choices?.at(0);
|
|
3333
3335
|
if (firstChoice?.message?.reasoning != null) {
|
|
3334
3336
|
throw new AssistantMessageEmptyWithReasoningError(firstChoice?.message?.reasoning ?? "");
|
|
3335
3337
|
}
|
|
@@ -3349,7 +3351,7 @@ async function step(ctx, operations, retry, failures) {
|
|
|
3349
3351
|
}
|
|
3350
3352
|
if (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)) {
|
|
3351
3353
|
const failures = [];
|
|
3352
|
-
for (const choice of completion.choices) {
|
|
3354
|
+
for (const choice of completion.choices ?? []) {
|
|
3353
3355
|
for (const tc of choice.message.tool_calls ?? []) {
|
|
3354
3356
|
if (tc.type !== "function" || tc.function.name !== "selectFunctions") {
|
|
3355
3357
|
continue;
|
|
@@ -3429,7 +3431,7 @@ async function step(ctx, operations, retry, failures) {
|
|
|
3429
3431
|
return step(ctx, operations, retry, failures);
|
|
3430
3432
|
}
|
|
3431
3433
|
}
|
|
3432
|
-
for (const choice of completion.choices) {
|
|
3434
|
+
for (const choice of completion.choices ?? []) {
|
|
3433
3435
|
if (choice.message.tool_calls != null) {
|
|
3434
3436
|
for (const tc of choice.message.tool_calls) {
|
|
3435
3437
|
if (tc.type !== "function") {
|
|
@@ -3656,6 +3658,7 @@ function getChatCompletionFunction(props) {
|
|
|
3656
3658
|
};
|
|
3657
3659
|
const event = createRequestEvent({
|
|
3658
3660
|
source,
|
|
3661
|
+
stream: streamOptions.stream,
|
|
3659
3662
|
body: {
|
|
3660
3663
|
...body,
|
|
3661
3664
|
model: props.vendor.model,
|
|
@@ -3686,6 +3689,25 @@ function getChatCompletionFunction(props) {
|
|
|
3686
3689
|
}
|
|
3687
3690
|
})();
|
|
3688
3691
|
if ("toReadableStream" in completion === false) {
|
|
3692
|
+
if (completion.usage != null) {
|
|
3693
|
+
AgenticaTokenUsageAggregator.aggregate({
|
|
3694
|
+
kind: source,
|
|
3695
|
+
completionUsage: completion.usage,
|
|
3696
|
+
usage: props.usage
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
void props.dispatch({
|
|
3700
|
+
id: v4(),
|
|
3701
|
+
type: "response",
|
|
3702
|
+
request_id: event.id,
|
|
3703
|
+
source,
|
|
3704
|
+
stream: false,
|
|
3705
|
+
body: event.body,
|
|
3706
|
+
completion,
|
|
3707
|
+
options: event.options,
|
|
3708
|
+
join: async () => completion,
|
|
3709
|
+
created_at: (new Date).toISOString()
|
|
3710
|
+
}).catch((() => {}));
|
|
3689
3711
|
return {
|
|
3690
3712
|
type: "none-stream",
|
|
3691
3713
|
value: completion
|
|
@@ -3715,8 +3737,9 @@ function getChatCompletionFunction(props) {
|
|
|
3715
3737
|
type: "response",
|
|
3716
3738
|
request_id: event.id,
|
|
3717
3739
|
source,
|
|
3718
|
-
stream:
|
|
3740
|
+
stream: true,
|
|
3719
3741
|
body: event.body,
|
|
3742
|
+
completion: streamDefaultReaderToAsyncGenerator(streamForStream.getReader(), props.abortSignal),
|
|
3720
3743
|
options: event.options,
|
|
3721
3744
|
join: async () => {
|
|
3722
3745
|
const chunks = await StreamUtil.readAll(streamForJoin, props.abortSignal);
|