@zimtsui/brainswitch 0.0.54 → 0.0.56
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/DEVELOPMENT.md +13 -14
- package/README.md +7 -14
- package/build/adaptor.d.ts +5 -5
- package/build/adaptor.js +16 -16
- package/build/adaptor.js.map +1 -1
- package/build/agentloop.d.ts +5 -5
- package/build/agentloop.js +4 -4
- package/build/agentloop.js.map +1 -1
- package/build/api-types/anthropic/billing.d.ts +12 -0
- package/build/api-types/anthropic/billing.js +15 -0
- package/build/api-types/anthropic/billing.js.map +1 -0
- package/build/api-types/anthropic/tool-codec.d.ts +17 -0
- package/build/api-types/anthropic/tool-codec.js +73 -0
- package/build/api-types/anthropic/tool-codec.js.map +1 -0
- package/build/api-types/google/billing.d.ts +12 -0
- package/build/api-types/google/billing.js +24 -0
- package/build/api-types/google/billing.js.map +1 -0
- package/build/api-types/google/restful-request.d.ts +8 -0
- package/build/api-types/google/restful-request.js +2 -0
- package/build/api-types/google/restful-request.js.map +1 -0
- package/build/api-types/google/tool-codec.d.ts +16 -0
- package/build/api-types/{google.js → google/tool-codec.js} +27 -26
- package/build/api-types/google/tool-codec.js.map +1 -0
- package/build/api-types/openai-chatcompletion/billing.d.ts +13 -0
- package/build/api-types/openai-chatcompletion/billing.js +16 -0
- package/build/api-types/openai-chatcompletion/billing.js.map +1 -0
- package/build/api-types/openai-chatcompletion/tool-codec.d.ts +18 -0
- package/build/api-types/openai-chatcompletion/tool-codec.js +86 -0
- package/build/api-types/openai-chatcompletion/tool-codec.js.map +1 -0
- package/build/api-types/openai-responses/billing.d.ts +12 -0
- package/build/api-types/openai-responses/billing.js +15 -0
- package/build/api-types/openai-responses/billing.js.map +1 -0
- package/build/api-types/openai-responses/tool-codec.d.ts +16 -0
- package/build/api-types/openai-responses/tool-codec.js +72 -0
- package/build/api-types/openai-responses/tool-codec.js.map +1 -0
- package/build/compatible/engine.d/aliyun.d.ts +23 -0
- package/build/compatible/engine.d/aliyun.js +44 -0
- package/build/compatible/engine.d/aliyun.js.map +1 -0
- package/build/compatible/engine.d/anthropic.d.ts +23 -0
- package/build/compatible/engine.d/anthropic.js +41 -0
- package/build/compatible/engine.d/anthropic.js.map +1 -0
- package/build/compatible/engine.d/google.d.ts +23 -0
- package/build/compatible/engine.d/google.js +45 -0
- package/build/compatible/engine.d/google.js.map +1 -0
- package/build/compatible/engine.d/openai-responses.d.ts +23 -0
- package/build/compatible/engine.d/openai-responses.js +41 -0
- package/build/compatible/engine.d/openai-responses.js.map +1 -0
- package/build/compatible/engine.d.ts +18 -0
- package/build/compatible/engine.js +21 -0
- package/build/compatible/engine.js.map +1 -0
- package/build/compatible/session.d.ts +78 -0
- package/build/compatible/session.js +138 -0
- package/build/compatible/session.js.map +1 -0
- package/build/compatible/tool-call-validator.d.ts +11 -0
- package/build/compatible/tool-call-validator.js +12 -0
- package/build/compatible/tool-call-validator.js.map +1 -0
- package/build/compatible.d/aliyun/transport.d.ts +11 -0
- package/build/compatible.d/aliyun/transport.js +9 -0
- package/build/compatible.d/aliyun/transport.js.map +1 -0
- package/build/compatible.d/anthropic/message-codec.d.ts +31 -0
- package/build/compatible.d/anthropic/message-codec.js +88 -0
- package/build/compatible.d/anthropic/message-codec.js.map +1 -0
- package/build/compatible.d/anthropic/transport.d.ts +31 -0
- package/build/compatible.d/anthropic/transport.js +137 -0
- package/build/compatible.d/anthropic/transport.js.map +1 -0
- package/build/compatible.d/google/message-codec.d.ts +31 -0
- package/build/compatible.d/google/message-codec.js +98 -0
- package/build/compatible.d/google/message-codec.js.map +1 -0
- package/build/compatible.d/google/transport.d.ts +28 -0
- package/build/compatible.d/google/transport.js +74 -0
- package/build/compatible.d/google/transport.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions/message-codec.d.ts +19 -0
- package/build/compatible.d/openai-chatcompletions/message-codec.js +66 -0
- package/build/compatible.d/openai-chatcompletions/message-codec.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions/transport.d.ts +9 -0
- package/build/compatible.d/openai-chatcompletions/transport.js +25 -0
- package/build/compatible.d/openai-chatcompletions/transport.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions.d/monolith.d.ts +36 -0
- package/build/compatible.d/openai-chatcompletions.d/monolith.js +74 -0
- package/build/compatible.d/openai-chatcompletions.d/monolith.js.map +1 -0
- package/build/compatible.d/openai-chatcompletions.d/stream.d.ts +35 -0
- package/build/{compatible-engines.d → compatible.d}/openai-chatcompletions.d/stream.js +52 -42
- package/build/compatible.d/openai-chatcompletions.d/stream.js.map +1 -0
- package/build/compatible.d/openai-responses/message-codec.d.ts +32 -0
- package/build/compatible.d/openai-responses/message-codec.js +105 -0
- package/build/compatible.d/openai-responses/message-codec.js.map +1 -0
- package/build/compatible.d/openai-responses/transport.d.ts +33 -0
- package/build/compatible.d/openai-responses/transport.js +88 -0
- package/build/compatible.d/openai-responses/transport.js.map +1 -0
- package/build/config.js +1 -1
- package/build/config.js.map +1 -1
- package/build/engine.d.ts +48 -26
- package/build/engine.js +78 -29
- package/build/engine.js.map +1 -1
- package/build/exports.d.ts +14 -13
- package/build/exports.js +14 -13
- package/build/exports.js.map +1 -1
- package/build/function.d.ts +25 -13
- package/build/function.js +2 -1
- package/build/function.js.map +1 -1
- package/build/inference-context.d.ts +1 -1
- package/build/native-engines.d/google/agentloop.d.ts +6 -6
- package/build/native-engines.d/google/agentloop.js +5 -5
- package/build/native-engines.d/google/agentloop.js.map +1 -1
- package/build/native-engines.d/google/engine.d.ts +28 -103
- package/build/native-engines.d/google/engine.js +63 -304
- package/build/native-engines.d/google/engine.js.map +1 -1
- package/build/native-engines.d/google/exports.d.ts +5 -5
- package/build/native-engines.d/google/exports.js +5 -5
- package/build/native-engines.d/google/exports.js.map +1 -1
- package/build/native-engines.d/google/message-codec.d.ts +21 -0
- package/build/native-engines.d/google/message-codec.js +69 -0
- package/build/native-engines.d/google/message-codec.js.map +1 -0
- package/build/native-engines.d/google/session.d.ts +16 -15
- package/build/native-engines.d/google/session.js +2 -2
- package/build/native-engines.d/google/session.js.map +1 -1
- package/build/native-engines.d/google/transport.d.ts +31 -0
- package/build/native-engines.d/google/transport.js +81 -0
- package/build/native-engines.d/google/transport.js.map +1 -0
- package/build/native-engines.d/openai-responses/agentloop.d.ts +7 -7
- package/build/native-engines.d/openai-responses/agentloop.js +6 -6
- package/build/native-engines.d/openai-responses/agentloop.js.map +1 -1
- package/build/native-engines.d/openai-responses/engine.d.ts +26 -106
- package/build/native-engines.d/openai-responses/engine.js +53 -334
- package/build/native-engines.d/openai-responses/engine.js.map +1 -1
- package/build/native-engines.d/openai-responses/exports.d.ts +6 -7
- package/build/native-engines.d/openai-responses/exports.js +6 -7
- package/build/native-engines.d/openai-responses/exports.js.map +1 -1
- package/build/native-engines.d/openai-responses/message-codec.d.ts +21 -0
- package/build/native-engines.d/openai-responses/message-codec.js +69 -0
- package/build/native-engines.d/openai-responses/message-codec.js.map +1 -0
- package/build/native-engines.d/openai-responses/session.d.ts +27 -26
- package/build/native-engines.d/openai-responses/session.js +3 -3
- package/build/native-engines.d/openai-responses/session.js.map +1 -1
- package/build/native-engines.d/openai-responses/tool-call-validator.d.ts +12 -0
- package/build/native-engines.d/openai-responses/tool-call-validator.js +33 -0
- package/build/native-engines.d/openai-responses/tool-call-validator.js.map +1 -0
- package/build/native-engines.d/openai-responses/tool.d.ts +3 -3
- package/build/native-engines.d/openai-responses/tool.js +1 -1
- package/build/native-engines.d/openai-responses/tool.js.map +1 -1
- package/build/native-engines.d/openai-responses/transport.d.ts +36 -0
- package/build/native-engines.d/openai-responses/transport.js +104 -0
- package/build/native-engines.d/openai-responses/transport.js.map +1 -0
- package/build/session.d.ts +5 -75
- package/build/session.js +0 -136
- package/build/session.js.map +1 -1
- package/build/throttle.d.ts +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/test/build/test-codecs.js +230 -0
- package/test/build/test-codecs.js.map +1 -0
- package/test/build/test-compatible-engine.d.ts +1 -0
- package/test/build/test-compatible-engine.js +27 -0
- package/test/build/test-compatible-engine.js.map +1 -0
- package/test/build/test-compatible-engines.d.ts +1 -0
- package/test/build/test-compatible-engines.js +112 -0
- package/test/build/test-compatible-engines.js.map +1 -0
- package/test/build/test-engine.d.ts +1 -0
- package/test/build/test-engine.js +97 -0
- package/test/build/test-engine.js.map +1 -0
- package/test/build/test-helpers.d.ts +46 -0
- package/test/build/test-helpers.js +45 -0
- package/test/build/test-helpers.js.map +1 -0
- package/test/build/test-native-engines.d.ts +1 -0
- package/test/build/test-native-engines.js +64 -0
- package/test/build/test-native-engines.js.map +1 -0
- package/test/build/test.d.ts +5 -0
- package/test/build/test.js +6 -0
- package/test/build/test.js.map +1 -0
- package/test/build/tsconfig.tsbuildinfo +1 -0
- package/test/src/test-codecs.ts +256 -0
- package/test/src/test-compatible-engine.ts +45 -0
- package/test/src/test-compatible-engines.ts +129 -0
- package/test/src/test-engine.ts +144 -0
- package/test/src/test-helpers.ts +53 -0
- package/test/src/test-native-engines.ts +75 -0
- package/test/src/test.ts +5 -0
- package/test/src/tsconfig.json +30 -0
- package/build/api-types/anthropic.d.ts +0 -29
- package/build/api-types/anthropic.js +0 -93
- package/build/api-types/anthropic.js.map +0 -1
- package/build/api-types/google.d.ts +0 -28
- package/build/api-types/google.js.map +0 -1
- package/build/api-types/openai-chat-completions.d.ts +0 -31
- package/build/api-types/openai-chat-completions.js +0 -113
- package/build/api-types/openai-chat-completions.js.map +0 -1
- package/build/api-types/openai-responses.d.ts +0 -23
- package/build/api-types/openai-responses.js +0 -71
- package/build/api-types/openai-responses.js.map +0 -1
- package/build/compatible-engine.d.ts +0 -51
- package/build/compatible-engine.js +0 -67
- package/build/compatible-engine.js.map +0 -1
- package/build/compatible-engines.d/aliyun.d.ts +0 -69
- package/build/compatible-engines.d/aliyun.js +0 -149
- package/build/compatible-engines.d/aliyun.js.map +0 -1
- package/build/compatible-engines.d/anthropic.d.ts +0 -78
- package/build/compatible-engines.d/anthropic.js +0 -312
- package/build/compatible-engines.d/anthropic.js.map +0 -1
- package/build/compatible-engines.d/google.d.ts +0 -83
- package/build/compatible-engines.d/google.js +0 -279
- package/build/compatible-engines.d/google.js.map +0 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +0 -15
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +0 -75
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +0 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +0 -21
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +0 -1
- package/build/compatible-engines.d/openai-chatcompletions.d.ts +0 -27
- package/build/compatible-engines.d/openai-chatcompletions.js +0 -76
- package/build/compatible-engines.d/openai-chatcompletions.js.map +0 -1
- package/build/compatible-engines.d/openai-responses.d.ts +0 -93
- package/build/compatible-engines.d/openai-responses.js +0 -300
- package/build/compatible-engines.d/openai-responses.js.map +0 -1
- package/build/test.js +0 -198
- package/build/test.js.map +0 -1
- /package/{build/test.d.ts → test/build/test-codecs.d.ts} +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { Function } from '#@/function.ts';
|
|
3
|
+
import { GoogleNativeEngine } from '#@/native-engines.d/google/engine.ts';
|
|
4
|
+
import { OpenAIResponsesNativeEngine } from '#@/native-engines.d/openai-responses/engine.ts';
|
|
5
|
+
import { Adaptor } from '#@/adaptor.ts';
|
|
6
|
+
import { Tool } from '#@/native-engines.d/openai-responses/tool.ts';
|
|
7
|
+
import { fdm, makeBaseOptions } from './test-helpers.ts';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GoogleNativeEngineProbe extends GoogleNativeEngine<fdm> {
|
|
11
|
+
public getToolChoice(): Function.ToolChoice<fdm> {
|
|
12
|
+
return this.toolChoice;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public getParallelToolCall(): boolean {
|
|
16
|
+
return this.parallelToolCall;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class OpenAIResponsesNativeEngineProbe extends OpenAIResponsesNativeEngine<fdm> {
|
|
21
|
+
public getToolChoice(): Tool.Choice<fdm> {
|
|
22
|
+
return this.toolChoice;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getParallelToolCall(): boolean {
|
|
26
|
+
return this.parallelToolCall;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
test('native engines preserve aggregated defaults', t => {
|
|
32
|
+
const googleEngine = new GoogleNativeEngineProbe({
|
|
33
|
+
...makeBaseOptions(),
|
|
34
|
+
apiType: 'google',
|
|
35
|
+
});
|
|
36
|
+
const openaiEngine = new OpenAIResponsesNativeEngineProbe({
|
|
37
|
+
...makeBaseOptions(),
|
|
38
|
+
apiType: 'openai-responses',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
t.is(googleEngine.getToolChoice(), Function.ToolChoice.AUTO);
|
|
42
|
+
t.true(googleEngine.getParallelToolCall());
|
|
43
|
+
|
|
44
|
+
t.is(openaiEngine.getToolChoice(), Function.ToolChoice.AUTO);
|
|
45
|
+
t.false(openaiEngine.getParallelToolCall());
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('Adaptor native engine factories return expected implementations', t => {
|
|
49
|
+
const adaptor = Adaptor.create({
|
|
50
|
+
brainswitch: {
|
|
51
|
+
endpoints: {
|
|
52
|
+
oa: {
|
|
53
|
+
baseUrl: 'https://example.com/v1',
|
|
54
|
+
apiKey: 'k',
|
|
55
|
+
model: 'm',
|
|
56
|
+
name: 'oa',
|
|
57
|
+
apiType: 'openai-responses',
|
|
58
|
+
},
|
|
59
|
+
gg: {
|
|
60
|
+
baseUrl: 'https://generativelanguage.googleapis.com',
|
|
61
|
+
apiKey: 'k',
|
|
62
|
+
model: 'gemini-test',
|
|
63
|
+
name: 'gg',
|
|
64
|
+
apiType: 'google',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const openaiEngine = adaptor.makeOpenAIResponsesNativeEngine('oa', fdm);
|
|
71
|
+
const googleEngine = adaptor.makeGoogleNativeEngine('gg', fdm);
|
|
72
|
+
|
|
73
|
+
t.true(openaiEngine instanceof OpenAIResponsesNativeEngine);
|
|
74
|
+
t.true(googleEngine instanceof GoogleNativeEngine);
|
|
75
|
+
});
|
package/test/src/test.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "preserve",
|
|
5
|
+
"moduleDetection": "force",
|
|
6
|
+
"lib": ["esnext"],
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"noUncheckedIndexedAccess": true,
|
|
11
|
+
"noUncheckedSideEffectImports": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"rewriteRelativeImportExtensions": true,
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noImplicitOverride": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"checkJs": true,
|
|
20
|
+
"composite": true,
|
|
21
|
+
"outDir": "../build",
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"./**/*",
|
|
26
|
+
],
|
|
27
|
+
"references": [
|
|
28
|
+
{ "path": "../../src/tsconfig.json" },
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Function } from '../function.ts';
|
|
2
|
-
import { type Engine } from '../engine.ts';
|
|
3
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
4
|
-
export declare namespace AnthropicEngine {
|
|
5
|
-
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
-
}
|
|
7
|
-
interface OwnProps {
|
|
8
|
-
parallelToolCall: boolean;
|
|
9
|
-
anthropic: Anthropic;
|
|
10
|
-
}
|
|
11
|
-
namespace OwnProps {
|
|
12
|
-
function init<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, options: Options<fdm>): OwnProps;
|
|
13
|
-
}
|
|
14
|
-
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
15
|
-
parallelToolCall: boolean;
|
|
16
|
-
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolUseBlock;
|
|
17
|
-
convertToFunctionCall(apifc: Anthropic.ToolUseBlock): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
18
|
-
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolResultBlockParam;
|
|
19
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Anthropic.Tool;
|
|
20
|
-
convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>, parallelToolCall: boolean): Anthropic.ToolChoice;
|
|
21
|
-
calcCost(usage: Anthropic.Usage): number;
|
|
22
|
-
}
|
|
23
|
-
function convertFromFunctionCall<fdm extends Function.Declaration.Map>(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolUseBlock;
|
|
24
|
-
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: Anthropic.ToolUseBlock): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
25
|
-
function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): Anthropic.ToolResultBlockParam;
|
|
26
|
-
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): Anthropic.Tool;
|
|
27
|
-
function convertFromToolChoice<fdm extends Function.Declaration.Map>(toolChoice: Function.ToolChoice<fdm>, parallelToolCall: boolean): Anthropic.ToolChoice;
|
|
28
|
-
function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: Anthropic.Usage): number;
|
|
29
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Function } from "../function.js";
|
|
2
|
-
import { ResponseInvalid } from "../engine.js";
|
|
3
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
4
|
-
import Ajv from 'ajv';
|
|
5
|
-
import {} from '@sinclair/typebox';
|
|
6
|
-
const ajv = new Ajv();
|
|
7
|
-
export var AnthropicEngine;
|
|
8
|
-
(function (AnthropicEngine) {
|
|
9
|
-
let OwnProps;
|
|
10
|
-
(function (OwnProps) {
|
|
11
|
-
function init(options) {
|
|
12
|
-
return {
|
|
13
|
-
parallelToolCall: options.parallelToolCall ?? false,
|
|
14
|
-
anthropic: new Anthropic({
|
|
15
|
-
baseURL: this.baseUrl,
|
|
16
|
-
apiKey: this.apiKey,
|
|
17
|
-
fetchOptions: { dispatcher: this.proxyAgent },
|
|
18
|
-
}),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
OwnProps.init = init;
|
|
22
|
-
})(OwnProps = AnthropicEngine.OwnProps || (AnthropicEngine.OwnProps = {}));
|
|
23
|
-
function convertFromFunctionCall(fc) {
|
|
24
|
-
throw new Error('Anthropic compatible engine requires native function calls.');
|
|
25
|
-
}
|
|
26
|
-
AnthropicEngine.convertFromFunctionCall = convertFromFunctionCall;
|
|
27
|
-
function convertToFunctionCall(apifc) {
|
|
28
|
-
const fditem = this.fdm[apifc.name];
|
|
29
|
-
if (fditem) { }
|
|
30
|
-
else
|
|
31
|
-
throw new ResponseInvalid('Unknown function call', { cause: apifc });
|
|
32
|
-
const args = (() => {
|
|
33
|
-
try {
|
|
34
|
-
return JSON.parse(apifc.input);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
throw new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
38
|
-
}
|
|
39
|
-
})();
|
|
40
|
-
if (ajv.validate(fditem.paraschema, args)) { }
|
|
41
|
-
else
|
|
42
|
-
throw new ResponseInvalid('Function call not conforming to schema', { cause: apifc });
|
|
43
|
-
return Function.Call.create({
|
|
44
|
-
id: apifc.id,
|
|
45
|
-
name: apifc.name,
|
|
46
|
-
args,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
AnthropicEngine.convertToFunctionCall = convertToFunctionCall;
|
|
50
|
-
function convertFromFunctionResponse(fr) {
|
|
51
|
-
if (fr.id) { }
|
|
52
|
-
else
|
|
53
|
-
throw new Error();
|
|
54
|
-
return {
|
|
55
|
-
type: 'tool_result',
|
|
56
|
-
tool_use_id: fr.id,
|
|
57
|
-
content: fr.text,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
AnthropicEngine.convertFromFunctionResponse = convertFromFunctionResponse;
|
|
61
|
-
function convertFromFunctionDeclarationEntry(fdentry) {
|
|
62
|
-
return {
|
|
63
|
-
name: fdentry[0],
|
|
64
|
-
description: fdentry[1].description,
|
|
65
|
-
input_schema: fdentry[1].paraschema,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
AnthropicEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
|
|
69
|
-
function convertFromToolChoice(toolChoice, parallelToolCall) {
|
|
70
|
-
if (toolChoice === Function.ToolChoice.NONE)
|
|
71
|
-
return { type: 'none' };
|
|
72
|
-
else if (toolChoice === Function.ToolChoice.REQUIRED)
|
|
73
|
-
return { type: 'any', disable_parallel_tool_use: !parallelToolCall };
|
|
74
|
-
else if (toolChoice === Function.ToolChoice.AUTO)
|
|
75
|
-
return { type: 'auto', disable_parallel_tool_use: !parallelToolCall };
|
|
76
|
-
else {
|
|
77
|
-
if (toolChoice.length === 1) { }
|
|
78
|
-
else
|
|
79
|
-
throw new Error();
|
|
80
|
-
return { type: 'tool', name: toolChoice[0], disable_parallel_tool_use: !parallelToolCall };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
AnthropicEngine.convertFromToolChoice = convertFromToolChoice;
|
|
84
|
-
function calcCost(usage) {
|
|
85
|
-
const cacheHitTokenCount = usage.cache_read_input_tokens || 0;
|
|
86
|
-
const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
|
|
87
|
-
return this.inputPrice * cacheMissTokenCount / 1e6 +
|
|
88
|
-
this.cachePrice * cacheHitTokenCount / 1e6 +
|
|
89
|
-
this.outputPrice * usage.output_tokens / 1e6;
|
|
90
|
-
}
|
|
91
|
-
AnthropicEngine.calcCost = calcCost;
|
|
92
|
-
})(AnthropicEngine || (AnthropicEngine = {}));
|
|
93
|
-
//# sourceMappingURL=anthropic.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/api-types/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAe,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAgB,MAAM,mBAAmB,CAAC;AAEjD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAItB,MAAM,KAAW,eAAe,CA8G/B;AA9GD,WAAiB,eAAe;IAO5B,IAAiB,QAAQ,CAcxB;IAdD,WAAiB,QAAQ;QACrB,SAAgB,IAAI,CAEhB,OAAqB;YAErB,OAAO;gBACH,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;gBACnD,SAAS,EAAE,IAAI,SAAS,CAAC;oBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,YAAY,EAAE,EAAE,UAAU,EAAE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AQ,CAEpB,KAAsB;QAEtB,MAAM,kBAAkB,GAAG,KAAK,CAAC,uBAAuB,IAAI,CAAC,CAAC;QAC9D,MAAM,mBAAmB,GAAG,KAAK,CAAC,YAAY,GAAG,kBAAkB,CAAC;QACpE,OAAO,IAAI,CAAC,UAAU,GAAG,mBAAmB,GAAG,GAAG;YAC1C,IAAI,CAAC,UAAU,GAAG,kBAAkB,GAAG,GAAG;YAC1C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC;IACzD,CAAC;IATe,wBAAQ,WASvB,CAAA;AAEL,CAAC,EA9GgB,eAAe,KAAf,eAAe,QA8G/B"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type Engine } from '../engine.ts';
|
|
2
|
-
import { Function } from '../function.ts';
|
|
3
|
-
import * as Google from '@google/genai';
|
|
4
|
-
export declare namespace GoogleEngine {
|
|
5
|
-
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
-
}
|
|
7
|
-
interface OwnProps {
|
|
8
|
-
parallelToolCall: boolean;
|
|
9
|
-
}
|
|
10
|
-
namespace OwnProps {
|
|
11
|
-
function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
|
|
12
|
-
}
|
|
13
|
-
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
14
|
-
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
|
|
15
|
-
convertToFunctionCall(googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
16
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
17
|
-
}
|
|
18
|
-
function convertFromFunctionCall<fdm extends Function.Declaration.Map>(this: GoogleEngine.Underhood<fdm>, fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
|
|
19
|
-
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(this: GoogleEngine.Underhood<fdm>, fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
|
|
20
|
-
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: GoogleEngine.Underhood<fdm>, googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
21
|
-
interface RestfulRequest {
|
|
22
|
-
contents: Google.Content[];
|
|
23
|
-
tools?: Google.Tool[];
|
|
24
|
-
toolConfig?: Google.ToolConfig;
|
|
25
|
-
systemInstruction?: Google.Content;
|
|
26
|
-
generationConfig?: Google.GenerationConfig;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/api-types/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AAItB,MAAM,KAAW,YAAY,CAoF5B;AApFD,WAAiB,YAAY;IAMzB,IAAiB,QAAQ,CAQxB;IARD,WAAiB,QAAQ;QACrB,SAAgB,IAAI,CAAuC,OAAqB;YAC5E,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,IAAI,CAAC;YAC1D,IAAI,gBAAgB,EAAE,CAAC,CAAA,CAAC;;gBAAM,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAC1F,OAAO;gBACH,gBAAgB;aACnB,CAAC;QACN,CAAC;QANe,aAAI,OAMnB,CAAA;IACL,CAAC,EARgB,QAAQ,GAAR,qBAAQ,KAAR,qBAAQ,QAQxB;IAWD,SAAgB,uBAAuB,CAE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,gDAAmC,sCAsBlD,CAAA;IAED,SAAgB,qBAAqB,CAEjC,QAA6B;QAE7B,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAoD,CAAC;QAC1F,IAAI,MAAM,EAAE,CAAC,CAAA,CAAC;;YAAM,MAAM,IAAI,eAAe,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5F,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA,CAAC;;YACjD,MAAM,IAAI,eAAe,CAAC,wCAAwC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9F,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;YACxB,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;SAC0C,CAAC,CAAC;IACvE,CAAC;IAde,kCAAqB,wBAcpC,CAAA;AAUL,CAAC,EApFgB,YAAY,KAAZ,YAAY,QAoF5B"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type Engine } from '../engine.ts';
|
|
2
|
-
import { Function } from '../function.ts';
|
|
3
|
-
import OpenAI from 'openai';
|
|
4
|
-
export declare namespace OpenAIChatCompletionsEngine {
|
|
5
|
-
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
-
}
|
|
7
|
-
interface OwnProps {
|
|
8
|
-
parallelToolCall: boolean;
|
|
9
|
-
}
|
|
10
|
-
namespace OwnProps {
|
|
11
|
-
function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
|
|
12
|
-
}
|
|
13
|
-
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
14
|
-
convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
|
|
15
|
-
convertToFunctionCall(apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
16
|
-
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
|
|
17
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
|
|
18
|
-
convertFromToolChoice(mode: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
|
|
19
|
-
calcCost(usage: OpenAI.CompletionUsage): number;
|
|
20
|
-
extractContent(completionContent: string): string;
|
|
21
|
-
handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
|
|
22
|
-
}
|
|
23
|
-
function convertFromFunctionCall<fdm extends Function.Declaration.Map>(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionMessageToolCall;
|
|
24
|
-
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: OpenAI.ChatCompletionMessageFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
25
|
-
function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.ChatCompletionToolMessageParam;
|
|
26
|
-
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.ChatCompletionTool;
|
|
27
|
-
function convertFromToolChoice<fdm extends Function.Declaration.Map>(toolChoice: Function.ToolChoice<fdm>): OpenAI.ChatCompletionToolChoiceOption;
|
|
28
|
-
function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: OpenAI.CompletionUsage): number;
|
|
29
|
-
function extractContent(completionContent: string): string;
|
|
30
|
-
function handleFinishReason(completion: OpenAI.ChatCompletion, finishReason: OpenAI.ChatCompletion.Choice['finish_reason']): void;
|
|
31
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { ResponseInvalid } from "../engine.js";
|
|
2
|
-
import { Function } from "../function.js";
|
|
3
|
-
import OpenAI from 'openai';
|
|
4
|
-
import { Ajv } from 'ajv';
|
|
5
|
-
const ajv = new Ajv();
|
|
6
|
-
export var OpenAIChatCompletionsEngine;
|
|
7
|
-
(function (OpenAIChatCompletionsEngine) {
|
|
8
|
-
let OwnProps;
|
|
9
|
-
(function (OwnProps) {
|
|
10
|
-
function init(options) {
|
|
11
|
-
return {
|
|
12
|
-
parallelToolCall: options.parallelToolCall ?? false,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
OwnProps.init = init;
|
|
16
|
-
})(OwnProps = OpenAIChatCompletionsEngine.OwnProps || (OpenAIChatCompletionsEngine.OwnProps = {}));
|
|
17
|
-
function convertFromFunctionCall(fc) {
|
|
18
|
-
if (fc.id) { }
|
|
19
|
-
else
|
|
20
|
-
throw new Error();
|
|
21
|
-
return {
|
|
22
|
-
id: fc.id,
|
|
23
|
-
type: 'function',
|
|
24
|
-
function: {
|
|
25
|
-
name: fc.name,
|
|
26
|
-
arguments: JSON.stringify(fc.args),
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
OpenAIChatCompletionsEngine.convertFromFunctionCall = convertFromFunctionCall;
|
|
31
|
-
function convertToFunctionCall(apifc) {
|
|
32
|
-
const fditem = this.fdm[apifc.function.name];
|
|
33
|
-
if (fditem) { }
|
|
34
|
-
else
|
|
35
|
-
throw new ResponseInvalid('Unknown function call', { cause: apifc });
|
|
36
|
-
const args = (() => {
|
|
37
|
-
try {
|
|
38
|
-
return JSON.parse(apifc.function.arguments);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
if (ajv.validate(fditem.paraschema, args)) { }
|
|
45
|
-
else
|
|
46
|
-
throw new ResponseInvalid('Invalid function arguments', { cause: apifc });
|
|
47
|
-
return Function.Call.create({
|
|
48
|
-
id: apifc.id,
|
|
49
|
-
name: apifc.function.name,
|
|
50
|
-
args,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
OpenAIChatCompletionsEngine.convertToFunctionCall = convertToFunctionCall;
|
|
54
|
-
function convertFromFunctionResponse(fr) {
|
|
55
|
-
if (fr.id) { }
|
|
56
|
-
else
|
|
57
|
-
throw new Error();
|
|
58
|
-
return {
|
|
59
|
-
role: 'tool',
|
|
60
|
-
tool_call_id: fr.id,
|
|
61
|
-
content: fr.text,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
OpenAIChatCompletionsEngine.convertFromFunctionResponse = convertFromFunctionResponse;
|
|
65
|
-
function convertFromFunctionDeclarationEntry(fdentry) {
|
|
66
|
-
return {
|
|
67
|
-
type: 'function',
|
|
68
|
-
function: {
|
|
69
|
-
name: fdentry[0],
|
|
70
|
-
description: fdentry[1].description,
|
|
71
|
-
strict: true,
|
|
72
|
-
parameters: fdentry[1].paraschema,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
OpenAIChatCompletionsEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
|
|
77
|
-
function convertFromToolChoice(toolChoice) {
|
|
78
|
-
if (toolChoice === Function.ToolChoice.NONE)
|
|
79
|
-
return 'none';
|
|
80
|
-
else if (toolChoice === Function.ToolChoice.REQUIRED)
|
|
81
|
-
return 'required';
|
|
82
|
-
else if (toolChoice === Function.ToolChoice.AUTO)
|
|
83
|
-
return 'auto';
|
|
84
|
-
else {
|
|
85
|
-
if (toolChoice.length === 1) { }
|
|
86
|
-
else
|
|
87
|
-
throw new Error();
|
|
88
|
-
return { type: 'function', function: { name: toolChoice[0] } };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
OpenAIChatCompletionsEngine.convertFromToolChoice = convertFromToolChoice;
|
|
92
|
-
function calcCost(usage) {
|
|
93
|
-
const cacheHitTokenCount = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
94
|
-
const cacheMissTokenCount = usage.prompt_tokens - cacheHitTokenCount;
|
|
95
|
-
return this.inputPrice * cacheMissTokenCount / 1e6 +
|
|
96
|
-
this.cachePrice * cacheHitTokenCount / 1e6 +
|
|
97
|
-
this.outputPrice * usage.completion_tokens / 1e6;
|
|
98
|
-
}
|
|
99
|
-
OpenAIChatCompletionsEngine.calcCost = calcCost;
|
|
100
|
-
function extractContent(completionContent) {
|
|
101
|
-
return completionContent;
|
|
102
|
-
}
|
|
103
|
-
OpenAIChatCompletionsEngine.extractContent = extractContent;
|
|
104
|
-
function handleFinishReason(completion, finishReason) {
|
|
105
|
-
if (finishReason === 'length')
|
|
106
|
-
throw new ResponseInvalid('Token limit exceeded.', { cause: completion });
|
|
107
|
-
if (['stop', 'tool_calls'].includes(finishReason)) { }
|
|
108
|
-
else
|
|
109
|
-
throw new ResponseInvalid('Abnormal finish reason', { cause: finishReason });
|
|
110
|
-
}
|
|
111
|
-
OpenAIChatCompletionsEngine.handleFinishReason = handleFinishReason;
|
|
112
|
-
})(OpenAIChatCompletionsEngine || (OpenAIChatCompletionsEngine = {}));
|
|
113
|
-
//# sourceMappingURL=openai-chat-completions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-chat-completions.js","sourceRoot":"","sources":["../../src/api-types/openai-chat-completions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAe,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,M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AAC;;YAChD,MAAM,IAAI,eAAe,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IACtF,CAAC;IALe,8CAAkB,qBAKjC,CAAA;AACL,CAAC,EA3HgB,2BAA2B,KAA3B,2BAA2B,QA2H3C"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
|
-
import { Function } from '../function.ts';
|
|
3
|
-
import { type Engine } from '../engine.ts';
|
|
4
|
-
export declare namespace OpenAIResponsesEngine {
|
|
5
|
-
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm> {
|
|
6
|
-
}
|
|
7
|
-
interface OwnProps {
|
|
8
|
-
parallelToolCall: boolean;
|
|
9
|
-
}
|
|
10
|
-
namespace OwnProps {
|
|
11
|
-
function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps;
|
|
12
|
-
}
|
|
13
|
-
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, OwnProps {
|
|
14
|
-
convertFromFunctionResponse(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
|
|
15
|
-
calcCost(usage: OpenAI.Responses.ResponseUsage): number;
|
|
16
|
-
convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.Responses.FunctionTool;
|
|
17
|
-
convertToFunctionCall(apifc: OpenAI.Responses.ResponseFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
18
|
-
}
|
|
19
|
-
function convertFromFunctionResponse<fdm extends Function.Declaration.Map>(fr: Function.Response.Distributive<Function.Declaration.From<fdm>>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
|
|
20
|
-
function calcCost<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, usage: OpenAI.Responses.ResponseUsage): number;
|
|
21
|
-
function convertFromFunctionDeclarationEntry<fdm extends Function.Declaration.Map>(fdentry: Function.Declaration.Entry.From<fdm>): OpenAI.Responses.FunctionTool;
|
|
22
|
-
function convertToFunctionCall<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, apifc: OpenAI.Responses.ResponseFunctionToolCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
|
|
23
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
|
-
import { Function } from "../function.js";
|
|
3
|
-
import { ResponseInvalid } from "../engine.js";
|
|
4
|
-
import Ajv from 'ajv';
|
|
5
|
-
import {} from "../engine.js";
|
|
6
|
-
const ajv = new Ajv();
|
|
7
|
-
export var OpenAIResponsesEngine;
|
|
8
|
-
(function (OpenAIResponsesEngine) {
|
|
9
|
-
let OwnProps;
|
|
10
|
-
(function (OwnProps) {
|
|
11
|
-
function init(options) {
|
|
12
|
-
return {
|
|
13
|
-
parallelToolCall: options.parallelToolCall ?? false,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
OwnProps.init = init;
|
|
17
|
-
})(OwnProps = OpenAIResponsesEngine.OwnProps || (OpenAIResponsesEngine.OwnProps = {}));
|
|
18
|
-
function convertFromFunctionResponse(fr) {
|
|
19
|
-
if (fr.id) { }
|
|
20
|
-
else
|
|
21
|
-
throw new Error();
|
|
22
|
-
return {
|
|
23
|
-
type: 'function_call_output',
|
|
24
|
-
call_id: fr.id,
|
|
25
|
-
output: fr.text,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
OpenAIResponsesEngine.convertFromFunctionResponse = convertFromFunctionResponse;
|
|
29
|
-
function calcCost(usage) {
|
|
30
|
-
const cacheHitTokenCount = usage.input_tokens_details.cached_tokens;
|
|
31
|
-
const cacheMissTokenCount = usage.input_tokens - cacheHitTokenCount;
|
|
32
|
-
return this.inputPrice * cacheMissTokenCount / 1e6 +
|
|
33
|
-
this.cachePrice * cacheHitTokenCount / 1e6 +
|
|
34
|
-
this.outputPrice * usage.output_tokens / 1e6;
|
|
35
|
-
}
|
|
36
|
-
OpenAIResponsesEngine.calcCost = calcCost;
|
|
37
|
-
function convertFromFunctionDeclarationEntry(fdentry) {
|
|
38
|
-
return {
|
|
39
|
-
name: fdentry[0],
|
|
40
|
-
description: fdentry[1].description,
|
|
41
|
-
parameters: fdentry[1].paraschema,
|
|
42
|
-
strict: true,
|
|
43
|
-
type: 'function',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
OpenAIResponsesEngine.convertFromFunctionDeclarationEntry = convertFromFunctionDeclarationEntry;
|
|
47
|
-
function convertToFunctionCall(apifc) {
|
|
48
|
-
const fditem = this.fdm[apifc.name];
|
|
49
|
-
if (fditem) { }
|
|
50
|
-
else
|
|
51
|
-
throw new ResponseInvalid('Unknown function call', { cause: apifc });
|
|
52
|
-
const args = (() => {
|
|
53
|
-
try {
|
|
54
|
-
return JSON.parse(apifc.arguments);
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
return new ResponseInvalid('Invalid JSON of function call', { cause: apifc });
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
60
|
-
if (ajv.validate(fditem.paraschema, args)) { }
|
|
61
|
-
else
|
|
62
|
-
throw new ResponseInvalid('Function call not conforming to schema', { cause: apifc });
|
|
63
|
-
return Function.Call.create({
|
|
64
|
-
id: apifc.call_id,
|
|
65
|
-
name: apifc.name,
|
|
66
|
-
args,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
OpenAIResponsesEngine.convertToFunctionCall = convertToFunctionCall;
|
|
70
|
-
})(OpenAIResponsesEngine || (OpenAIResponsesEngine = {}));
|
|
71
|
-
//# sourceMappingURL=openai-responses.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../src/api-types/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;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age, type Session } from './session.ts';
|
|
2
|
-
import { Function } from './function.ts';
|
|
3
|
-
import { type InferenceContext } from './inference-context.ts';
|
|
4
|
-
import { type Engine } from './engine.ts';
|
|
5
|
-
export interface CompatibleEngine<in out fdm extends Function.Declaration.Map> extends Engine {
|
|
6
|
-
/**
|
|
7
|
-
* @throws {@link USER_ABORTION} 用户中止
|
|
8
|
-
* @throws {@link InferenceTimeout} 推理超时
|
|
9
|
-
* @throws {@link ResponseInvalid} 模型抽风
|
|
10
|
-
* @throws {TypeError} 网络故障
|
|
11
|
-
*/
|
|
12
|
-
stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
13
|
-
/**
|
|
14
|
-
* @param session mutable
|
|
15
|
-
*/
|
|
16
|
-
stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
17
|
-
appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
|
|
18
|
-
/**
|
|
19
|
-
* @param session mutable
|
|
20
|
-
*/
|
|
21
|
-
pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
|
|
22
|
-
}
|
|
23
|
-
export declare namespace CompatibleEngine {
|
|
24
|
-
interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm>, Options.Tools<fdm> {
|
|
25
|
-
}
|
|
26
|
-
namespace Options {
|
|
27
|
-
interface Tools<in out fdm extends Function.Declaration.Map> extends Engine.Options.Tools<fdm> {
|
|
28
|
-
toolChoice?: Function.ToolChoice<fdm>;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
interface OwnProps<in out fdm extends Function.Declaration.Map> {
|
|
32
|
-
toolChoice: Function.ToolChoice<fdm>;
|
|
33
|
-
}
|
|
34
|
-
namespace OwnProps {
|
|
35
|
-
function init<fdm extends Function.Declaration.Map>(options: CompatibleEngine.Options<fdm>): OwnProps<fdm>;
|
|
36
|
-
}
|
|
37
|
-
interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, CompatibleEngine<fdm>, OwnProps<fdm> {
|
|
38
|
-
parallelToolCall: boolean;
|
|
39
|
-
fetch(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
40
|
-
stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
41
|
-
stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
42
|
-
appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
|
|
43
|
-
pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
|
|
44
|
-
validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
|
|
45
|
-
}
|
|
46
|
-
function stateless<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
47
|
-
function stateful<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
|
|
48
|
-
function appendUserMessage<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
|
|
49
|
-
function pushUserMessage<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
|
|
50
|
-
function validateToolCallsByToolChoice<fdm extends Function.Declaration.Map>(this: CompatibleEngine.Underhood<fdm>, toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
|
|
51
|
-
}
|