@agentica/core 0.16.4 → 0.16.7-fix-for-wrtn
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/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +17 -426
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.js +13 -18
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +3 -2
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/execute.js +0 -7
- package/lib/orchestrate/execute.js.map +1 -1
- package/lib/orchestrate/internal/cancelFunction.js +13 -24
- package/lib/orchestrate/internal/cancelFunction.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.js +7 -407
- package/lib/utils/ChatGptCompletionMessageUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/orchestrate/call.ts +15 -22
- package/src/orchestrate/cancel.ts +3 -2
- package/src/orchestrate/execute.ts +0 -7
- package/src/orchestrate/internal/cancelFunction.ts +4 -4
- package/src/utils/ChatGptCompletionMessageUtil.ts +7 -6
|
@@ -9,7 +9,6 @@ import { call } from "./call";
|
|
|
9
9
|
import { cancel } from "./cancel";
|
|
10
10
|
import { describe } from "./describe";
|
|
11
11
|
import { initialize } from "./initialize";
|
|
12
|
-
import { cancelFunction } from "./internal/cancelFunction";
|
|
13
12
|
import { select } from "./select";
|
|
14
13
|
|
|
15
14
|
export function execute<Model extends ILlmSchema.Model>(executor: Partial<IAgenticaExecutor<Model>> | null) {
|
|
@@ -64,12 +63,6 @@ export function execute<Model extends ILlmSchema.Model>(executor: Partial<IAgent
|
|
|
64
63
|
const executes: AgenticaExecuteHistory<Model>[] = prompts.filter(
|
|
65
64
|
prompt => prompt.type === "execute",
|
|
66
65
|
);
|
|
67
|
-
for (const e of executes) {
|
|
68
|
-
await cancelFunction(ctx, {
|
|
69
|
-
reason: "completed",
|
|
70
|
-
name: e.operation.name,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
66
|
histories.push(
|
|
74
67
|
...(await (
|
|
75
68
|
executor?.describe ?? describe
|
|
@@ -10,10 +10,10 @@ import { createOperationSelection } from "../../factory/operations";
|
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export function cancelFunction<Model extends ILlmSchema.Model>(
|
|
14
14
|
ctx: AgenticaContext<Model>,
|
|
15
15
|
reference: __IChatFunctionReference,
|
|
16
|
-
):
|
|
16
|
+
): AgenticaOperationSelection<Model> | null {
|
|
17
17
|
const index: number = ctx.stack.findIndex(
|
|
18
18
|
item => item.operation.name === reference.name,
|
|
19
19
|
);
|
|
@@ -23,13 +23,13 @@ export async function cancelFunction<Model extends ILlmSchema.Model>(
|
|
|
23
23
|
|
|
24
24
|
const item: AgenticaOperationSelection<Model> = ctx.stack[index]!;
|
|
25
25
|
ctx.stack.splice(index, 1);
|
|
26
|
-
|
|
26
|
+
ctx.dispatch(
|
|
27
27
|
createCancelEvent({
|
|
28
28
|
selection: createOperationSelection({
|
|
29
29
|
operation: item.operation,
|
|
30
30
|
reason: reference.reason,
|
|
31
31
|
}),
|
|
32
32
|
}),
|
|
33
|
-
);
|
|
33
|
+
).catch(() => {});
|
|
34
34
|
return item;
|
|
35
35
|
}
|
|
@@ -3,20 +3,21 @@ import type {
|
|
|
3
3
|
ChatCompletionChunk,
|
|
4
4
|
ChatCompletionMessage,
|
|
5
5
|
ChatCompletionMessageToolCall,
|
|
6
|
-
CompletionUsage,
|
|
7
6
|
} from "openai/resources";
|
|
8
7
|
|
|
9
|
-
import
|
|
10
|
-
|
|
8
|
+
// import typia from "typia";
|
|
11
9
|
import { ByteArrayUtil } from "./ByteArrayUtil";
|
|
12
10
|
import { ChatGptTokenUsageAggregator } from "./ChatGptTokenUsageAggregator";
|
|
13
11
|
|
|
14
12
|
function transformCompletionChunk(source: string | Uint8Array): ChatCompletionChunk {
|
|
15
13
|
const str
|
|
16
14
|
= source instanceof Uint8Array ? ByteArrayUtil.toUtf8(source) : source;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const result: ChatCompletionChunk = JSON.parse(str) as ChatCompletionChunk;
|
|
16
|
+
// const valid = typia.validate<ChatCompletionChunk>(result);
|
|
17
|
+
// if (valid.success === false) {
|
|
18
|
+
// console.error("Invalid ChatCompletionChunk", valid.errors);
|
|
19
|
+
// }
|
|
20
|
+
return result;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function accumulate(origin: ChatCompletion, chunk: ChatCompletionChunk): ChatCompletion {
|