llmwise 0.1.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/LICENSE +22 -0
- package/README.md +75 -0
- package/dist/client.d.ts +48 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +170 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/sse.d.ts +2 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +52 -0
- package/dist/sse.js.map +1 -0
- package/dist/types.d.ts +133 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LLMWise
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# LLMWise TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Lightweight TypeScript client for the LLMWise multi-model API:
|
|
4
|
+
|
|
5
|
+
- Chat (single model + Auto routing)
|
|
6
|
+
- Failover routing (primary + fallback chain)
|
|
7
|
+
- Compare (run 2+ models in parallel)
|
|
8
|
+
- Blend (synthesize answers from multiple models, supports MoA / Self-MoA)
|
|
9
|
+
- Judge (model-vs-model evaluation)
|
|
10
|
+
|
|
11
|
+
No heavy dependencies. Works in Node 18+ and modern browsers.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install llmwise
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quickstart (Chat)
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { LLMWise } from "llmwise";
|
|
23
|
+
|
|
24
|
+
const client = new LLMWise("mm_sk_...");
|
|
25
|
+
|
|
26
|
+
const resp = await client.chat({
|
|
27
|
+
model: "auto",
|
|
28
|
+
messages: [{ role: "user", content: "Write a haiku about failover." }],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(resp.content);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Streaming (Chat)
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { LLMWise } from "llmwise";
|
|
38
|
+
|
|
39
|
+
const client = new LLMWise("mm_sk_...");
|
|
40
|
+
|
|
41
|
+
for await (const ev of client.chatStream({
|
|
42
|
+
model: "claude-sonnet-4.5",
|
|
43
|
+
messages: [{ role: "user", content: "Explain recursion to a 10-year-old." }],
|
|
44
|
+
})) {
|
|
45
|
+
if (ev.event === "done") {
|
|
46
|
+
console.log("\\nDONE", ev.credits_charged, ev.credits_remaining);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (ev.delta) process.stdout.write(ev.delta);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Failover (Chat + Routing)
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { LLMWise } from "llmwise";
|
|
57
|
+
|
|
58
|
+
const client = new LLMWise("mm_sk_...");
|
|
59
|
+
|
|
60
|
+
for await (const ev of client.chatStream({
|
|
61
|
+
model: "claude-sonnet-4.5",
|
|
62
|
+
routing: { fallback: ["gpt-5.2", "gemini-3-flash"], strategy: "rate-limit" },
|
|
63
|
+
messages: [{ role: "user", content: "Summarize this in 3 bullets: ..." }],
|
|
64
|
+
})) {
|
|
65
|
+
if (ev.event === "route" || ev.event === "trace") continue;
|
|
66
|
+
if (ev.event === "done") break;
|
|
67
|
+
if (ev.delta) process.stdout.write(ev.delta);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Configure
|
|
72
|
+
|
|
73
|
+
- Default base URL: `https://llmwise.ai/api/v1`
|
|
74
|
+
- Override with: `new LLMWise({ apiKey, baseUrl })`
|
|
75
|
+
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { BlendRequest, ChatRequest, ChatResponse, CompareRequest, JudgeRequest, StreamEvent } from "./types.js";
|
|
2
|
+
type ClientInit = string | {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
};
|
|
8
|
+
export declare class LLMWise {
|
|
9
|
+
private apiKey;
|
|
10
|
+
private baseUrl;
|
|
11
|
+
private fetchImpl;
|
|
12
|
+
private extraHeaders;
|
|
13
|
+
constructor(init: ClientInit);
|
|
14
|
+
private url;
|
|
15
|
+
private postJSON;
|
|
16
|
+
chat(req: Omit<ChatRequest, "stream"> & {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): Promise<ChatResponse>;
|
|
19
|
+
chatStream(req: Omit<ChatRequest, "stream"> & {
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
}): AsyncGenerator<StreamEvent>;
|
|
22
|
+
compare(req: Omit<CompareRequest, "stream"> & {
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}): Promise<Record<string, unknown>>;
|
|
25
|
+
compareStream(req: Omit<CompareRequest, "stream"> & {
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}): AsyncGenerator<StreamEvent>;
|
|
28
|
+
blend(req: Omit<BlendRequest, "stream"> & {
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}): Promise<Record<string, unknown>>;
|
|
31
|
+
blendStream(req: Omit<BlendRequest, "stream"> & {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}): AsyncGenerator<StreamEvent>;
|
|
34
|
+
judge(req: Omit<JudgeRequest, "stream"> & {
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}): Promise<Record<string, unknown>>;
|
|
37
|
+
judgeStream(req: Omit<JudgeRequest, "stream"> & {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): AsyncGenerator<StreamEvent>;
|
|
40
|
+
models(opts?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<unknown[]>;
|
|
43
|
+
creditsBalance(opts?: {
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}): Promise<Record<string, unknown>>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=client.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AG,cAAc,CAAC,WAAW,CAAC;IAkB3G,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAKpG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,cAAc,CAAC,WAAW,CAAC;IAkBvG,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAKpG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,cAAc,CAAC,WAAW,CAAC;IAkBvG,MAAM,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAgB3D,cAAc,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAexF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { LLMWiseError } from "./errors.js";
|
|
2
|
+
import { authHeaders, normalizeApiBase } from "./util.js";
|
|
3
|
+
import { streamSSEJSON } from "./sse.js";
|
|
4
|
+
export class LLMWise {
|
|
5
|
+
apiKey;
|
|
6
|
+
baseUrl;
|
|
7
|
+
fetchImpl;
|
|
8
|
+
extraHeaders;
|
|
9
|
+
constructor(init) {
|
|
10
|
+
if (typeof init === "string") {
|
|
11
|
+
this.apiKey = init;
|
|
12
|
+
this.baseUrl = normalizeApiBase(undefined);
|
|
13
|
+
this.fetchImpl = fetch;
|
|
14
|
+
this.extraHeaders = {};
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.apiKey = init.apiKey;
|
|
18
|
+
this.baseUrl = normalizeApiBase(init.baseUrl);
|
|
19
|
+
this.fetchImpl = init.fetch || fetch;
|
|
20
|
+
this.extraHeaders = init.headers || {};
|
|
21
|
+
}
|
|
22
|
+
url(path) {
|
|
23
|
+
const p = path.startsWith("/") ? path : `/${path}`;
|
|
24
|
+
return `${this.baseUrl}${p}`;
|
|
25
|
+
}
|
|
26
|
+
async postJSON(path, body, signal) {
|
|
27
|
+
const res = await this.fetchImpl(this.url(path), {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
...authHeaders(this.apiKey),
|
|
32
|
+
...this.extraHeaders,
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify(body),
|
|
35
|
+
signal,
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const text = await res.text().catch(() => "");
|
|
39
|
+
let payload = text;
|
|
40
|
+
let message = `HTTP ${res.status}`;
|
|
41
|
+
try {
|
|
42
|
+
payload = JSON.parse(text);
|
|
43
|
+
if (payload && typeof payload === "object" && payload.error) {
|
|
44
|
+
message = String(payload.error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
if (text)
|
|
49
|
+
message = text;
|
|
50
|
+
}
|
|
51
|
+
throw new LLMWiseError(message, { status: res.status, payload });
|
|
52
|
+
}
|
|
53
|
+
return (await res.json());
|
|
54
|
+
}
|
|
55
|
+
async chat(req) {
|
|
56
|
+
const { signal, ...payload } = req;
|
|
57
|
+
return await this.postJSON("/chat", { ...payload, stream: false }, signal);
|
|
58
|
+
}
|
|
59
|
+
async *chatStream(req) {
|
|
60
|
+
const { signal, ...payload } = req;
|
|
61
|
+
const res = await this.fetchImpl(this.url("/chat"), {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
Accept: "text/event-stream",
|
|
66
|
+
...authHeaders(this.apiKey),
|
|
67
|
+
...this.extraHeaders,
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify({ ...payload, stream: true }),
|
|
70
|
+
signal,
|
|
71
|
+
});
|
|
72
|
+
for await (const ev of streamSSEJSON(res)) {
|
|
73
|
+
yield ev;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async compare(req) {
|
|
77
|
+
const { signal, ...payload } = req;
|
|
78
|
+
return await this.postJSON("/compare", { ...payload, stream: false }, signal);
|
|
79
|
+
}
|
|
80
|
+
async *compareStream(req) {
|
|
81
|
+
const { signal, ...payload } = req;
|
|
82
|
+
const res = await this.fetchImpl(this.url("/compare"), {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
Accept: "text/event-stream",
|
|
87
|
+
...authHeaders(this.apiKey),
|
|
88
|
+
...this.extraHeaders,
|
|
89
|
+
},
|
|
90
|
+
body: JSON.stringify({ ...payload, stream: true }),
|
|
91
|
+
signal,
|
|
92
|
+
});
|
|
93
|
+
for await (const ev of streamSSEJSON(res)) {
|
|
94
|
+
yield ev;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async blend(req) {
|
|
98
|
+
const { signal, ...payload } = req;
|
|
99
|
+
return await this.postJSON("/blend", { ...payload, stream: false }, signal);
|
|
100
|
+
}
|
|
101
|
+
async *blendStream(req) {
|
|
102
|
+
const { signal, ...payload } = req;
|
|
103
|
+
const res = await this.fetchImpl(this.url("/blend"), {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: {
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
Accept: "text/event-stream",
|
|
108
|
+
...authHeaders(this.apiKey),
|
|
109
|
+
...this.extraHeaders,
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({ ...payload, stream: true }),
|
|
112
|
+
signal,
|
|
113
|
+
});
|
|
114
|
+
for await (const ev of streamSSEJSON(res)) {
|
|
115
|
+
yield ev;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async judge(req) {
|
|
119
|
+
const { signal, ...payload } = req;
|
|
120
|
+
return await this.postJSON("/judge", { ...payload, stream: false }, signal);
|
|
121
|
+
}
|
|
122
|
+
async *judgeStream(req) {
|
|
123
|
+
const { signal, ...payload } = req;
|
|
124
|
+
const res = await this.fetchImpl(this.url("/judge"), {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: {
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
Accept: "text/event-stream",
|
|
129
|
+
...authHeaders(this.apiKey),
|
|
130
|
+
...this.extraHeaders,
|
|
131
|
+
},
|
|
132
|
+
body: JSON.stringify({ ...payload, stream: true }),
|
|
133
|
+
signal,
|
|
134
|
+
});
|
|
135
|
+
for await (const ev of streamSSEJSON(res)) {
|
|
136
|
+
yield ev;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async models(opts) {
|
|
140
|
+
const res = await this.fetchImpl(this.url("/models"), {
|
|
141
|
+
method: "GET",
|
|
142
|
+
headers: {
|
|
143
|
+
...authHeaders(this.apiKey),
|
|
144
|
+
...this.extraHeaders,
|
|
145
|
+
},
|
|
146
|
+
signal: opts?.signal,
|
|
147
|
+
});
|
|
148
|
+
if (!res.ok) {
|
|
149
|
+
const text = await res.text().catch(() => "");
|
|
150
|
+
throw new LLMWiseError(text || `HTTP ${res.status}`, { status: res.status, payload: text || undefined });
|
|
151
|
+
}
|
|
152
|
+
return (await res.json());
|
|
153
|
+
}
|
|
154
|
+
async creditsBalance(opts) {
|
|
155
|
+
const res = await this.fetchImpl(this.url("/credits/balance"), {
|
|
156
|
+
method: "GET",
|
|
157
|
+
headers: {
|
|
158
|
+
...authHeaders(this.apiKey),
|
|
159
|
+
...this.extraHeaders,
|
|
160
|
+
},
|
|
161
|
+
signal: opts?.signal,
|
|
162
|
+
});
|
|
163
|
+
if (!res.ok) {
|
|
164
|
+
const text = await res.text().catch(() => "");
|
|
165
|
+
throw new LLMWiseError(text || `HTTP ${res.status}`, { status: res.status, payload: text || undefined });
|
|
166
|
+
}
|
|
167
|
+
return (await res.json());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAS1D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAWzC,MAAM,OAAO,OAAO;IACV,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,SAAS,CAAe;IACxB,YAAY,CAAyB;IAE7C,YAAY,IAAgB;QAC1B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;YAC3C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IACzC,CA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,YAAY,CAAC,IAAI,IAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,CAAC,CAAC;QAC3G,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA4B,CAAC;IACvD,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEN,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;CAMzE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,MAAM,CAAS;IACf,OAAO,CAAW;IAElB,YAAY,OAAe,EAAE,IAA2C;QACtE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,cAAc,YAAY,CAAC"}
|
package/dist/sse.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAgBA,wBAAuB,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAoCvF"}
|
package/dist/sse.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LLMWiseError } from "./errors.js";
|
|
2
|
+
async function parseErrorPayload(res) {
|
|
3
|
+
const text = await res.text().catch(() => "");
|
|
4
|
+
try {
|
|
5
|
+
const json = JSON.parse(text);
|
|
6
|
+
if (json && typeof json === "object" && "error" in json) {
|
|
7
|
+
const msg = String(json.error || "Request failed");
|
|
8
|
+
return { message: msg, payload: json };
|
|
9
|
+
}
|
|
10
|
+
return { message: "Request failed", payload: json };
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return { message: text || "Request failed", payload: text || undefined };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function* streamSSEJSON(res) {
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
const err = await parseErrorPayload(res);
|
|
19
|
+
throw new LLMWiseError(err.message, { status: res.status, payload: err.payload });
|
|
20
|
+
}
|
|
21
|
+
const reader = res.body?.getReader();
|
|
22
|
+
if (!reader) {
|
|
23
|
+
throw new LLMWiseError("No response body", { status: 502 });
|
|
24
|
+
}
|
|
25
|
+
const decoder = new TextDecoder();
|
|
26
|
+
let buffer = "";
|
|
27
|
+
while (true) {
|
|
28
|
+
const { done, value } = await reader.read();
|
|
29
|
+
if (done)
|
|
30
|
+
break;
|
|
31
|
+
buffer += decoder.decode(value, { stream: true });
|
|
32
|
+
const lines = buffer.split("\\n");
|
|
33
|
+
buffer = lines.pop() || "";
|
|
34
|
+
for (const line of lines) {
|
|
35
|
+
const trimmed = line.trim();
|
|
36
|
+
if (!trimmed.startsWith("data:"))
|
|
37
|
+
continue;
|
|
38
|
+
const data = trimmed.slice(5).trim();
|
|
39
|
+
if (!data)
|
|
40
|
+
continue;
|
|
41
|
+
if (data === "[DONE]")
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
yield JSON.parse(data);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Ignore malformed JSON chunks
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=sse.js.map
|
package/dist/sse.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,KAAK,UAAU,iBAAiB,CAAC,GAAa;IAC5C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACxD,MAAM,GAAG,GAAG,MAAM,CAAE,IAAY,CAAC,KAAK,IAAI,gBAAgB,CAAC,CAAC;YAC5D,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACzC,CAAC;QACD,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KAAK,EAAE,CAAC;YACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,SAAS;YAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,CAAC,IAAI;gBAAE,SAAS;YACpB,IAAI,IAAI,KAAK,QAAQ;gBAAE,OAAO;YAE9B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACP,+BAA+B;YACjC,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export type Role = "system" | "user" | "assistant";
|
|
2
|
+
export type TextBlock = {
|
|
3
|
+
type: "text";
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
export type ImageBlock = {
|
|
7
|
+
type: "image_url";
|
|
8
|
+
image_url: {
|
|
9
|
+
url: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type ContentBlock = TextBlock | ImageBlock;
|
|
13
|
+
export type MessageContent = string | ContentBlock[];
|
|
14
|
+
export type Message = {
|
|
15
|
+
role: Role;
|
|
16
|
+
content: MessageContent;
|
|
17
|
+
};
|
|
18
|
+
export type OptimizationGoal = "balanced" | "latency" | "cost" | "reliability";
|
|
19
|
+
export type RoutingConfig = {
|
|
20
|
+
fallback: string[];
|
|
21
|
+
strategy?: string;
|
|
22
|
+
};
|
|
23
|
+
export type ChatRequest = {
|
|
24
|
+
model: string;
|
|
25
|
+
messages: Message[];
|
|
26
|
+
temperature?: number;
|
|
27
|
+
max_tokens?: number;
|
|
28
|
+
stream?: boolean;
|
|
29
|
+
cost_saver?: boolean;
|
|
30
|
+
optimization_goal?: OptimizationGoal;
|
|
31
|
+
semantic_memory?: boolean;
|
|
32
|
+
semantic_top_k?: number;
|
|
33
|
+
semantic_min_score?: number;
|
|
34
|
+
routing?: RoutingConfig;
|
|
35
|
+
conversation_id?: string;
|
|
36
|
+
};
|
|
37
|
+
export type CompareRequest = {
|
|
38
|
+
models: string[];
|
|
39
|
+
messages: Message[];
|
|
40
|
+
temperature?: number;
|
|
41
|
+
max_tokens?: number;
|
|
42
|
+
stream?: boolean;
|
|
43
|
+
semantic_memory?: boolean;
|
|
44
|
+
semantic_top_k?: number;
|
|
45
|
+
semantic_min_score?: number;
|
|
46
|
+
conversation_id?: string;
|
|
47
|
+
};
|
|
48
|
+
export type BlendRequest = {
|
|
49
|
+
models: string[];
|
|
50
|
+
messages: Message[];
|
|
51
|
+
temperature?: number;
|
|
52
|
+
max_tokens?: number;
|
|
53
|
+
stream?: boolean;
|
|
54
|
+
semantic_memory?: boolean;
|
|
55
|
+
semantic_top_k?: number;
|
|
56
|
+
semantic_min_score?: number;
|
|
57
|
+
strategy?: "consensus" | "council" | "best_of" | "chain" | "moa" | "self_moa";
|
|
58
|
+
synthesizer?: string;
|
|
59
|
+
layers?: number;
|
|
60
|
+
samples?: number;
|
|
61
|
+
conversation_id?: string;
|
|
62
|
+
};
|
|
63
|
+
export type JudgeRequest = {
|
|
64
|
+
contestants: string[];
|
|
65
|
+
judge: string;
|
|
66
|
+
messages: Message[];
|
|
67
|
+
temperature?: number;
|
|
68
|
+
max_tokens?: number;
|
|
69
|
+
stream?: boolean;
|
|
70
|
+
semantic_memory?: boolean;
|
|
71
|
+
semantic_top_k?: number;
|
|
72
|
+
semantic_min_score?: number;
|
|
73
|
+
criteria?: string[];
|
|
74
|
+
conversation_id?: string;
|
|
75
|
+
};
|
|
76
|
+
export type StreamEvent = {
|
|
77
|
+
model?: string;
|
|
78
|
+
delta?: string;
|
|
79
|
+
done?: boolean;
|
|
80
|
+
error?: string;
|
|
81
|
+
event?: string;
|
|
82
|
+
status?: string;
|
|
83
|
+
status_code?: number;
|
|
84
|
+
latency_ms?: number;
|
|
85
|
+
content_length?: number;
|
|
86
|
+
ttft_ms?: number;
|
|
87
|
+
prompt_tokens?: number;
|
|
88
|
+
completion_tokens?: number;
|
|
89
|
+
tokens_per_second?: number;
|
|
90
|
+
cost?: number;
|
|
91
|
+
finish_reason?: string;
|
|
92
|
+
credits_charged?: number;
|
|
93
|
+
credits_remaining?: number;
|
|
94
|
+
byok?: boolean;
|
|
95
|
+
conversation_id?: string;
|
|
96
|
+
resolved_model?: string;
|
|
97
|
+
auto_strategy?: string;
|
|
98
|
+
optimization_goal?: OptimizationGoal;
|
|
99
|
+
trace?: Array<{
|
|
100
|
+
model: string;
|
|
101
|
+
status: string;
|
|
102
|
+
status_code?: number;
|
|
103
|
+
latency_ms?: number;
|
|
104
|
+
}>;
|
|
105
|
+
final_model?: string;
|
|
106
|
+
saved_ms?: number;
|
|
107
|
+
fastest?: string;
|
|
108
|
+
longest?: string;
|
|
109
|
+
models?: Record<string, {
|
|
110
|
+
latency_ms: number;
|
|
111
|
+
tokens: number;
|
|
112
|
+
}>;
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
};
|
|
115
|
+
export type ChatResponse = {
|
|
116
|
+
id: string;
|
|
117
|
+
model: string;
|
|
118
|
+
content: string;
|
|
119
|
+
prompt_tokens?: number;
|
|
120
|
+
completion_tokens?: number;
|
|
121
|
+
latency_ms?: number;
|
|
122
|
+
cost?: number;
|
|
123
|
+
credits_charged?: number;
|
|
124
|
+
credits_remaining?: number;
|
|
125
|
+
finish_reason?: string | null;
|
|
126
|
+
mode?: string;
|
|
127
|
+
conversation_id?: string;
|
|
128
|
+
resolved_model?: string;
|
|
129
|
+
auto_strategy?: string;
|
|
130
|
+
optimization_goal?: OptimizationGoal;
|
|
131
|
+
[key: string]: unknown;
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","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AQ,CAAC,EAAE,MAAM,CAAC;IAElB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEhE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,gBAAgB,CAAC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGnE"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function normalizeApiBase(baseUrl) {
|
|
2
|
+
const raw = (baseUrl || "").trim().replace(/\/+$/, "");
|
|
3
|
+
if (!raw)
|
|
4
|
+
return "https://llmwise.ai/api/v1";
|
|
5
|
+
if (raw.endsWith("/api/v1"))
|
|
6
|
+
return raw;
|
|
7
|
+
return `${raw}/api/v1`;
|
|
8
|
+
}
|
|
9
|
+
export function authHeaders(apiKey) {
|
|
10
|
+
if (!apiKey)
|
|
11
|
+
return {};
|
|
12
|
+
return { Authorization: `Bearer ${apiKey}` };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvD,IAAI,CAAC,GAAG;QAAE,OAAO,2BAA2B,CAAC;IAC7C,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,GAAG,GAAG,SAAS,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,OAAO,EAAE,aAAa,EAAE,UAAU,MAAM,EAAE,EAAE,CAAC;AAC/C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "llmwise",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lightweight TypeScript SDK for the LLMWise multi-model API (chat, compare, blend, judge, failover).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
26
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
|
+
"prepack": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.6.3"
|
|
32
|
+
}
|
|
33
|
+
}
|