@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,99 +1,99 @@
|
|
|
1
|
-
var
|
|
1
|
+
var p = (s) => {
|
|
2
2
|
throw TypeError(s);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var m = (s, o,
|
|
7
|
-
import { BaseProvider as
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
var y = (s, o, e) => o.has(s) || p("Cannot " + e);
|
|
5
|
+
var h = (s, o, e) => o.has(s) ? p("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(s) : o.set(s, e);
|
|
6
|
+
var m = (s, o, e) => (y(s, o, "access private method"), e);
|
|
7
|
+
import { BaseProvider as A } from "./BaseProvider.js";
|
|
8
|
+
import { isOpenAIReasoningModel as _ } from "./samplingPolicy.js";
|
|
9
|
+
var u, k;
|
|
10
|
+
class C extends A {
|
|
10
11
|
constructor() {
|
|
11
12
|
super(...arguments);
|
|
12
|
-
|
|
13
|
+
h(this, u);
|
|
13
14
|
}
|
|
14
15
|
async detectCapabilities() {
|
|
15
16
|
if (!this.config.model) return;
|
|
16
|
-
const
|
|
17
|
-
(
|
|
17
|
+
const e = this.config.model.toLowerCase();
|
|
18
|
+
_(e) && this.capabilities.add("thinking"), e.includes("gpt-4") && e.includes("vision") && this.capabilities.add("vision"), (e.includes("gpt-4") || e.includes("gpt-3.5") || e.includes("gpt-5")) && this.capabilities.add("tools");
|
|
18
19
|
}
|
|
19
|
-
prepareRequest(
|
|
20
|
-
const
|
|
21
|
-
model:
|
|
22
|
-
messages: this.processMessages(
|
|
23
|
-
|
|
24
|
-
stream: e.stream || !1
|
|
20
|
+
prepareRequest(e, n) {
|
|
21
|
+
const t = n.model || this.config.model || "gpt-3.5-turbo", i = {
|
|
22
|
+
model: t,
|
|
23
|
+
messages: this.processMessages(e, n),
|
|
24
|
+
stream: n.stream || !1
|
|
25
25
|
};
|
|
26
|
-
return i.stream && (i.stream_options = { include_usage: !0 }), m(this, u,
|
|
26
|
+
return i.stream && (i.stream_options = { include_usage: !0 }), m(this, u, k).call(this, t) ? i.max_completion_tokens = n.maxTokens || 1e3 : i.max_tokens = n.maxTokens || 1e3, this.applySamplingParams(i, n), n.enableThinking && this.capabilities.has("thinking") && (i.reasoning_effort = n.reasoningEffort || "medium"), n.tools && this.capabilities.has("tools") && (i.tools = n.tools), i;
|
|
27
27
|
}
|
|
28
|
-
processMessages(
|
|
29
|
-
const
|
|
30
|
-
return
|
|
28
|
+
processMessages(e, n) {
|
|
29
|
+
const t = b(e);
|
|
30
|
+
return n.images && this.capabilities.has("vision") ? this.addImagesToMessages(t, n.images) : t;
|
|
31
31
|
}
|
|
32
|
-
addImagesToMessages(
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const i = [{ type: "text", text:
|
|
36
|
-
|
|
32
|
+
addImagesToMessages(e, n) {
|
|
33
|
+
const t = e[e.length - 1];
|
|
34
|
+
if (t && t.role === "user") {
|
|
35
|
+
const i = [{ type: "text", text: t.content }];
|
|
36
|
+
n.forEach((a) => {
|
|
37
37
|
i.push({
|
|
38
38
|
type: "image_url",
|
|
39
|
-
image_url: { url: typeof
|
|
39
|
+
image_url: { url: typeof a == "string" ? a : a.url }
|
|
40
40
|
});
|
|
41
|
-
}),
|
|
41
|
+
}), t.content = i;
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return e;
|
|
44
44
|
}
|
|
45
|
-
processResponse(
|
|
46
|
-
var i,
|
|
47
|
-
const
|
|
48
|
-
content: (
|
|
49
|
-
usage: g(
|
|
50
|
-
finishReason: ((
|
|
45
|
+
processResponse(e) {
|
|
46
|
+
var i, a, l, r;
|
|
47
|
+
const n = (a = (i = e.choices) == null ? void 0 : i[0]) == null ? void 0 : a.message, t = {
|
|
48
|
+
content: (n == null ? void 0 : n.content) || "",
|
|
49
|
+
usage: g(e.usage),
|
|
50
|
+
finishReason: ((r = (l = e.choices) == null ? void 0 : l[0]) == null ? void 0 : r.finish_reason) || null
|
|
51
51
|
};
|
|
52
|
-
return
|
|
52
|
+
return e.reasoning && (t.thinking = e.reasoning), Array.isArray(n == null ? void 0 : n.tool_calls) && (t.toolCalls = n.tool_calls.map((c) => {
|
|
53
53
|
var d, f;
|
|
54
54
|
return {
|
|
55
55
|
id: c.id,
|
|
56
56
|
name: (d = c.function) == null ? void 0 : d.name,
|
|
57
57
|
args: T((f = c.function) == null ? void 0 : f.arguments)
|
|
58
58
|
};
|
|
59
|
-
})),
|
|
59
|
+
})), t;
|
|
60
60
|
}
|
|
61
|
-
parseStreamingLine(
|
|
62
|
-
if (!
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
61
|
+
parseStreamingLine(e) {
|
|
62
|
+
if (!e.startsWith("data: ")) return null;
|
|
63
|
+
const n = e.slice(6).trim();
|
|
64
|
+
if (n === "[DONE]") return { done: !0 };
|
|
65
65
|
try {
|
|
66
|
-
return JSON.parse(
|
|
66
|
+
return JSON.parse(n);
|
|
67
67
|
} catch {
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
extractStreamingContent(
|
|
72
|
-
var i,
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
71
|
+
extractStreamingContent(e) {
|
|
72
|
+
var i, a, l;
|
|
73
|
+
if (e.done) return { done: !0 };
|
|
74
|
+
const n = (i = e.choices) == null ? void 0 : i[0], t = n == null ? void 0 : n.delta;
|
|
75
|
+
if (t && Array.isArray(t.tool_calls) && t.tool_calls.length) {
|
|
76
|
+
const r = t.tool_calls[0];
|
|
77
77
|
return {
|
|
78
|
-
content:
|
|
79
|
-
thinking:
|
|
78
|
+
content: t.content || "",
|
|
79
|
+
thinking: t.reasoning || "",
|
|
80
80
|
done: !1,
|
|
81
|
-
usage: g(
|
|
82
|
-
finishReason: (
|
|
81
|
+
usage: g(e.usage),
|
|
82
|
+
finishReason: (n == null ? void 0 : n.finish_reason) || null,
|
|
83
83
|
toolCallDelta: {
|
|
84
|
-
index:
|
|
85
|
-
id:
|
|
86
|
-
name: ((
|
|
87
|
-
argsTextDelta: ((l =
|
|
84
|
+
index: r.index ?? 0,
|
|
85
|
+
id: r.id || void 0,
|
|
86
|
+
name: ((a = r.function) == null ? void 0 : a.name) || void 0,
|
|
87
|
+
argsTextDelta: ((l = r.function) == null ? void 0 : l.arguments) || ""
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
|
-
content: (
|
|
93
|
-
thinking: (
|
|
92
|
+
content: (t == null ? void 0 : t.content) || "",
|
|
93
|
+
thinking: (t == null ? void 0 : t.reasoning) || "",
|
|
94
94
|
done: !1,
|
|
95
|
-
usage: g(
|
|
96
|
-
finishReason: (
|
|
95
|
+
usage: g(e.usage),
|
|
96
|
+
finishReason: (n == null ? void 0 : n.finish_reason) || null
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
getApiPath() {
|
|
@@ -105,17 +105,17 @@ class v extends y {
|
|
|
105
105
|
getModelsEndpoint() {
|
|
106
106
|
return `${this.config.baseUrl}/v1/models`;
|
|
107
107
|
}
|
|
108
|
-
parseModelsResponse(
|
|
109
|
-
var
|
|
110
|
-
return ((
|
|
111
|
-
const i =
|
|
108
|
+
parseModelsResponse(e) {
|
|
109
|
+
var n;
|
|
110
|
+
return ((n = e.data) == null ? void 0 : n.filter((t) => {
|
|
111
|
+
const i = t.id.toLowerCase();
|
|
112
112
|
return i.includes("gpt") || i.includes("chat");
|
|
113
|
-
}).map((
|
|
113
|
+
}).map((t) => t.id).sort()) || [];
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
u = new WeakSet(),
|
|
117
|
-
const
|
|
118
|
-
return
|
|
116
|
+
u = new WeakSet(), k = function(e) {
|
|
117
|
+
const n = (e || "").toLowerCase();
|
|
118
|
+
return _(n) || n.includes("gpt-5") || this.capabilities.has("thinking");
|
|
119
119
|
};
|
|
120
120
|
function T(s) {
|
|
121
121
|
if (!s) return {};
|
|
@@ -126,27 +126,27 @@ function T(s) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
function g(s) {
|
|
129
|
-
var l,
|
|
129
|
+
var l, r;
|
|
130
130
|
if (!s) return null;
|
|
131
|
-
const o = s.prompt_tokens ?? 0,
|
|
132
|
-
return
|
|
131
|
+
const o = s.prompt_tokens ?? 0, e = s.completion_tokens ?? 0, n = s.total_tokens ?? o + e, t = (l = s.prompt_tokens_details) == null ? void 0 : l.cached_tokens, i = (r = s.completion_tokens_details) == null ? void 0 : r.reasoning_tokens, a = { inputTokens: o, outputTokens: e, totalTokens: n, raw: s };
|
|
132
|
+
return t != null && (a.cachedInputTokens = t), i != null && (a.reasoningTokens = i), a;
|
|
133
133
|
}
|
|
134
|
-
function
|
|
134
|
+
function b(s) {
|
|
135
135
|
return s.map((o) => o.role === "assistant" && Array.isArray(o.tool_calls) && o.tool_calls.length ? {
|
|
136
136
|
role: "assistant",
|
|
137
137
|
content: o.content ?? null,
|
|
138
|
-
tool_calls: o.tool_calls.map((
|
|
139
|
-
id:
|
|
138
|
+
tool_calls: o.tool_calls.map((e) => ({
|
|
139
|
+
id: e.id,
|
|
140
140
|
type: "function",
|
|
141
141
|
function: {
|
|
142
|
-
name:
|
|
143
|
-
arguments: typeof
|
|
142
|
+
name: e.name,
|
|
143
|
+
arguments: typeof e.args == "string" ? e.args : JSON.stringify(e.args || {})
|
|
144
144
|
}
|
|
145
145
|
}))
|
|
146
146
|
} : o);
|
|
147
147
|
}
|
|
148
148
|
export {
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
C as OpenAIProvider,
|
|
150
|
+
b as convertMessagesToOpenAI,
|
|
151
151
|
g as normalizeOpenAIUsage
|
|
152
152
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseProvider as f } from "./BaseProvider.js";
|
|
2
2
|
import { convertMessagesToOpenAI as g, normalizeOpenAIUsage as c } from "./OpenAIProvider.js";
|
|
3
|
-
class
|
|
3
|
+
class _ extends f {
|
|
4
4
|
async detectCapabilities() {
|
|
5
5
|
this.config.model && (this.capabilities.add("tools"), (this.config.model.includes("o1") || this.config.model.includes("thinking") || this.config.model.includes("reasoning")) && this.capabilities.add("thinking"), (this.config.model.includes("vision") || this.config.model.includes("gpt-4") || this.config.model.includes("claude") || this.config.model.includes("gemini")) && this.capabilities.add("vision"));
|
|
6
6
|
}
|
|
@@ -8,11 +8,10 @@ class y extends f {
|
|
|
8
8
|
const t = {
|
|
9
9
|
model: e.model || this.config.model,
|
|
10
10
|
messages: this.processMessages(i, e),
|
|
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.enableThinking && this.capabilities.has("thinking") && (t.reasoning = e.reasoning !== !1, e.reasoningEffort && (t.reasoning_effort = e.reasoningEffort)), 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.enableThinking && this.capabilities.has("thinking") && (t.reasoning = e.reasoning !== !1, e.reasoningEffort && (t.reasoning_effort = e.reasoningEffort)), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
|
|
16
15
|
}
|
|
17
16
|
processMessages(i, e) {
|
|
18
17
|
const t = g(i);
|
|
@@ -110,5 +109,5 @@ function m(r) {
|
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
export {
|
|
113
|
-
|
|
112
|
+
_ as OpenRouterProvider
|
|
114
113
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const n = { PASS: "pass", OMIT: "omit", ONE: "one" }, r = /* @__PURE__ */ new Map();
|
|
2
|
+
function l(e, t) {
|
|
3
|
+
return `${e || ""}::${t || ""}`;
|
|
4
|
+
}
|
|
5
|
+
function c(e, t) {
|
|
6
|
+
e && (t === n.OMIT || t === n.ONE) && r.set(e, t);
|
|
7
|
+
}
|
|
8
|
+
function p(e, t) {
|
|
9
|
+
return r.get(e) || i(t);
|
|
10
|
+
}
|
|
11
|
+
function i(e) {
|
|
12
|
+
const t = String(e || "");
|
|
13
|
+
return s(t) ? n.OMIT : a(t) ? n.ONE : n.PASS;
|
|
14
|
+
}
|
|
15
|
+
function s(e) {
|
|
16
|
+
const t = e || "";
|
|
17
|
+
return /claude-opus-4[-.][789]/.test(t) || /claude-(sonnet|opus|haiku|fable)-5(?!\d)/.test(t);
|
|
18
|
+
}
|
|
19
|
+
function u(e) {
|
|
20
|
+
const t = String(e || "").toLowerCase();
|
|
21
|
+
return /(?:^|\/)o[1-9](?:[-.]|$)/.test(t) || t.includes("gpt-5") && !t.includes("gpt-5-chat") ? !0 : t === "gpt5" || t.includes("reasoning");
|
|
22
|
+
}
|
|
23
|
+
function a(e) {
|
|
24
|
+
const t = String(e || "").toLowerCase(), o = /kimi|moonshot/.test(t);
|
|
25
|
+
return u(t) || o;
|
|
26
|
+
}
|
|
27
|
+
function d(e) {
|
|
28
|
+
const t = String(e || "").toLowerCase();
|
|
29
|
+
return t.includes("temperature") ? /\bonly\s*1\b|\bmust be (?:exactly )?1\b|\bmust equal 1\b|\bequal to 1\b|\bset to 1\b/.test(t) ? n.ONE : /deprecat|unsupported|not support|no longer|isn'?t allowed|not allowed|not permitted|unexpected (?:parameter|field)|invalid parameter/.test(t) ? n.OMIT : null : null;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
n as SAMPLING_MODE,
|
|
33
|
+
d as classifyTemperatureError,
|
|
34
|
+
a as isFixedTemperatureModel,
|
|
35
|
+
u as isOpenAIReasoningModel,
|
|
36
|
+
c as recordSamplingConstraint,
|
|
37
|
+
l as samplingKey,
|
|
38
|
+
p as samplingModeFor,
|
|
39
|
+
s as samplingParamsRemoved,
|
|
40
|
+
i as staticSamplingMode
|
|
41
|
+
};
|