@anvaka/vue-llm 0.2.0 → 0.3.1
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/README.md +81 -3
- package/dist/core/LLMClient.js +95 -63
- package/dist/index.js +37 -29
- package/dist/pricing/calculate.js +58 -0
- package/dist/pricing/index.js +10 -0
- package/dist/pricing/rates.js +88 -0
- package/dist/providers/AnthropicProvider.js +139 -85
- package/dist/providers/BaseProvider.js +84 -74
- package/dist/providers/CustomProvider.js +69 -28
- package/dist/providers/DeepSeekProvider.js +115 -0
- package/dist/providers/GeminiProvider.js +143 -111
- package/dist/providers/GrokProvider.js +75 -38
- package/dist/providers/LlamaServerProvider.js +72 -31
- package/dist/providers/OllamaProvider.js +117 -41
- package/dist/providers/OpenAIProvider.js +64 -57
- package/dist/providers/OpenRouterProvider.js +40 -40
- package/dist/providers/factory.js +12 -7
- package/dist/providers/index.js +10 -8
- package/package.json +8 -2
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { BaseProvider as
|
|
2
|
-
import { convertMessagesToOpenAI as
|
|
3
|
-
class y extends
|
|
1
|
+
import { BaseProvider as f } from "./BaseProvider.js";
|
|
2
|
+
import { convertMessagesToOpenAI as g, normalizeOpenAIUsage as c } from "./OpenAIProvider.js";
|
|
3
|
+
class y 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
|
}
|
|
7
|
-
prepareRequest(
|
|
7
|
+
prepareRequest(i, e) {
|
|
8
8
|
const t = {
|
|
9
9
|
model: e.model || this.config.model,
|
|
10
|
-
messages: this.processMessages(
|
|
10
|
+
messages: this.processMessages(i, e),
|
|
11
11
|
temperature: e.temperature ?? 0.7,
|
|
12
12
|
max_tokens: e.maxTokens || 1e3,
|
|
13
13
|
stream: e.stream || !1
|
|
14
14
|
};
|
|
15
|
-
return 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;
|
|
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;
|
|
16
16
|
}
|
|
17
|
-
processMessages(
|
|
18
|
-
const t =
|
|
17
|
+
processMessages(i, e) {
|
|
18
|
+
const t = g(i);
|
|
19
19
|
return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(t, e.images) : t;
|
|
20
20
|
}
|
|
21
|
-
addImagesToMessages(
|
|
22
|
-
const t =
|
|
23
|
-
return t && t.role === "user" && (t.content = [{ type: "text", text: t.content }, ...e.map((
|
|
21
|
+
addImagesToMessages(i, e) {
|
|
22
|
+
const t = i[i.length - 1];
|
|
23
|
+
return t && t.role === "user" && (t.content = [{ type: "text", text: t.content }, ...e.map((n) => ({ type: "image_url", image_url: { url: n } }))]), i;
|
|
24
24
|
}
|
|
25
25
|
buildHeaders() {
|
|
26
|
-
const
|
|
27
|
-
return this.requiresAuth() && (
|
|
26
|
+
const i = { "Content-Type": "application/json" };
|
|
27
|
+
return this.requiresAuth() && (i[this.getAuthHeaderName()] = this.getAuthHeaderValue()), this.config.siteUrl && (i["HTTP-Referer"] = this.config.siteUrl), this.config.siteName && (i["X-Title"] = this.config.siteName), i;
|
|
28
28
|
}
|
|
29
|
-
processResponse(
|
|
30
|
-
var
|
|
31
|
-
const e = (s = (
|
|
29
|
+
processResponse(i) {
|
|
30
|
+
var n, s, o, a;
|
|
31
|
+
const e = (s = (n = i.choices) == null ? void 0 : n[0]) == null ? void 0 : s.message, t = { content: (e == null ? void 0 : e.content) || "", usage: c(i.usage), finishReason: u((a = (o = i.choices) == null ? void 0 : o[0]) == null ? void 0 : a.finish_reason) };
|
|
32
32
|
return e != null && e.reasoning && (t.thinking = e.reasoning), Array.isArray(e == null ? void 0 : e.tool_calls) && (t.toolCalls = e.tool_calls.map((l) => {
|
|
33
|
-
var
|
|
33
|
+
var d, h;
|
|
34
34
|
return {
|
|
35
35
|
id: l.id,
|
|
36
|
-
name: (
|
|
37
|
-
args:
|
|
36
|
+
name: (d = l.function) == null ? void 0 : d.name,
|
|
37
|
+
args: m((h = l.function) == null ? void 0 : h.arguments)
|
|
38
38
|
};
|
|
39
39
|
})), t;
|
|
40
40
|
}
|
|
41
|
-
parseStreamingLine(
|
|
42
|
-
if (!
|
|
43
|
-
const e =
|
|
41
|
+
parseStreamingLine(i) {
|
|
42
|
+
if (!i.startsWith("data: ")) return null;
|
|
43
|
+
const e = i.slice(6).trim();
|
|
44
44
|
if (e === "[DONE]") return { done: !0 };
|
|
45
45
|
try {
|
|
46
46
|
return JSON.parse(e);
|
|
@@ -48,18 +48,18 @@ class y extends h {
|
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
extractStreamingContent(
|
|
52
|
-
var
|
|
53
|
-
if (
|
|
54
|
-
const e = (
|
|
51
|
+
extractStreamingContent(i) {
|
|
52
|
+
var n, s, o;
|
|
53
|
+
if (i.done) return { done: !0 };
|
|
54
|
+
const e = (n = i.choices) == null ? void 0 : n[0], t = e == null ? void 0 : e.delta;
|
|
55
55
|
if (t && Array.isArray(t.tool_calls) && t.tool_calls.length) {
|
|
56
56
|
const a = t.tool_calls[0];
|
|
57
57
|
return {
|
|
58
58
|
content: t.content || "",
|
|
59
59
|
thinking: t.reasoning || "",
|
|
60
60
|
done: !1,
|
|
61
|
-
usage:
|
|
62
|
-
finishReason:
|
|
61
|
+
usage: c(i.usage),
|
|
62
|
+
finishReason: u(e == null ? void 0 : e.finish_reason),
|
|
63
63
|
toolCallDelta: {
|
|
64
64
|
index: a.index ?? 0,
|
|
65
65
|
id: a.id || void 0,
|
|
@@ -68,7 +68,7 @@ class y extends h {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
return { content: (t == null ? void 0 : t.content) || "", thinking: (t == null ? void 0 : t.reasoning) || "", done: !1, usage:
|
|
71
|
+
return { content: (t == null ? void 0 : t.content) || "", thinking: (t == null ? void 0 : t.reasoning) || "", done: !1, usage: c(i.usage), finishReason: u(e == null ? void 0 : e.finish_reason) };
|
|
72
72
|
}
|
|
73
73
|
getApiPath() {
|
|
74
74
|
return "/v1/chat/completions";
|
|
@@ -79,29 +79,29 @@ class y extends h {
|
|
|
79
79
|
getModelsEndpoint() {
|
|
80
80
|
return `${this.config.baseUrl}/v1/models`;
|
|
81
81
|
}
|
|
82
|
-
parseModelsResponse(
|
|
83
|
-
return Array.isArray(
|
|
84
|
-
var
|
|
85
|
-
const t = (
|
|
82
|
+
parseModelsResponse(i) {
|
|
83
|
+
return Array.isArray(i.data) ? i.data.filter((e) => {
|
|
84
|
+
var n;
|
|
85
|
+
const t = (n = e.architecture) == null ? void 0 : n.modality;
|
|
86
86
|
return t && (t.includes("text->text") || t.includes("text+image->text"));
|
|
87
87
|
}).map((e) => e.id).sort() : [];
|
|
88
88
|
}
|
|
89
|
-
async discoverModelsWithMetadata(
|
|
89
|
+
async discoverModelsWithMetadata(i = 15e3) {
|
|
90
90
|
try {
|
|
91
|
-
const e = this.buildHeaders(), t = new AbortController(),
|
|
92
|
-
if (clearTimeout(
|
|
91
|
+
const e = this.buildHeaders(), t = new AbortController(), n = setTimeout(() => t.abort(), i), s = await fetch(this.getModelsEndpoint(), { method: "GET", headers: e, signal: t.signal });
|
|
92
|
+
if (clearTimeout(n), !s.ok) throw new Error(`Failed to fetch models: ${s.status} ${s.statusText}`);
|
|
93
93
|
return (await s.json()).data || [];
|
|
94
94
|
} catch (e) {
|
|
95
95
|
throw e.name === "AbortError" ? new Error("Model discovery timeout - please check your connection") : e;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function u(r) {
|
|
100
100
|
if (!r) return null;
|
|
101
|
-
const
|
|
102
|
-
return
|
|
101
|
+
const i = String(r).toLowerCase();
|
|
102
|
+
return i === "length" || i === "max_tokens" ? "length" : i;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function m(r) {
|
|
105
105
|
if (!r) return {};
|
|
106
106
|
try {
|
|
107
107
|
return JSON.parse(r);
|
|
@@ -4,8 +4,9 @@ import { BedrockProvider as n } from "./BedrockProvider.js";
|
|
|
4
4
|
import { GrokProvider as m } from "./GrokProvider.js";
|
|
5
5
|
import { GeminiProvider as p } from "./GeminiProvider.js";
|
|
6
6
|
import { OllamaProvider as u } from "./OllamaProvider.js";
|
|
7
|
-
import { LlamaServerProvider as
|
|
8
|
-
import { OpenRouterProvider as
|
|
7
|
+
import { LlamaServerProvider as E } from "./LlamaServerProvider.js";
|
|
8
|
+
import { OpenRouterProvider as l } from "./OpenRouterProvider.js";
|
|
9
|
+
import { DeepSeekProvider as A } from "./DeepSeekProvider.js";
|
|
9
10
|
import { CustomProvider as O } from "./CustomProvider.js";
|
|
10
11
|
const e = {
|
|
11
12
|
OPENAI: "openai",
|
|
@@ -16,8 +17,9 @@ const e = {
|
|
|
16
17
|
OLLAMA: "ollama",
|
|
17
18
|
LLAMA_SERVER: "llama-server",
|
|
18
19
|
OPENROUTER: "openrouter",
|
|
20
|
+
DEEPSEEK: "deepseek",
|
|
19
21
|
CUSTOM: "custom"
|
|
20
|
-
},
|
|
22
|
+
}, S = {
|
|
21
23
|
[e.OPENAI]: { name: "OpenAI", baseUrl: "https://api.openai.com", requiresApiKey: !0 },
|
|
22
24
|
[e.ANTHROPIC]: { name: "Anthropic", baseUrl: "https://api.anthropic.com", requiresApiKey: !0 },
|
|
23
25
|
[e.BEDROCK]: { name: "AWS Bedrock", baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com", requiresApiKey: !0 },
|
|
@@ -26,6 +28,7 @@ const e = {
|
|
|
26
28
|
[e.OLLAMA]: { name: "Ollama (Native)", baseUrl: "http://localhost:11434", requiresApiKey: !1 },
|
|
27
29
|
[e.LLAMA_SERVER]: { name: "Local Llama Server", baseUrl: "http://localhost:8080", requiresApiKey: !1 },
|
|
28
30
|
[e.OPENROUTER]: { name: "OpenRouter", baseUrl: "https://openrouter.ai/api", requiresApiKey: !0 },
|
|
31
|
+
[e.DEEPSEEK]: { name: "DeepSeek", baseUrl: "https://api.deepseek.com", requiresApiKey: !0 },
|
|
29
32
|
[e.CUSTOM]: { name: "Custom OpenAI Compatible", baseUrl: "", requiresApiKey: !1 }
|
|
30
33
|
};
|
|
31
34
|
function c(t, r) {
|
|
@@ -43,8 +46,10 @@ function c(t, r) {
|
|
|
43
46
|
case e.OLLAMA:
|
|
44
47
|
return new u(r);
|
|
45
48
|
case e.LLAMA_SERVER:
|
|
46
|
-
return new
|
|
49
|
+
return new E(r);
|
|
47
50
|
case e.OPENROUTER:
|
|
51
|
+
return new l(r);
|
|
52
|
+
case e.DEEPSEEK:
|
|
48
53
|
return new A(r);
|
|
49
54
|
case e.CUSTOM:
|
|
50
55
|
return new O(r);
|
|
@@ -53,7 +58,7 @@ function c(t, r) {
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
const a = /* @__PURE__ */ new Map();
|
|
56
|
-
function
|
|
61
|
+
function b(t, r) {
|
|
57
62
|
if (typeof t != "string" || !r)
|
|
58
63
|
throw new Error("registerProvider requires a type string and a class reference");
|
|
59
64
|
a.set(t, r);
|
|
@@ -66,9 +71,9 @@ function N(t, r) {
|
|
|
66
71
|
return c(t, r);
|
|
67
72
|
}
|
|
68
73
|
export {
|
|
69
|
-
|
|
74
|
+
S as DEFAULT_CONFIGS,
|
|
70
75
|
e as PROVIDERS,
|
|
71
76
|
c as createProvider,
|
|
72
77
|
N as createProviderFlexible,
|
|
73
|
-
|
|
78
|
+
b as registerProvider
|
|
74
79
|
};
|
package/dist/providers/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { BaseProvider as o } from "./BaseProvider.js";
|
|
2
2
|
import { OpenAIProvider as t } from "./OpenAIProvider.js";
|
|
3
|
-
import { AnthropicProvider as
|
|
3
|
+
import { AnthropicProvider as p } from "./AnthropicProvider.js";
|
|
4
4
|
import { BEDROCK_CLAUDE_MODELS as v, BedrockProvider as x } from "./BedrockProvider.js";
|
|
5
|
-
import {
|
|
5
|
+
import { DeepSeekProvider as m } from "./DeepSeekProvider.js";
|
|
6
|
+
import { DEFAULT_CONFIGS as E, PROVIDERS as O, createProvider as c, createProviderFlexible as A, registerProvider as S } from "./factory.js";
|
|
6
7
|
export {
|
|
7
|
-
|
|
8
|
+
p as AnthropicProvider,
|
|
8
9
|
v as BEDROCK_CLAUDE_MODELS,
|
|
9
10
|
o as BaseProvider,
|
|
10
11
|
x as BedrockProvider,
|
|
11
|
-
|
|
12
|
+
E as DEFAULT_CONFIGS,
|
|
13
|
+
m as DeepSeekProvider,
|
|
12
14
|
t as OpenAIProvider,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
O as PROVIDERS,
|
|
16
|
+
c as createProvider,
|
|
17
|
+
A as createProviderFlexible,
|
|
18
|
+
S as registerProvider
|
|
17
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anvaka/vue-llm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Browser-only LLM client with provider adapters and Vue 3 components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"module": "dist/index.js",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "vite build",
|
|
11
|
-
"dev": "vite build --watch"
|
|
11
|
+
"dev": "vite build --watch",
|
|
12
|
+
"test:providers": "node test/providers.mjs",
|
|
13
|
+
"test:caching": "node test/caching.mjs"
|
|
12
14
|
},
|
|
13
15
|
"exports": {
|
|
14
16
|
".": {
|
|
@@ -23,6 +25,10 @@
|
|
|
23
25
|
"import": "./dist/providers/index.js",
|
|
24
26
|
"default": "./dist/providers/index.js"
|
|
25
27
|
},
|
|
28
|
+
"./pricing": {
|
|
29
|
+
"import": "./dist/pricing/index.js",
|
|
30
|
+
"default": "./dist/pricing/index.js"
|
|
31
|
+
},
|
|
26
32
|
"./styles/variables.css": "./src/styles/variables.css",
|
|
27
33
|
"./styles/components.css": "./src/styles/components.css",
|
|
28
34
|
"./dist/vue-llm.css": "./dist/vue-llm.css"
|