@atomic-chat/core 0.18.4 → 0.19.0
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/app-daemon.js +5 -0
- package/dist/app-daemon.js.map +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/cli/main.js +5 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/client/control-client.d.ts +18 -1
- package/dist/client/control-client.js +27 -0
- package/dist/client/control-client.js.map +1 -1
- package/dist/cloud/registry.js +1 -0
- package/dist/cloud/registry.js.map +1 -1
- package/dist/config/paths.d.ts +4 -0
- package/dist/config/paths.js +13 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/contracts/control-api.d.ts +9 -0
- package/dist/contracts/diffusion.d.ts +17 -7
- package/dist/contracts/diffusion.js.map +1 -1
- package/dist/contracts/engine-builds.d.ts +1 -1
- package/dist/contracts/engine-builds.js +1 -1
- package/dist/contracts/engine-builds.js.map +1 -1
- package/dist/contracts/engines.d.ts +1 -1
- package/dist/contracts/engines.js +2 -0
- package/dist/contracts/engines.js.map +1 -1
- package/dist/contracts/errors.d.ts +9 -1
- package/dist/contracts/errors.js.map +1 -1
- package/dist/contracts/events.d.ts +3 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/litert-lm.d.ts +97 -0
- package/dist/contracts/litert-lm.js +17 -0
- package/dist/contracts/litert-lm.js.map +1 -0
- package/dist/contracts/model-yml.d.ts +31 -0
- package/dist/contracts/model-yml.js +5 -0
- package/dist/contracts/model-yml.js.map +1 -1
- package/dist/contracts/session.d.ts +5 -1
- package/dist/contracts/session.js.map +1 -1
- package/dist/contracts/settings.d.ts +10 -1
- package/dist/contracts/settings.js.map +1 -1
- package/dist/core/atomic-core.d.ts +6 -1
- package/dist/core/atomic-core.js +6 -0
- package/dist/core/atomic-core.js.map +1 -1
- package/dist/core/create.js +141 -20
- package/dist/core/create.js.map +1 -1
- package/dist/diffusion/args.d.ts +8 -0
- package/dist/diffusion/args.js +10 -0
- package/dist/diffusion/args.js.map +1 -1
- package/dist/diffusion/compat.d.ts +3 -3
- package/dist/diffusion/compat.js +15 -10
- package/dist/diffusion/compat.js.map +1 -1
- package/dist/diffusion/recipe.d.ts +19 -2
- package/dist/diffusion/recipe.js +43 -20
- package/dist/diffusion/recipe.js.map +1 -1
- package/dist/diffusion/remote-job.js +6 -7
- package/dist/diffusion/remote-job.js.map +1 -1
- package/dist/diffusion/service.d.ts +1 -0
- package/dist/diffusion/service.js +4 -2
- package/dist/diffusion/service.js.map +1 -1
- package/dist/diffusion/video-history.js +3 -2
- package/dist/diffusion/video-history.js.map +1 -1
- package/dist/diffusion/video-recipe.d.ts +4 -1
- package/dist/diffusion/video-recipe.js +15 -11
- package/dist/diffusion/video-recipe.js.map +1 -1
- package/dist/diffusion/workflow.d.ts +2 -1
- package/dist/diffusion/workflow.js +3 -1
- package/dist/diffusion/workflow.js.map +1 -1
- package/dist/downloads/archive.d.ts +2 -1
- package/dist/downloads/archive.js +3 -2
- package/dist/downloads/archive.js.map +1 -1
- package/dist/engine-builds/engines.d.ts +22 -5
- package/dist/engine-builds/engines.js +44 -7
- package/dist/engine-builds/engines.js.map +1 -1
- package/dist/engine-builds/litert-lm.d.ts +29 -0
- package/dist/engine-builds/litert-lm.js +119 -0
- package/dist/engine-builds/litert-lm.js.map +1 -0
- package/dist/engine-builds/manifest.d.ts +55 -1
- package/dist/engine-builds/manifest.js +114 -1
- package/dist/engine-builds/manifest.js.map +1 -1
- package/dist/engine-builds/order.d.ts +2 -1
- package/dist/engine-builds/order.js +3 -1
- package/dist/engine-builds/order.js.map +1 -1
- package/dist/engine-builds/select.d.ts +19 -1
- package/dist/engine-builds/select.js +45 -0
- package/dist/engine-builds/select.js.map +1 -1
- package/dist/engine-builds/service.d.ts +8 -5
- package/dist/engine-builds/service.js +11 -4
- package/dist/engine-builds/service.js.map +1 -1
- package/dist/engines/service.d.ts +3 -1
- package/dist/engines/service.js +4 -1
- package/dist/engines/service.js.map +1 -1
- package/dist/host/recipes/executor-io-windows.d.ts +10 -1
- package/dist/host/recipes/executor-io-windows.js +9 -3
- package/dist/host/recipes/executor-io-windows.js.map +1 -1
- package/dist/router/resolve.d.ts +25 -4
- package/dist/router/resolve.js +34 -3
- package/dist/router/resolve.js.map +1 -1
- package/dist/runtime/environment/host-exec.d.ts +2 -0
- package/dist/runtime/environment/host-exec.js +15 -4
- package/dist/runtime/environment/host-exec.js.map +1 -1
- package/dist/runtime/litert-lm/accelerators.d.ts +54 -0
- package/dist/runtime/litert-lm/accelerators.js +176 -0
- package/dist/runtime/litert-lm/accelerators.js.map +1 -0
- package/dist/runtime/litert-lm/check.d.ts +44 -0
- package/dist/runtime/litert-lm/check.js +113 -0
- package/dist/runtime/litert-lm/check.js.map +1 -0
- package/dist/runtime/litert-lm/host/args.d.ts +47 -0
- package/dist/runtime/litert-lm/host/args.js +108 -0
- package/dist/runtime/litert-lm/host/args.js.map +1 -0
- package/dist/runtime/litert-lm/host/ffi-bun.d.ts +16 -0
- package/dist/runtime/litert-lm/host/ffi-bun.js +535 -0
- package/dist/runtime/litert-lm/host/ffi-bun.js.map +1 -0
- package/dist/runtime/litert-lm/host/library.d.ts +113 -0
- package/dist/runtime/litert-lm/host/library.js +38 -0
- package/dist/runtime/litert-lm/host/library.js.map +1 -0
- package/dist/runtime/litert-lm/host/openai.d.ts +97 -0
- package/dist/runtime/litert-lm/host/openai.js +355 -0
- package/dist/runtime/litert-lm/host/openai.js.map +1 -0
- package/dist/runtime/litert-lm/host/pool.d.ts +51 -0
- package/dist/runtime/litert-lm/host/pool.js +114 -0
- package/dist/runtime/litert-lm/host/pool.js.map +1 -0
- package/dist/runtime/litert-lm/host/run.d.ts +48 -0
- package/dist/runtime/litert-lm/host/run.js +169 -0
- package/dist/runtime/litert-lm/host/run.js.map +1 -0
- package/dist/runtime/litert-lm/host/server.d.ts +28 -0
- package/dist/runtime/litert-lm/host/server.js +242 -0
- package/dist/runtime/litert-lm/host/server.js.map +1 -0
- package/dist/runtime/litert-lm/host-process.d.ts +44 -0
- package/dist/runtime/litert-lm/host-process.js +99 -0
- package/dist/runtime/litert-lm/host-process.js.map +1 -0
- package/dist/runtime/litert-lm/index.d.ts +10 -0
- package/dist/runtime/litert-lm/index.js +11 -0
- package/dist/runtime/litert-lm/index.js.map +1 -0
- package/dist/runtime/litert-lm/litert-host.d.ts +17 -0
- package/dist/runtime/litert-lm/litert-host.js +22 -0
- package/dist/runtime/litert-lm/litert-host.js.map +1 -0
- package/dist/runtime/litert-lm/model-yml.d.ts +8 -0
- package/dist/runtime/litert-lm/model-yml.js +67 -0
- package/dist/runtime/litert-lm/model-yml.js.map +1 -0
- package/dist/runtime/litert-lm/npu.d.ts +11 -0
- package/dist/runtime/litert-lm/npu.js +24 -0
- package/dist/runtime/litert-lm/npu.js.map +1 -0
- package/dist/runtime/litert-lm/runtime.d.ts +99 -0
- package/dist/runtime/litert-lm/runtime.js +354 -0
- package/dist/runtime/litert-lm/runtime.js.map +1 -0
- package/dist/runtime/shared/external-sessions.js +1 -0
- package/dist/runtime/shared/external-sessions.js.map +1 -1
- package/dist/server/control/router.js +2 -0
- package/dist/server/control/router.js.map +1 -1
- package/dist/server/control/routes/litert-lm.d.ts +11 -0
- package/dist/server/control/routes/litert-lm.js +33 -0
- package/dist/server/control/routes/litert-lm.js.map +1 -0
- package/dist/server/control/routes/public-server.js +22 -0
- package/dist/server/control/routes/public-server.js.map +1 -1
- package/dist/server/control/types.d.ts +16 -1
- package/dist/server/control/types.js.map +1 -1
- package/dist/server/http.js +3 -0
- package/dist/server/http.js.map +1 -1
- package/dist/server/public/errors.d.ts +17 -0
- package/dist/server/public/errors.js +28 -0
- package/dist/server/public/errors.js.map +1 -1
- package/dist/server/public/forward.d.ts +20 -1
- package/dist/server/public/forward.js +64 -14
- package/dist/server/public/forward.js.map +1 -1
- package/dist/server/public/listing.d.ts +6 -0
- package/dist/server/public/listing.js +25 -3
- package/dist/server/public/listing.js.map +1 -1
- package/dist/server/public/responses.js +21 -10
- package/dist/server/public/responses.js.map +1 -1
- package/dist/server/public/subscription.js +2 -2
- package/dist/server/public/subscription.js.map +1 -1
- package/dist/server/public/types.d.ts +5 -0
- package/dist/server/public/videos-params.js +6 -1
- package/dist/server/public/videos-params.js.map +1 -1
- package/dist/settings/schema/litert-lm.json +37 -0
- package/dist/settings/schema.js +9 -0
- package/dist/settings/schema.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of LiteRT-LM's C API (`litert_lm_*`, the binding's ABI 1) the host uses, as an interface.
|
|
3
|
+
* `ffi-bun.ts` implements it over `bun:ffi`; the protocol and server tests (tasks 5.2–5.5) run the host
|
|
4
|
+
* against a fake one. Calls are synchronous except `send`, whose chunks arrive later on the JS thread.
|
|
5
|
+
*/
|
|
6
|
+
import type { LiteRtLmFileMetadata } from '../../../contracts/index.js';
|
|
7
|
+
/** A library call returned an error (the library's own message) or a null handle. */
|
|
8
|
+
export declare class LiteRtLibraryError extends Error {
|
|
9
|
+
readonly operation: string;
|
|
10
|
+
constructor(operation: string, message: string);
|
|
11
|
+
}
|
|
12
|
+
export type LiteRtBackendName = 'cpu' | 'gpu' | 'npu';
|
|
13
|
+
export type LiteRtModality = 'text' | 'vision' | 'audio' | 'video';
|
|
14
|
+
export type LiteRtNpuBrand = 'unknown' | 'qualcomm' | 'google-tensor' | 'mediatek' | 'intel' | 'samsung';
|
|
15
|
+
/**
|
|
16
|
+
* What `litert_lm_loaded_file_*` tells about a `.litertlm` file without creating an engine: the wire
|
|
17
|
+
* shape core returns from `/models/litert-lm/check`. `max_context_tokens` is `null` when the library
|
|
18
|
+
* answers 0 (not declared); `function_calling` and `thinking` are what the file declares, and Gemma 4
|
|
19
|
+
* files declare neither while doing both (spike S1).
|
|
20
|
+
*/
|
|
21
|
+
export type LiteRtFileInfo = LiteRtLmFileMetadata;
|
|
22
|
+
export interface LiteRtEngineSettings {
|
|
23
|
+
model: string;
|
|
24
|
+
backend: LiteRtBackendName;
|
|
25
|
+
/** Set only for a file with a vision encoder: the engine refuses conversations otherwise (spike S2). */
|
|
26
|
+
visionBackend: LiteRtBackendName | null;
|
|
27
|
+
maxNumTokens: number;
|
|
28
|
+
/** Must exist (spike S2). */
|
|
29
|
+
cacheDir: string;
|
|
30
|
+
/** NPU only: the dispatch library folder of the build. */
|
|
31
|
+
dispatchLibDir?: string;
|
|
32
|
+
speculative: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Always the library's `TOP_P` sampler: `GREEDY` and `TOP_K` are not implemented on CPU (spike S2). */
|
|
35
|
+
export interface LiteRtSampler {
|
|
36
|
+
temperature?: number;
|
|
37
|
+
topP?: number;
|
|
38
|
+
topK?: number;
|
|
39
|
+
seed?: number;
|
|
40
|
+
}
|
|
41
|
+
/** One message in the library's conversation JSON (`{role, content: [...], tool_calls?}`). */
|
|
42
|
+
export type LiteRtMessage = Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* What a conversation's `TOP_P` sampler is set to: `null` when the request names nothing, so the
|
|
45
|
+
* engine keeps the sampling the file declares (as the Python binding does without a SamplerConfig);
|
|
46
|
+
* otherwise the request's values, the rest filled in, and a fresh seed unless one is given — a fixed
|
|
47
|
+
* seed would answer a regenerate with the same text. A temperature near 0 becomes one candidate at
|
|
48
|
+
* temperature 1: the same choice, which the GPU sampler (Windows, 0.18.1) gets right; at 0 it answers
|
|
49
|
+
* gibberish, at 0.0001 nothing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function samplerSettings(sampler: LiteRtSampler, random?: () => number): {
|
|
52
|
+
topK: number;
|
|
53
|
+
topP: number;
|
|
54
|
+
temperature: number;
|
|
55
|
+
seed: number;
|
|
56
|
+
} | null;
|
|
57
|
+
export interface LiteRtConversationConfig {
|
|
58
|
+
/** History the conversation starts from; the next `send` continues it. */
|
|
59
|
+
messages: LiteRtMessage[];
|
|
60
|
+
/** OpenAI-shaped `tools`; `null` for none. Fixed for the conversation's life. */
|
|
61
|
+
tools: unknown[] | null;
|
|
62
|
+
sampler: LiteRtSampler;
|
|
63
|
+
/** Enables the LL_GUIDANCE constraint provider, so a `send` may carry a constraint. */
|
|
64
|
+
constrained: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface LiteRtSendOptions {
|
|
67
|
+
maxOutputTokens?: number;
|
|
68
|
+
constraint?: {
|
|
69
|
+
kind: 'json_schema' | 'regex';
|
|
70
|
+
value: string;
|
|
71
|
+
};
|
|
72
|
+
thinking?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** A chunk as copied off the library's thread: `text` is one message JSON of the library. */
|
|
75
|
+
export interface LiteRtChunk {
|
|
76
|
+
text: string | null;
|
|
77
|
+
error: string | null;
|
|
78
|
+
final: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface LiteRtConversation {
|
|
81
|
+
/**
|
|
82
|
+
* Starts a generation; chunks arrive in order on the JS thread, the last one `final` or with an
|
|
83
|
+
* `error` (`CANCELLED…` after `cancel`). Throws when the library refuses to start.
|
|
84
|
+
*/
|
|
85
|
+
send(message: LiteRtMessage | LiteRtMessage[], options: LiteRtSendOptions, onChunk: (chunk: LiteRtChunk) => void): void;
|
|
86
|
+
/** A cancelled conversation answers every later `send` with `CANCELLED`: drop it (spike S2). */
|
|
87
|
+
cancel(): void;
|
|
88
|
+
/** Tokens in the conversation so far, history included. */
|
|
89
|
+
tokenCount(): number;
|
|
90
|
+
close(): void;
|
|
91
|
+
}
|
|
92
|
+
export interface LiteRtEngine {
|
|
93
|
+
conversation(config: LiteRtConversationConfig): LiteRtConversation;
|
|
94
|
+
close(): void;
|
|
95
|
+
}
|
|
96
|
+
export interface LiteRtLibrary {
|
|
97
|
+
/** The library's version; `null` where it cannot be read (Windows). */
|
|
98
|
+
version: string | null;
|
|
99
|
+
/** The binding's ABI number. */
|
|
100
|
+
abi: number;
|
|
101
|
+
/** The backends this build can run here: `npu` only with Intel's dispatch library beside it. */
|
|
102
|
+
backends: LiteRtBackendName[];
|
|
103
|
+
inspect(file: string): LiteRtFileInfo;
|
|
104
|
+
createEngine(settings: LiteRtEngineSettings): LiteRtEngine;
|
|
105
|
+
}
|
|
106
|
+
export interface LoadLiteRtLibraryOptions {
|
|
107
|
+
/** NPU: the prepared OpenVINO libraries, made findable before the library loads them. */
|
|
108
|
+
ovLibsDir?: string;
|
|
109
|
+
}
|
|
110
|
+
/** Opens the library of one build (`<build>/lib`); throws `LiteRtLibraryError` when it does not load. */
|
|
111
|
+
export type LoadLiteRtLibrary = (libDir: string, options?: LoadLiteRtLibraryOptions) => Promise<LiteRtLibrary>;
|
|
112
|
+
/** The ABI number `ffi-bun.ts` binds; see `SUPPORTED_LITERT_LM_ABI` in engine-builds. */
|
|
113
|
+
export declare const BOUND_LITERT_LM_ABI = 1;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of LiteRT-LM's C API (`litert_lm_*`, the binding's ABI 1) the host uses, as an interface.
|
|
3
|
+
* `ffi-bun.ts` implements it over `bun:ffi`; the protocol and server tests (tasks 5.2–5.5) run the host
|
|
4
|
+
* against a fake one. Calls are synchronous except `send`, whose chunks arrive later on the JS thread.
|
|
5
|
+
*/
|
|
6
|
+
/** A library call returned an error (the library's own message) or a null handle. */
|
|
7
|
+
export class LiteRtLibraryError extends Error {
|
|
8
|
+
operation;
|
|
9
|
+
constructor(operation, message) {
|
|
10
|
+
super(`${operation}: ${message}`);
|
|
11
|
+
this.operation = operation;
|
|
12
|
+
this.name = 'LiteRtLibraryError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Below this a temperature is greedy: the GPU sampler divides logits by it, and near 0 they overflow. */
|
|
16
|
+
const GREEDY_BELOW = 0.01;
|
|
17
|
+
/**
|
|
18
|
+
* What a conversation's `TOP_P` sampler is set to: `null` when the request names nothing, so the
|
|
19
|
+
* engine keeps the sampling the file declares (as the Python binding does without a SamplerConfig);
|
|
20
|
+
* otherwise the request's values, the rest filled in, and a fresh seed unless one is given — a fixed
|
|
21
|
+
* seed would answer a regenerate with the same text. A temperature near 0 becomes one candidate at
|
|
22
|
+
* temperature 1: the same choice, which the GPU sampler (Windows, 0.18.1) gets right; at 0 it answers
|
|
23
|
+
* gibberish, at 0.0001 nothing.
|
|
24
|
+
*/
|
|
25
|
+
export function samplerSettings(sampler, random = Math.random) {
|
|
26
|
+
if (Object.values(sampler).every((value) => value === undefined))
|
|
27
|
+
return null;
|
|
28
|
+
const greedy = sampler.temperature !== undefined && sampler.temperature < GREEDY_BELOW;
|
|
29
|
+
return {
|
|
30
|
+
topK: greedy ? 1 : (sampler.topK ?? 64),
|
|
31
|
+
topP: sampler.topP ?? 0.95,
|
|
32
|
+
temperature: greedy ? 1 : (sampler.temperature ?? 1),
|
|
33
|
+
seed: sampler.seed ?? Math.floor(random() * 0x7fffffff),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The ABI number `ffi-bun.ts` binds; see `SUPPORTED_LITERT_LM_ABI` in engine-builds. */
|
|
37
|
+
export const BOUND_LITERT_LM_ABI = 1;
|
|
38
|
+
//# sourceMappingURL=library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../../../src/runtime/litert-lm/host/library.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,qFAAqF;AACrF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAEhC;IADX,YACW,SAAiB,EAC1B,OAAe;QAEf,KAAK,CAAC,GAAG,SAAS,KAAK,OAAO,EAAE,CAAC,CAAA;QAHxB,cAAS,GAAT,SAAS,CAAQ;QAI1B,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;CACF;AAsCD,0GAA0G;AAC1G,MAAM,YAAY,GAAG,IAAI,CAAA;AAEzB;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAsB,EACtB,SAAuB,IAAI,CAAC,MAAM;IAElC,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7E,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,KAAK,SAAS,IAAI,OAAO,CAAC,WAAW,GAAG,YAAY,CAAA;IACtF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;QACvC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;QAC1B,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;QACpD,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;KACxD,CAAA;AACH,CAAC;AAkED,yFAAyF;AACzF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI chat completions over LiteRT-LM's conversation JSON (spec `litert-lm-runtime`, "Сервер
|
|
3
|
+
* хоста отвечает как OpenAI chat completions"; task 5.4). Pure: requests in, library messages out;
|
|
4
|
+
* library chunks in, OpenAI deltas and replies out.
|
|
5
|
+
*
|
|
6
|
+
* What the library does itself (spike S2): chat templates, parsing tool calls into `tool_calls` with
|
|
7
|
+
* an `arguments` object (one chunk, no deltas), thinking as `channels.thought`. What it has no notion
|
|
8
|
+
* of and the host adds: `stop` strings, OpenAI's string `arguments`, call ids, `finish_reason`.
|
|
9
|
+
*/
|
|
10
|
+
import type { LiteRtMessage, LiteRtSampler } from './library.js';
|
|
11
|
+
export interface OpenAiErrorBody {
|
|
12
|
+
error: {
|
|
13
|
+
message: string;
|
|
14
|
+
type: string;
|
|
15
|
+
param: string | null;
|
|
16
|
+
code: string | null;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** A request this server answers with an OpenAI-shaped error instead of a completion. */
|
|
20
|
+
export declare class OpenAiRequestError extends Error {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly body: OpenAiErrorBody;
|
|
23
|
+
constructor(status: number, message: string, param?: string | null, type?: string, code?: string | null);
|
|
24
|
+
}
|
|
25
|
+
export interface ModelCaps {
|
|
26
|
+
/** The file declares image input. */
|
|
27
|
+
vision: boolean;
|
|
28
|
+
/** Think unless the request says not to (`model.yml` `reasoning`). */
|
|
29
|
+
reasoning: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ParsedChat {
|
|
32
|
+
/** Every message but the trailing user message or run of tool results. */
|
|
33
|
+
history: LiteRtMessage[];
|
|
34
|
+
/** What this request adds: one user message, or the tool results that close a round of calls. */
|
|
35
|
+
next: LiteRtMessage[];
|
|
36
|
+
/** `null` with no tools or `tool_choice: "none"`. */
|
|
37
|
+
tools: unknown[] | null;
|
|
38
|
+
stream: boolean;
|
|
39
|
+
includeUsage: boolean;
|
|
40
|
+
sampler: LiteRtSampler;
|
|
41
|
+
maxTokens?: number;
|
|
42
|
+
stop: string[];
|
|
43
|
+
responseFormat: {
|
|
44
|
+
kind: 'json_schema' | 'regex';
|
|
45
|
+
value: string;
|
|
46
|
+
} | null;
|
|
47
|
+
thinking: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A chat completions body, or `OpenAiRequestError` (400) naming the field it cannot serve. */
|
|
50
|
+
export declare function parseChatRequest(raw: unknown, caps: ModelCaps): ParsedChat;
|
|
51
|
+
/** One OpenAI delta (`choices[0].delta`) without the role. */
|
|
52
|
+
export type Delta = {
|
|
53
|
+
content: string;
|
|
54
|
+
} | {
|
|
55
|
+
reasoning_content: string;
|
|
56
|
+
} | {
|
|
57
|
+
tool_calls: Array<{
|
|
58
|
+
index: number;
|
|
59
|
+
id: string;
|
|
60
|
+
type: 'function';
|
|
61
|
+
function: {
|
|
62
|
+
name: string;
|
|
63
|
+
arguments: string;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
export type FinishReason = 'stop' | 'length' | 'tool_calls';
|
|
68
|
+
/** Builds one reply from the library's chunks: deltas as they come, the whole message at the end. */
|
|
69
|
+
export declare class ReplyBuilder {
|
|
70
|
+
private readonly stops;
|
|
71
|
+
private readonly newCallId;
|
|
72
|
+
private content;
|
|
73
|
+
private reasoning;
|
|
74
|
+
private readonly calls;
|
|
75
|
+
/** Text not yet sent because it may be the start of a stop string. */
|
|
76
|
+
private held;
|
|
77
|
+
/** A stop string was met: everything after it is dropped and the library should be cancelled. */
|
|
78
|
+
stopped: boolean;
|
|
79
|
+
/** Chunks that carried generated text or thought: the completion's token count, near enough. */
|
|
80
|
+
completionChunks: number;
|
|
81
|
+
constructor(stops: readonly string[], newCallId?: () => string);
|
|
82
|
+
/** One library chunk (a message JSON, or bare text); the deltas it makes. */
|
|
83
|
+
add(raw: string): Delta[];
|
|
84
|
+
/** Text to send now; holds back a tail that may begin a stop string, cuts at a whole one. */
|
|
85
|
+
private text;
|
|
86
|
+
/** At the end: whatever was held back for a stop string that never came. */
|
|
87
|
+
flush(): Delta[];
|
|
88
|
+
/**
|
|
89
|
+
* The finish reason, given the error the last chunk carried. A cancel the host made for a stop
|
|
90
|
+
* string is a stop; the token limit is `length`; any other error is thrown, with the library's words.
|
|
91
|
+
*/
|
|
92
|
+
finish(error: string | null): FinishReason;
|
|
93
|
+
/** `choices[0].message` of a non-stream reply. */
|
|
94
|
+
message(): Record<string, unknown>;
|
|
95
|
+
/** The reply as the library's conversation holds it: what a continuing request must repeat. */
|
|
96
|
+
history(): LiteRtMessage;
|
|
97
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI chat completions over LiteRT-LM's conversation JSON (spec `litert-lm-runtime`, "Сервер
|
|
3
|
+
* хоста отвечает как OpenAI chat completions"; task 5.4). Pure: requests in, library messages out;
|
|
4
|
+
* library chunks in, OpenAI deltas and replies out.
|
|
5
|
+
*
|
|
6
|
+
* What the library does itself (spike S2): chat templates, parsing tool calls into `tool_calls` with
|
|
7
|
+
* an `arguments` object (one chunk, no deltas), thinking as `channels.thought`. What it has no notion
|
|
8
|
+
* of and the host adds: `stop` strings, OpenAI's string `arguments`, call ids, `finish_reason`.
|
|
9
|
+
*/
|
|
10
|
+
/** A request this server answers with an OpenAI-shaped error instead of a completion. */
|
|
11
|
+
export class OpenAiRequestError extends Error {
|
|
12
|
+
status;
|
|
13
|
+
body;
|
|
14
|
+
constructor(status, message, param = null, type = status >= 500 ? 'server_error' : 'invalid_request_error', code = null) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.name = 'OpenAiRequestError';
|
|
18
|
+
this.body = { error: { message, type, param, code } };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const invalid = (message, param = null) => new OpenAiRequestError(400, message, param);
|
|
22
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
+
const text = (value) => ({ type: 'text', text: value });
|
|
24
|
+
function parseArguments(raw) {
|
|
25
|
+
if (typeof raw !== 'string')
|
|
26
|
+
return isRecord(raw) ? raw : {};
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(raw);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** A tool result: the JSON it holds when it is JSON, else the text. */
|
|
35
|
+
function parseToolResponse(content) {
|
|
36
|
+
const raw = typeof content === 'string' ? content : textOf(content, 'content');
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(raw);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return raw;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function textOf(content, param) {
|
|
45
|
+
if (content == null)
|
|
46
|
+
return '';
|
|
47
|
+
if (typeof content === 'string')
|
|
48
|
+
return content;
|
|
49
|
+
if (!Array.isArray(content))
|
|
50
|
+
throw invalid(`${param} must be a string or an array of parts`, param);
|
|
51
|
+
return content
|
|
52
|
+
.map((part) => {
|
|
53
|
+
if (isRecord(part) && part['type'] === 'text' && typeof part['text'] === 'string')
|
|
54
|
+
return part['text'];
|
|
55
|
+
throw invalid(`${param} may hold text parts only`, param);
|
|
56
|
+
})
|
|
57
|
+
.join('');
|
|
58
|
+
}
|
|
59
|
+
const DATA_URL_RE = /^data:image\/[a-z0-9.+-]+;base64,([A-Za-z0-9+/=]+)$/i;
|
|
60
|
+
function userContent(content, caps, param) {
|
|
61
|
+
if (typeof content === 'string')
|
|
62
|
+
return [text(content)];
|
|
63
|
+
if (!Array.isArray(content))
|
|
64
|
+
throw invalid(`${param} must be a string or an array of parts`, param);
|
|
65
|
+
return content.map((part, index) => {
|
|
66
|
+
const at = `${param}[${index}]`;
|
|
67
|
+
if (!isRecord(part))
|
|
68
|
+
throw invalid(`${at} is not a content part`, at);
|
|
69
|
+
if (part['type'] === 'text' && typeof part['text'] === 'string')
|
|
70
|
+
return text(part['text']);
|
|
71
|
+
if (part['type'] === 'image_url') {
|
|
72
|
+
if (!caps.vision)
|
|
73
|
+
throw invalid('This model does not take image input.', at);
|
|
74
|
+
const url = isRecord(part['image_url']) ? part['image_url']['url'] : part['image_url'];
|
|
75
|
+
const match = typeof url === 'string' ? DATA_URL_RE.exec(url) : null;
|
|
76
|
+
if (!match)
|
|
77
|
+
throw invalid('An image must be a base64 data URL (data:image/…;base64,…).', at);
|
|
78
|
+
return { type: 'image', blob: match[1] };
|
|
79
|
+
}
|
|
80
|
+
throw invalid(`Content part type ${JSON.stringify(part['type'])} is not supported.`, at);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function convertMessages(raw, caps) {
|
|
84
|
+
const callNames = new Map();
|
|
85
|
+
return raw.map((item, index) => {
|
|
86
|
+
const param = `messages[${index}]`;
|
|
87
|
+
if (!isRecord(item))
|
|
88
|
+
throw invalid(`${param} is not a message`, param);
|
|
89
|
+
const role = item['role'];
|
|
90
|
+
if (role === 'system' || role === 'developer')
|
|
91
|
+
return { role: 'system', content: [text(textOf(item['content'], `${param}.content`))] };
|
|
92
|
+
if (role === 'user')
|
|
93
|
+
return { role: 'user', content: userContent(item['content'], caps, `${param}.content`) };
|
|
94
|
+
if (role === 'assistant') {
|
|
95
|
+
const said = textOf(item['content'], `${param}.content`);
|
|
96
|
+
const calls = Array.isArray(item['tool_calls']) ? item['tool_calls'] : [];
|
|
97
|
+
const message = { role: 'assistant', content: said ? [text(said)] : [] };
|
|
98
|
+
if (calls.length > 0)
|
|
99
|
+
message['tool_calls'] = calls.map((call) => {
|
|
100
|
+
const fn = isRecord(call) && isRecord(call['function']) ? call['function'] : {};
|
|
101
|
+
const name = typeof fn['name'] === 'string' ? fn['name'] : '';
|
|
102
|
+
if (isRecord(call) && typeof call['id'] === 'string')
|
|
103
|
+
callNames.set(call['id'], name);
|
|
104
|
+
return { type: 'function', function: { name, arguments: parseArguments(fn['arguments']) } };
|
|
105
|
+
});
|
|
106
|
+
return message;
|
|
107
|
+
}
|
|
108
|
+
if (role === 'tool') {
|
|
109
|
+
const id = item['tool_call_id'];
|
|
110
|
+
const name = (typeof id === 'string' ? callNames.get(id) : undefined) ??
|
|
111
|
+
(typeof item['name'] === 'string' ? item['name'] : '');
|
|
112
|
+
return {
|
|
113
|
+
role: 'tool',
|
|
114
|
+
content: [{ type: 'tool_response', name, response: parseToolResponse(item['content']) }],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
throw invalid(`${param}.role ${JSON.stringify(role)} is not system, developer, user, assistant or tool`, `${param}.role`);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function optionalNumber(body, key) {
|
|
121
|
+
const value = body[key];
|
|
122
|
+
if (value === undefined || value === null)
|
|
123
|
+
return undefined;
|
|
124
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
125
|
+
throw invalid(`${key} must be a number`, key);
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
function parseResponseFormat(raw) {
|
|
129
|
+
if (raw === undefined || raw === null)
|
|
130
|
+
return null;
|
|
131
|
+
if (!isRecord(raw))
|
|
132
|
+
throw invalid('response_format must be an object', 'response_format');
|
|
133
|
+
if (raw['type'] === 'text')
|
|
134
|
+
return null;
|
|
135
|
+
if (raw['type'] === 'json_object')
|
|
136
|
+
return { kind: 'json_schema', value: '{"type":"object"}' };
|
|
137
|
+
if (raw['type'] === 'json_schema') {
|
|
138
|
+
const schema = isRecord(raw['json_schema']) ? raw['json_schema']['schema'] : undefined;
|
|
139
|
+
if (!isRecord(schema))
|
|
140
|
+
throw invalid('response_format.json_schema.schema must be a JSON schema', 'response_format');
|
|
141
|
+
return { kind: 'json_schema', value: JSON.stringify(schema) };
|
|
142
|
+
}
|
|
143
|
+
throw invalid(`response_format type ${JSON.stringify(raw['type'])} is not supported`, 'response_format');
|
|
144
|
+
}
|
|
145
|
+
function parseThinking(body, caps) {
|
|
146
|
+
const kwargs = body['chat_template_kwargs'];
|
|
147
|
+
if (isRecord(kwargs) && typeof kwargs['enable_thinking'] === 'boolean')
|
|
148
|
+
return kwargs['enable_thinking'];
|
|
149
|
+
const effort = body['reasoning_effort'];
|
|
150
|
+
if (typeof effort === 'string')
|
|
151
|
+
return effort !== 'none';
|
|
152
|
+
return caps.reasoning;
|
|
153
|
+
}
|
|
154
|
+
/** A chat completions body, or `OpenAiRequestError` (400) naming the field it cannot serve. */
|
|
155
|
+
export function parseChatRequest(raw, caps) {
|
|
156
|
+
if (!isRecord(raw))
|
|
157
|
+
throw invalid('The request body must be a JSON object.');
|
|
158
|
+
const n = raw['n'];
|
|
159
|
+
if (n !== undefined && n !== null && n !== 1)
|
|
160
|
+
throw invalid('Only n: 1 is supported.', 'n');
|
|
161
|
+
if (!Array.isArray(raw['messages']) || raw['messages'].length === 0)
|
|
162
|
+
throw invalid('messages must be a non-empty array', 'messages');
|
|
163
|
+
const messages = convertMessages(raw['messages'], caps);
|
|
164
|
+
let split = messages.length;
|
|
165
|
+
while (split > 0 && messages[split - 1]?.['role'] === 'tool')
|
|
166
|
+
split--;
|
|
167
|
+
if (split === messages.length) {
|
|
168
|
+
if (messages.at(-1)?.['role'] !== 'user')
|
|
169
|
+
throw invalid('The last message must be from the user or a tool.', 'messages');
|
|
170
|
+
split--;
|
|
171
|
+
}
|
|
172
|
+
const toolChoice = raw['tool_choice'];
|
|
173
|
+
if (toolChoice !== undefined && toolChoice !== null && toolChoice !== 'auto' && toolChoice !== 'none')
|
|
174
|
+
throw invalid('Only tool_choice "auto" and "none" are supported.', 'tool_choice');
|
|
175
|
+
const tools = Array.isArray(raw['tools']) && raw['tools'].length > 0 && toolChoice !== 'none' ? raw['tools'] : null;
|
|
176
|
+
const streamOptions = raw['stream_options'];
|
|
177
|
+
const stop = raw['stop'];
|
|
178
|
+
const maxTokens = optionalNumber(raw, 'max_completion_tokens') ?? optionalNumber(raw, 'max_tokens');
|
|
179
|
+
const temperature = optionalNumber(raw, 'temperature');
|
|
180
|
+
const topP = optionalNumber(raw, 'top_p');
|
|
181
|
+
const topK = optionalNumber(raw, 'top_k');
|
|
182
|
+
const seed = optionalNumber(raw, 'seed');
|
|
183
|
+
return {
|
|
184
|
+
history: messages.slice(0, split),
|
|
185
|
+
next: messages.slice(split),
|
|
186
|
+
tools,
|
|
187
|
+
stream: raw['stream'] === true,
|
|
188
|
+
includeUsage: isRecord(streamOptions) && streamOptions['include_usage'] === true,
|
|
189
|
+
sampler: {
|
|
190
|
+
...(temperature !== undefined ? { temperature } : {}),
|
|
191
|
+
...(topP !== undefined ? { topP } : {}),
|
|
192
|
+
...(topK !== undefined ? { topK: Math.round(topK) } : {}),
|
|
193
|
+
...(seed !== undefined ? { seed: Math.round(seed) } : {}),
|
|
194
|
+
},
|
|
195
|
+
...(maxTokens !== undefined ? { maxTokens: Math.max(1, Math.round(maxTokens)) } : {}),
|
|
196
|
+
stop: typeof stop === 'string'
|
|
197
|
+
? [stop]
|
|
198
|
+
: Array.isArray(stop)
|
|
199
|
+
? stop.filter((s) => typeof s === 'string' && s)
|
|
200
|
+
: [],
|
|
201
|
+
responseFormat: parseResponseFormat(raw['response_format']),
|
|
202
|
+
thinking: parseThinking(raw, caps),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/** The library's words for a generation it ended at the token limit; not an error to the client. */
|
|
206
|
+
const TOKEN_LIMIT_RE = /max number of tokens/i;
|
|
207
|
+
const CANCELLED_RE = /^CANCELLED/i;
|
|
208
|
+
/** Builds one reply from the library's chunks: deltas as they come, the whole message at the end. */
|
|
209
|
+
export class ReplyBuilder {
|
|
210
|
+
stops;
|
|
211
|
+
newCallId;
|
|
212
|
+
content = '';
|
|
213
|
+
reasoning = '';
|
|
214
|
+
calls = [];
|
|
215
|
+
/** Text not yet sent because it may be the start of a stop string. */
|
|
216
|
+
held = '';
|
|
217
|
+
/** A stop string was met: everything after it is dropped and the library should be cancelled. */
|
|
218
|
+
stopped = false;
|
|
219
|
+
/** Chunks that carried generated text or thought: the completion's token count, near enough. */
|
|
220
|
+
completionChunks = 0;
|
|
221
|
+
constructor(stops, newCallId = () => `call_${Math.random().toString(36).slice(2, 14)}`) {
|
|
222
|
+
this.stops = stops;
|
|
223
|
+
this.newCallId = newCallId;
|
|
224
|
+
}
|
|
225
|
+
/** One library chunk (a message JSON, or bare text); the deltas it makes. */
|
|
226
|
+
add(raw) {
|
|
227
|
+
if (this.stopped)
|
|
228
|
+
return [];
|
|
229
|
+
let message;
|
|
230
|
+
try {
|
|
231
|
+
const parsed = JSON.parse(raw);
|
|
232
|
+
message = isRecord(parsed) ? parsed : { content: [text(raw)] };
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
message = { content: [text(raw)] };
|
|
236
|
+
}
|
|
237
|
+
const deltas = [];
|
|
238
|
+
const thought = isRecord(message['channels']) ? message['channels']['thought'] : undefined;
|
|
239
|
+
if (typeof thought === 'string' && thought) {
|
|
240
|
+
this.reasoning += thought;
|
|
241
|
+
this.completionChunks++;
|
|
242
|
+
deltas.push({ reasoning_content: thought });
|
|
243
|
+
}
|
|
244
|
+
const parts = Array.isArray(message['content']) ? message['content'] : [];
|
|
245
|
+
const said = parts
|
|
246
|
+
.map((part) => isRecord(part) && part['type'] === 'text' && typeof part['text'] === 'string' ? part['text'] : '')
|
|
247
|
+
.join('');
|
|
248
|
+
if (said) {
|
|
249
|
+
this.completionChunks++;
|
|
250
|
+
const out = this.text(said);
|
|
251
|
+
if (out)
|
|
252
|
+
deltas.push({ content: out });
|
|
253
|
+
}
|
|
254
|
+
const calls = Array.isArray(message['tool_calls']) ? message['tool_calls'] : [];
|
|
255
|
+
if (calls.length > 0) {
|
|
256
|
+
const added = calls.map((call) => {
|
|
257
|
+
const fn = isRecord(call) && isRecord(call['function']) ? call['function'] : {};
|
|
258
|
+
const made = {
|
|
259
|
+
id: this.newCallId(),
|
|
260
|
+
name: typeof fn['name'] === 'string' ? fn['name'] : '',
|
|
261
|
+
arguments: parseArguments(fn['arguments']),
|
|
262
|
+
};
|
|
263
|
+
this.calls.push(made);
|
|
264
|
+
return made;
|
|
265
|
+
});
|
|
266
|
+
deltas.push({
|
|
267
|
+
tool_calls: added.map((call) => ({
|
|
268
|
+
index: this.calls.indexOf(call),
|
|
269
|
+
id: call.id,
|
|
270
|
+
type: 'function',
|
|
271
|
+
function: { name: call.name, arguments: JSON.stringify(call.arguments) },
|
|
272
|
+
})),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return deltas;
|
|
276
|
+
}
|
|
277
|
+
/** Text to send now; holds back a tail that may begin a stop string, cuts at a whole one. */
|
|
278
|
+
text(more) {
|
|
279
|
+
const pending = this.held + more;
|
|
280
|
+
for (const stop of this.stops) {
|
|
281
|
+
const at = pending.indexOf(stop);
|
|
282
|
+
if (at >= 0) {
|
|
283
|
+
this.stopped = true;
|
|
284
|
+
this.held = '';
|
|
285
|
+
this.content += pending.slice(0, at);
|
|
286
|
+
return pending.slice(0, at);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
let keep = 0;
|
|
290
|
+
for (const stop of this.stops)
|
|
291
|
+
for (let length = Math.min(stop.length - 1, pending.length); length > keep; length--)
|
|
292
|
+
if (pending.endsWith(stop.slice(0, length))) {
|
|
293
|
+
keep = length;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
this.held = pending.slice(pending.length - keep);
|
|
297
|
+
const out = pending.slice(0, pending.length - keep);
|
|
298
|
+
this.content += out;
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
/** At the end: whatever was held back for a stop string that never came. */
|
|
302
|
+
flush() {
|
|
303
|
+
if (!this.held)
|
|
304
|
+
return [];
|
|
305
|
+
const out = this.held;
|
|
306
|
+
this.held = '';
|
|
307
|
+
this.content += out;
|
|
308
|
+
return [{ content: out }];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* The finish reason, given the error the last chunk carried. A cancel the host made for a stop
|
|
312
|
+
* string is a stop; the token limit is `length`; any other error is thrown, with the library's words.
|
|
313
|
+
*/
|
|
314
|
+
finish(error) {
|
|
315
|
+
if (error && !(this.stopped && CANCELLED_RE.test(error))) {
|
|
316
|
+
if (TOKEN_LIMIT_RE.test(error))
|
|
317
|
+
return 'length';
|
|
318
|
+
throw new OpenAiRequestError(500, `LiteRT-LM: ${error}`);
|
|
319
|
+
}
|
|
320
|
+
return this.calls.length > 0 ? 'tool_calls' : 'stop';
|
|
321
|
+
}
|
|
322
|
+
/** `choices[0].message` of a non-stream reply. */
|
|
323
|
+
message() {
|
|
324
|
+
return {
|
|
325
|
+
role: 'assistant',
|
|
326
|
+
content: this.content || this.calls.length === 0 ? this.content : null,
|
|
327
|
+
...(this.reasoning ? { reasoning_content: this.reasoning } : {}),
|
|
328
|
+
...(this.calls.length > 0
|
|
329
|
+
? {
|
|
330
|
+
tool_calls: this.calls.map((call) => ({
|
|
331
|
+
id: call.id,
|
|
332
|
+
type: 'function',
|
|
333
|
+
function: { name: call.name, arguments: JSON.stringify(call.arguments) },
|
|
334
|
+
})),
|
|
335
|
+
}
|
|
336
|
+
: {}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** The reply as the library's conversation holds it: what a continuing request must repeat. */
|
|
340
|
+
history() {
|
|
341
|
+
return {
|
|
342
|
+
role: 'assistant',
|
|
343
|
+
content: this.content ? [text(this.content)] : [],
|
|
344
|
+
...(this.calls.length > 0
|
|
345
|
+
? {
|
|
346
|
+
tool_calls: this.calls.map((call) => ({
|
|
347
|
+
type: 'function',
|
|
348
|
+
function: { name: call.name, arguments: call.arguments },
|
|
349
|
+
})),
|
|
350
|
+
}
|
|
351
|
+
: {}),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../../src/runtime/litert-lm/host/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,yFAAyF;AACzF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGhC;IAFF,IAAI,CAAiB;IAC9B,YACW,MAAc,EACvB,OAAe,EACf,QAAuB,IAAI,EAC3B,IAAI,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,uBAAuB,EAC/D,OAAsB,IAAI;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAA;QANL,WAAM,GAAN,MAAM,CAAQ;QAOvB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,E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