@anvaka/vue-llm 0.4.1 → 0.4.2
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/core/LLMClient.js +126 -89
- package/dist/providers/AnthropicProvider.js +35 -40
- package/dist/providers/BaseProvider.js +114 -60
- package/dist/providers/BedrockMantleProvider.js +55 -48
- package/dist/providers/BedrockProvider.js +63 -70
- package/dist/providers/CustomProvider.js +3 -4
- package/dist/providers/DeepSeekProvider.js +5 -6
- package/dist/providers/GrokProvider.js +43 -44
- package/dist/providers/LlamaServerProvider.js +7 -8
- package/dist/providers/OpenAIProvider.js +77 -77
- package/dist/providers/OpenRouterProvider.js +3 -4
- package/dist/providers/samplingPolicy.js +41 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseProvider as
|
|
2
|
-
import { AnthropicProvider as
|
|
3
|
-
const
|
|
1
|
+
import { BaseProvider as b } from "./BaseProvider.js";
|
|
2
|
+
import { AnthropicProvider as v } from "./AnthropicProvider.js";
|
|
3
|
+
const f = [
|
|
4
4
|
"us.anthropic.claude-opus-4-8",
|
|
5
5
|
"us.anthropic.claude-opus-4-7",
|
|
6
6
|
"us.anthropic.claude-sonnet-4-6",
|
|
@@ -10,13 +10,13 @@ const p = [
|
|
|
10
10
|
"us.anthropic.claude-sonnet-4-5-20250929-v1:0",
|
|
11
11
|
"us.anthropic.claude-opus-4-1-20250805-v1:0"
|
|
12
12
|
];
|
|
13
|
-
class A extends
|
|
13
|
+
class A extends v {
|
|
14
14
|
prepareRequest(r, n) {
|
|
15
15
|
const t = super.prepareRequest(r, n);
|
|
16
16
|
return delete t.stream, t.anthropic_version = "bedrock-2023-05-31", t;
|
|
17
17
|
}
|
|
18
18
|
buildHeaders() {
|
|
19
|
-
return
|
|
19
|
+
return b.prototype.buildHeaders.call(this);
|
|
20
20
|
}
|
|
21
21
|
getAuthHeaderName() {
|
|
22
22
|
return "Authorization";
|
|
@@ -28,68 +28,61 @@ class A extends w {
|
|
|
28
28
|
return !!this.config.apiKey;
|
|
29
29
|
}
|
|
30
30
|
async makeRequest(r, n, t) {
|
|
31
|
-
const e = r.model,
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const o = await fetch(i, {
|
|
31
|
+
const e = r.model, c = `${this.config.baseUrl}/model/${encodeURIComponent(e)}/invoke`, u = n ? { signal: n } : new AbortController();
|
|
32
|
+
n || (t = t || this.generateRequestId(), this.activeRequests.set(t, u));
|
|
33
|
+
const d = () => {
|
|
34
|
+
const i = { ...r };
|
|
35
|
+
return delete i.model, fetch(c, {
|
|
37
36
|
method: "POST",
|
|
38
37
|
headers: this.buildHeaders(),
|
|
39
|
-
body: JSON.stringify(
|
|
40
|
-
signal:
|
|
38
|
+
body: JSON.stringify(i),
|
|
39
|
+
signal: u.signal || n
|
|
41
40
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return o.json();
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
return (await this._sendWithTemperatureRetry(d, r, "Bedrock API Error")).json();
|
|
47
44
|
} finally {
|
|
48
45
|
!n && t && this.activeRequests.delete(t);
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
async makeStreamingRequest(r, n) {
|
|
52
|
-
const t = r.model, e = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error(`Bedrock API Error (${i.status}): ${c}`);
|
|
63
|
-
}
|
|
64
|
-
const l = i.body.getReader(), o = new v(), h = new TextEncoder(), f = new ReadableStream({
|
|
65
|
-
async pull(c) {
|
|
49
|
+
const t = r.model, e = `${this.config.baseUrl}/model/${encodeURIComponent(t)}/invoke-with-response-stream`, c = () => {
|
|
50
|
+
const o = { ...r };
|
|
51
|
+
return delete o.model, fetch(e, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: this.buildHeaders(),
|
|
54
|
+
body: JSON.stringify(o),
|
|
55
|
+
signal: n
|
|
56
|
+
});
|
|
57
|
+
}, d = (await this._sendWithTemperatureRetry(c, r, "Bedrock API Error")).body.getReader(), i = new w(), m = new TextEncoder(), h = new ReadableStream({
|
|
58
|
+
async pull(o) {
|
|
66
59
|
try {
|
|
67
|
-
const { done: a, value:
|
|
60
|
+
const { done: a, value: y } = await d.read();
|
|
68
61
|
if (a) {
|
|
69
|
-
|
|
62
|
+
o.close();
|
|
70
63
|
return;
|
|
71
64
|
}
|
|
72
|
-
const
|
|
73
|
-
for (const
|
|
74
|
-
if (
|
|
75
|
-
|
|
65
|
+
const p = i.feed(y);
|
|
66
|
+
for (const l of p) {
|
|
67
|
+
if (l.kind === "error") {
|
|
68
|
+
o.error(new Error(l.message));
|
|
76
69
|
return;
|
|
77
70
|
}
|
|
78
|
-
|
|
71
|
+
o.enqueue(m.encode(`data: ${JSON.stringify(l.payload)}
|
|
79
72
|
`));
|
|
80
73
|
}
|
|
81
74
|
} catch (a) {
|
|
82
|
-
|
|
75
|
+
o.error(a);
|
|
83
76
|
}
|
|
84
77
|
},
|
|
85
|
-
cancel(
|
|
78
|
+
cancel(o) {
|
|
86
79
|
try {
|
|
87
|
-
|
|
80
|
+
d.cancel(o);
|
|
88
81
|
} catch {
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
84
|
});
|
|
92
|
-
return new Response(
|
|
85
|
+
return new Response(h, { status: 200, headers: { "Content-Type": "text/event-stream" } });
|
|
93
86
|
}
|
|
94
87
|
// Live discovery is opt-in via config.liveModelDiscovery. A Bedrock API key
|
|
95
88
|
// authenticates against the control plane with Bearer auth (no SigV4), and
|
|
@@ -102,12 +95,12 @@ class A extends w {
|
|
|
102
95
|
// unset and keep the "no surprise network calls" default.
|
|
103
96
|
async discoverModels(r = 1e4, { force: n = !1 } = {}) {
|
|
104
97
|
if (!n && !this.config.liveModelDiscovery || !this.getModelsEndpoint())
|
|
105
|
-
return
|
|
98
|
+
return f.slice();
|
|
106
99
|
try {
|
|
107
100
|
const t = await super.discoverModels(r);
|
|
108
|
-
return t.length ? t :
|
|
101
|
+
return t.length ? t : f.slice();
|
|
109
102
|
} catch {
|
|
110
|
-
return
|
|
103
|
+
return f.slice();
|
|
111
104
|
}
|
|
112
105
|
}
|
|
113
106
|
// The control plane lives at the same host with the `-runtime` segment
|
|
@@ -125,12 +118,12 @@ class A extends w {
|
|
|
125
118
|
// exactly what InvokeModel expects in the URL path.
|
|
126
119
|
parseModelsResponse(r) {
|
|
127
120
|
const n = r == null ? void 0 : r.inferenceProfileSummaries;
|
|
128
|
-
if (!Array.isArray(n)) return
|
|
121
|
+
if (!Array.isArray(n)) return f.slice();
|
|
129
122
|
const t = n.map((e) => e == null ? void 0 : e.inferenceProfileId).filter((e) => typeof e == "string" && e.includes("anthropic.claude"));
|
|
130
|
-
return t.length ? t :
|
|
123
|
+
return t.length ? t : f.slice();
|
|
131
124
|
}
|
|
132
125
|
}
|
|
133
|
-
class
|
|
126
|
+
class w {
|
|
134
127
|
constructor() {
|
|
135
128
|
this.buf = new Uint8Array(0), this.textDecoder = new TextDecoder();
|
|
136
129
|
}
|
|
@@ -141,30 +134,30 @@ class v {
|
|
|
141
134
|
}
|
|
142
135
|
const n = [];
|
|
143
136
|
for (; this.buf.length >= 12; ) {
|
|
144
|
-
const t = new DataView(this.buf.buffer, this.buf.byteOffset, this.buf.byteLength), e = t.getUint32(0, !1),
|
|
137
|
+
const t = new DataView(this.buf.buffer, this.buf.byteOffset, this.buf.byteLength), e = t.getUint32(0, !1), c = t.getUint32(4, !1);
|
|
145
138
|
if (e < 16 || e > 16 * 1024 * 1024)
|
|
146
139
|
throw new Error(`Bedrock event stream: invalid frame length ${e}`);
|
|
147
140
|
if (this.buf.length < e) break;
|
|
148
|
-
const
|
|
141
|
+
const u = 12, d = u + c, i = d, m = e - 4, h = k(this.buf.subarray(u, d)), o = this.textDecoder.decode(this.buf.subarray(i, m));
|
|
149
142
|
this.buf = this.buf.subarray(e);
|
|
150
143
|
let a;
|
|
151
144
|
try {
|
|
152
|
-
a = JSON.parse(
|
|
145
|
+
a = JSON.parse(o);
|
|
153
146
|
} catch {
|
|
154
147
|
a = null;
|
|
155
148
|
}
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
n.push({ kind: "error", message: `${
|
|
149
|
+
const y = h[":message-type"], p = h[":exception-type"];
|
|
150
|
+
if (y === "exception" || p) {
|
|
151
|
+
const l = p || h[":event-type"] || "BedrockStreamException", g = (a == null ? void 0 : a.message) || o || "unknown error";
|
|
152
|
+
n.push({ kind: "error", message: `${l}: ${g}` });
|
|
160
153
|
continue;
|
|
161
154
|
}
|
|
162
155
|
if (a && typeof a.bytes == "string")
|
|
163
156
|
try {
|
|
164
|
-
const
|
|
165
|
-
n.push({ kind: "event", payload:
|
|
166
|
-
} catch (
|
|
167
|
-
n.push({ kind: "error", message: `Bedrock event-stream decode failed: ${
|
|
157
|
+
const l = R(a.bytes), g = JSON.parse(l);
|
|
158
|
+
n.push({ kind: "event", payload: g });
|
|
159
|
+
} catch (l) {
|
|
160
|
+
n.push({ kind: "error", message: `Bedrock event-stream decode failed: ${l.message}` });
|
|
168
161
|
}
|
|
169
162
|
}
|
|
170
163
|
return n;
|
|
@@ -174,27 +167,27 @@ function k(s) {
|
|
|
174
167
|
const r = {}, n = new DataView(s.buffer, s.byteOffset, s.byteLength), t = new TextDecoder();
|
|
175
168
|
let e = 0;
|
|
176
169
|
for (; e < s.length; ) {
|
|
170
|
+
const c = s[e];
|
|
171
|
+
if (e += 1, e + c > s.length) break;
|
|
172
|
+
const u = t.decode(s.subarray(e, e + c));
|
|
173
|
+
if (e += c, e >= s.length) break;
|
|
177
174
|
const d = s[e];
|
|
178
|
-
if (e += 1,
|
|
179
|
-
const i = t.decode(s.subarray(e, e + d));
|
|
180
|
-
if (e += d, e >= s.length) break;
|
|
181
|
-
const l = s[e];
|
|
182
|
-
if (e += 1, l === 7) {
|
|
175
|
+
if (e += 1, d === 7) {
|
|
183
176
|
if (e + 2 > s.length) break;
|
|
184
|
-
const
|
|
185
|
-
if (e += 2, e +
|
|
186
|
-
r[
|
|
177
|
+
const i = n.getUint16(e, !1);
|
|
178
|
+
if (e += 2, e + i > s.length) break;
|
|
179
|
+
r[u] = t.decode(s.subarray(e, e + i)), e += i;
|
|
187
180
|
} else
|
|
188
181
|
break;
|
|
189
182
|
}
|
|
190
183
|
return r;
|
|
191
184
|
}
|
|
192
|
-
function
|
|
185
|
+
function R(s) {
|
|
193
186
|
const r = atob(s), n = new Uint8Array(r.length);
|
|
194
187
|
for (let t = 0; t < r.length; t++) n[t] = r.charCodeAt(t);
|
|
195
188
|
return new TextDecoder().decode(n);
|
|
196
189
|
}
|
|
197
190
|
export {
|
|
198
|
-
|
|
191
|
+
f as BEDROCK_CLAUDE_MODELS,
|
|
199
192
|
A as BedrockProvider
|
|
200
193
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseProvider as d } from "./BaseProvider.js";
|
|
2
2
|
import { convertMessagesToOpenAI as g, normalizeOpenAIUsage as u } from "./OpenAIProvider.js";
|
|
3
|
-
class
|
|
3
|
+
class y extends d {
|
|
4
4
|
async detectCapabilities() {
|
|
5
5
|
this.capabilities.add("tools");
|
|
6
6
|
}
|
|
@@ -8,11 +8,10 @@ class A extends d {
|
|
|
8
8
|
const t = {
|
|
9
9
|
model: e.model || this.config.model || "gpt-3.5-turbo",
|
|
10
10
|
messages: g(n),
|
|
11
|
-
temperature: e.temperature ?? 0.7,
|
|
12
11
|
max_tokens: e.maxTokens || 1e3,
|
|
13
12
|
stream: e.stream || !1
|
|
14
13
|
};
|
|
15
|
-
return t.stream && (t.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
|
|
14
|
+
return this.applySamplingParams(t, e), t.stream && (t.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
|
|
16
15
|
}
|
|
17
16
|
processResponse(n) {
|
|
18
17
|
var s, o, i, a;
|
|
@@ -90,5 +89,5 @@ function h(r) {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
export {
|
|
93
|
-
|
|
92
|
+
y as CustomProvider
|
|
94
93
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseProvider as
|
|
2
|
-
import { convertMessagesToOpenAI as
|
|
3
|
-
class b extends
|
|
1
|
+
import { BaseProvider as h } from "./BaseProvider.js";
|
|
2
|
+
import { convertMessagesToOpenAI as d } from "./OpenAIProvider.js";
|
|
3
|
+
class b extends h {
|
|
4
4
|
async detectCapabilities() {
|
|
5
5
|
if (!this.config.model) return;
|
|
6
6
|
const t = this.config.model.toLowerCase();
|
|
@@ -10,11 +10,10 @@ class b extends d {
|
|
|
10
10
|
const n = {
|
|
11
11
|
model: e.model || this.config.model || "deepseek-chat",
|
|
12
12
|
messages: _(t),
|
|
13
|
-
temperature: e.temperature ?? 0.7,
|
|
14
13
|
max_tokens: e.maxTokens || 1e3,
|
|
15
14
|
stream: e.stream || !1
|
|
16
15
|
};
|
|
17
|
-
return n.stream && (n.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (n.tools = e.tools, e.tool_choice && (n.tool_choice = e.tool_choice)), e.enableThinking && this.capabilities.has("thinking") && (n.thinking = { type: "enabled" }), n;
|
|
16
|
+
return this.applySamplingParams(n, e), n.stream && (n.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (n.tools = e.tools, e.tool_choice && (n.tool_choice = e.tool_choice)), e.enableThinking && this.capabilities.has("thinking") && (n.thinking = { type: "enabled" }), n;
|
|
18
17
|
}
|
|
19
18
|
processResponse(t) {
|
|
20
19
|
var s, i, a, r;
|
|
@@ -103,7 +102,7 @@ function u(o) {
|
|
|
103
102
|
return o.prompt_cache_hit_tokens != null && (s.cachedInputTokens = o.prompt_cache_hit_tokens), s;
|
|
104
103
|
}
|
|
105
104
|
function _(o) {
|
|
106
|
-
return
|
|
105
|
+
return d(o).map((e, n) => {
|
|
107
106
|
if (e.role !== "assistant") return e;
|
|
108
107
|
const s = o[n] || {}, i = s.thinking || s.reasoning_content, { thinking: a, reasoning_content: r, ...c } = e;
|
|
109
108
|
return i && (c.reasoning_content = i), c;
|
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
import { BaseProvider as g } from "./BaseProvider.js";
|
|
2
|
-
import { convertMessagesToOpenAI as m, normalizeOpenAIUsage as
|
|
2
|
+
import { convertMessagesToOpenAI as m, normalizeOpenAIUsage as c } from "./OpenAIProvider.js";
|
|
3
3
|
class y extends g {
|
|
4
4
|
async detectCapabilities() {
|
|
5
5
|
if (!this.config.model) return;
|
|
6
|
-
const
|
|
7
|
-
(
|
|
6
|
+
const s = this.config.model.toLowerCase();
|
|
7
|
+
(s.includes("grok-2") || s.includes("vision")) && this.capabilities.add("vision"), this.capabilities.add("tools");
|
|
8
8
|
}
|
|
9
|
-
prepareRequest(
|
|
10
|
-
const
|
|
9
|
+
prepareRequest(s, e) {
|
|
10
|
+
const t = {
|
|
11
11
|
model: e.model || this.config.model || "grok-beta",
|
|
12
|
-
messages: this.processMessages(
|
|
13
|
-
temperature: e.temperature ?? 0.7,
|
|
12
|
+
messages: this.processMessages(s, e),
|
|
14
13
|
max_tokens: e.maxTokens || 1e3,
|
|
15
14
|
stream: e.stream || !1
|
|
16
15
|
};
|
|
17
|
-
return
|
|
16
|
+
return this.applySamplingParams(t, e), t.stream && (t.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
|
|
18
17
|
}
|
|
19
|
-
processMessages(
|
|
20
|
-
const
|
|
21
|
-
return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(
|
|
18
|
+
processMessages(s, e) {
|
|
19
|
+
const t = m(s);
|
|
20
|
+
return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(t, e.images) : t;
|
|
22
21
|
}
|
|
23
|
-
addImagesToMessages(
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
e.forEach((
|
|
22
|
+
addImagesToMessages(s, e) {
|
|
23
|
+
const t = s[s.length - 1];
|
|
24
|
+
if (t && t.role === "user") {
|
|
25
|
+
const r = [{ type: "text", text: t.content }];
|
|
26
|
+
e.forEach((n) => r.push({ type: "image_url", image_url: { url: typeof n == "string" ? n : n.url } })), t.content = r;
|
|
28
27
|
}
|
|
29
|
-
return
|
|
28
|
+
return s;
|
|
30
29
|
}
|
|
31
|
-
processResponse(
|
|
32
|
-
var
|
|
33
|
-
const e = (
|
|
30
|
+
processResponse(s) {
|
|
31
|
+
var r, n, i, o;
|
|
32
|
+
const e = (n = (r = s.choices) == null ? void 0 : r[0]) == null ? void 0 : n.message, t = {
|
|
34
33
|
content: (e == null ? void 0 : e.content) || "",
|
|
35
|
-
usage:
|
|
36
|
-
finishReason:
|
|
34
|
+
usage: c(s.usage),
|
|
35
|
+
finishReason: u((o = (i = s.choices) == null ? void 0 : i[0]) == null ? void 0 : o.finish_reason)
|
|
37
36
|
};
|
|
38
|
-
return Array.isArray(e == null ? void 0 : e.tool_calls) && (
|
|
37
|
+
return Array.isArray(e == null ? void 0 : e.tool_calls) && (t.toolCalls = e.tool_calls.map((l) => {
|
|
39
38
|
var d, f;
|
|
40
39
|
return {
|
|
41
40
|
id: l.id,
|
|
42
41
|
name: (d = l.function) == null ? void 0 : d.name,
|
|
43
42
|
args: h((f = l.function) == null ? void 0 : f.arguments)
|
|
44
43
|
};
|
|
45
|
-
})),
|
|
44
|
+
})), t;
|
|
46
45
|
}
|
|
47
|
-
parseStreamingLine(
|
|
48
|
-
if (!
|
|
49
|
-
const e =
|
|
46
|
+
parseStreamingLine(s) {
|
|
47
|
+
if (!s.startsWith("data: ")) return null;
|
|
48
|
+
const e = s.slice(6).trim();
|
|
50
49
|
if (e === "[DONE]") return { done: !0 };
|
|
51
50
|
try {
|
|
52
51
|
return JSON.parse(e);
|
|
@@ -54,26 +53,26 @@ class y extends g {
|
|
|
54
53
|
return null;
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
|
-
extractStreamingContent(
|
|
58
|
-
var
|
|
59
|
-
if (
|
|
60
|
-
const e = (
|
|
61
|
-
if (
|
|
62
|
-
const o =
|
|
56
|
+
extractStreamingContent(s) {
|
|
57
|
+
var r, n, i;
|
|
58
|
+
if (s.done) return { done: !0 };
|
|
59
|
+
const e = (r = s.choices) == null ? void 0 : r[0], t = e == null ? void 0 : e.delta;
|
|
60
|
+
if (t && Array.isArray(t.tool_calls) && t.tool_calls.length) {
|
|
61
|
+
const o = t.tool_calls[0];
|
|
63
62
|
return {
|
|
64
|
-
content:
|
|
63
|
+
content: t.content || "",
|
|
65
64
|
done: !1,
|
|
66
|
-
usage:
|
|
67
|
-
finishReason:
|
|
65
|
+
usage: c(s.usage),
|
|
66
|
+
finishReason: u(e == null ? void 0 : e.finish_reason),
|
|
68
67
|
toolCallDelta: {
|
|
69
68
|
index: o.index ?? 0,
|
|
70
69
|
id: o.id || void 0,
|
|
71
|
-
name: ((
|
|
70
|
+
name: ((n = o.function) == null ? void 0 : n.name) || void 0,
|
|
72
71
|
argsTextDelta: ((i = o.function) == null ? void 0 : i.arguments) || ""
|
|
73
72
|
}
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
|
-
return { content: (
|
|
75
|
+
return { content: (t == null ? void 0 : t.content) || "", done: !1, usage: c(s.usage), finishReason: u(e == null ? void 0 : e.finish_reason) };
|
|
77
76
|
}
|
|
78
77
|
getApiPath() {
|
|
79
78
|
return "/v1/chat/completions";
|
|
@@ -84,15 +83,15 @@ class y extends g {
|
|
|
84
83
|
getModelsEndpoint() {
|
|
85
84
|
return `${this.config.baseUrl}/v1/models`;
|
|
86
85
|
}
|
|
87
|
-
parseModelsResponse(
|
|
88
|
-
var e,
|
|
89
|
-
return ((
|
|
86
|
+
parseModelsResponse(s) {
|
|
87
|
+
var e, t, r;
|
|
88
|
+
return ((r = (t = (e = s.data) == null ? void 0 : e.filter((n) => String(n.id).toLowerCase().includes("grok"))) == null ? void 0 : t.map((n) => n.id)) == null ? void 0 : r.sort()) || [];
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
function
|
|
91
|
+
function u(a) {
|
|
93
92
|
if (!a) return null;
|
|
94
|
-
const
|
|
95
|
-
return
|
|
93
|
+
const s = String(a).toLowerCase();
|
|
94
|
+
return s === "length" || s === "max_tokens" ? "length" : s;
|
|
96
95
|
}
|
|
97
96
|
function h(a) {
|
|
98
97
|
if (!a) return {};
|
|
@@ -8,18 +8,17 @@ class A extends m {
|
|
|
8
8
|
const t = {
|
|
9
9
|
model: e.model || this.config.model || "llama2",
|
|
10
10
|
messages: g(n),
|
|
11
|
-
temperature: e.temperature ?? 0.7,
|
|
12
11
|
max_tokens: e.maxTokens || 1e3,
|
|
13
12
|
stream: e.stream || !1
|
|
14
13
|
};
|
|
15
|
-
return t.stream && (t.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
|
|
14
|
+
return this.applySamplingParams(t, e), t.stream && (t.stream_options = { include_usage: !0 }), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
|
|
16
15
|
}
|
|
17
16
|
processResponse(n) {
|
|
18
|
-
var r,
|
|
19
|
-
const e = (
|
|
17
|
+
var r, i, o, a;
|
|
18
|
+
const e = (i = (r = n.choices) == null ? void 0 : r[0]) == null ? void 0 : i.message, t = {
|
|
20
19
|
content: (e == null ? void 0 : e.content) || "",
|
|
21
20
|
usage: u(n.usage),
|
|
22
|
-
finishReason: c((a = (
|
|
21
|
+
finishReason: c((a = (o = n.choices) == null ? void 0 : o[0]) == null ? void 0 : a.finish_reason)
|
|
23
22
|
};
|
|
24
23
|
return Array.isArray(e == null ? void 0 : e.tool_calls) && (t.toolCalls = e.tool_calls.map((l) => {
|
|
25
24
|
var d, f;
|
|
@@ -41,7 +40,7 @@ class A extends m {
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
extractStreamingContent(n) {
|
|
44
|
-
var r,
|
|
43
|
+
var r, i, o;
|
|
45
44
|
if (n.done) return { done: !0 };
|
|
46
45
|
const e = (r = n.choices) == null ? void 0 : r[0], t = e == null ? void 0 : e.delta;
|
|
47
46
|
if (t && Array.isArray(t.tool_calls) && t.tool_calls.length) {
|
|
@@ -55,8 +54,8 @@ class A extends m {
|
|
|
55
54
|
toolCallDelta: {
|
|
56
55
|
index: a.index ?? 0,
|
|
57
56
|
id: a.id || void 0,
|
|
58
|
-
name: ((
|
|
59
|
-
argsTextDelta: ((
|
|
57
|
+
name: ((i = a.function) == null ? void 0 : i.name) || void 0,
|
|
58
|
+
argsTextDelta: ((o = a.function) == null ? void 0 : o.arguments) || ""
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
61
|
}
|