huxy-llm-api 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/index.js +65 -65
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -17,124 +17,124 @@ var q = {
|
|
|
17
17
|
},
|
|
18
18
|
I = q;
|
|
19
19
|
var F = ['response.reasoning_text.delta', 'response.reasoning_summary_text.delta'],
|
|
20
|
-
C = async (t, r,
|
|
20
|
+
C = async (t, r, e) => {
|
|
21
21
|
if (r) {
|
|
22
|
-
let
|
|
22
|
+
let o = '',
|
|
23
23
|
n = '';
|
|
24
|
-
for await (let
|
|
25
|
-
let {type: a, delta:
|
|
26
|
-
(F.includes(a) && (n +=
|
|
24
|
+
for await (let s of t) {
|
|
25
|
+
let {type: a, delta: i} = s;
|
|
26
|
+
(F.includes(a) && (n += i), a === 'response.output_text.delta' && (o += i), e?.({content: o, reasoning: n}, s));
|
|
27
27
|
}
|
|
28
|
-
return {content:
|
|
28
|
+
return {content: o, reasoning: n};
|
|
29
29
|
}
|
|
30
|
-
return (
|
|
30
|
+
return (e?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
|
|
31
31
|
},
|
|
32
|
-
P = async (t, r,
|
|
32
|
+
P = async (t, r, e) => {
|
|
33
33
|
if (r) {
|
|
34
|
-
let
|
|
34
|
+
let s = '',
|
|
35
35
|
a = '';
|
|
36
|
-
for await (let
|
|
37
|
-
let {delta: p} =
|
|
36
|
+
for await (let i of t) {
|
|
37
|
+
let {delta: p} = i.choices?.[0] ?? {},
|
|
38
38
|
{reasoning: u, content: m} = p ?? {};
|
|
39
|
-
(u && (a += u), m && (
|
|
39
|
+
(u && (a += u), m && (s += m), e?.({content: s, reasoning: a}, i));
|
|
40
40
|
}
|
|
41
|
-
return {content:
|
|
41
|
+
return {content: s, reasoning: a};
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
let {message:
|
|
45
|
-
{content:
|
|
46
|
-
return {content:
|
|
43
|
+
e?.(t);
|
|
44
|
+
let {message: c} = t.choices?.[0] ?? {},
|
|
45
|
+
{content: o, reasoning: n} = c;
|
|
46
|
+
return {content: o, reasoning: n};
|
|
47
47
|
};
|
|
48
48
|
var Y = ['response.reasoning_text.delta', 'response.reasoning_summary_text.delta'],
|
|
49
|
-
k = async (t, r,
|
|
49
|
+
k = async (t, r, e) => {
|
|
50
50
|
if (r) {
|
|
51
|
-
let
|
|
51
|
+
let o = '',
|
|
52
52
|
n = '';
|
|
53
|
-
for await (let
|
|
54
|
-
let {type: a, delta:
|
|
55
|
-
(Y.includes(a) && (n +=
|
|
53
|
+
for await (let s of t) {
|
|
54
|
+
let {type: a, delta: i} = s;
|
|
55
|
+
(Y.includes(a) && (n += i), a === 'response.output_text.delta' && (o += i), e?.({content: o, reasoning: n}, s));
|
|
56
56
|
}
|
|
57
|
-
return {content:
|
|
57
|
+
return {content: o, reasoning: n};
|
|
58
58
|
}
|
|
59
|
-
return (
|
|
59
|
+
return (e?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
|
|
60
60
|
},
|
|
61
|
-
v = async (t, r,
|
|
61
|
+
v = async (t, r, e) => {
|
|
62
62
|
if (r) {
|
|
63
63
|
let n = '',
|
|
64
|
-
|
|
64
|
+
s = '';
|
|
65
65
|
for await (let a of t) {
|
|
66
|
-
let
|
|
66
|
+
let i = a.reasoning ?? a.thinking,
|
|
67
67
|
p = a.content ?? a.response;
|
|
68
|
-
(
|
|
68
|
+
(i && (s += i), p && (n += p), e?.({content: n, reasoning: s}, a));
|
|
69
69
|
}
|
|
70
|
-
return {content: n, reasoning:
|
|
70
|
+
return {content: n, reasoning: s};
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
let
|
|
74
|
-
return {content: t.content ?? t.response, reasoning:
|
|
72
|
+
e?.(t);
|
|
73
|
+
let c = t.reasoning ?? t.thinking;
|
|
74
|
+
return {content: t.content ?? t.response, reasoning: c};
|
|
75
75
|
},
|
|
76
|
-
O = async (t, r,
|
|
76
|
+
O = async (t, r, e) => {
|
|
77
77
|
if (r) {
|
|
78
|
-
let
|
|
78
|
+
let s = '',
|
|
79
79
|
a = '';
|
|
80
|
-
for await (let
|
|
81
|
-
let {message: p} =
|
|
80
|
+
for await (let i of t) {
|
|
81
|
+
let {message: p} = i,
|
|
82
82
|
u = p.reasoning ?? p.thinking,
|
|
83
83
|
m = p.content ?? p.response;
|
|
84
|
-
(u && (a += u), m && (
|
|
84
|
+
(u && (a += u), m && (s += m), e?.({content: s, reasoning: a}, i));
|
|
85
85
|
}
|
|
86
|
-
return {content:
|
|
86
|
+
return {content: s, reasoning: a};
|
|
87
87
|
}
|
|
88
|
-
let {message:
|
|
89
|
-
|
|
90
|
-
let
|
|
91
|
-
return {content:
|
|
88
|
+
let {message: c} = t;
|
|
89
|
+
e?.(t);
|
|
90
|
+
let o = c.reasoning ?? c.thinking;
|
|
91
|
+
return {content: c.content ?? c.response, reasoning: o};
|
|
92
92
|
};
|
|
93
|
-
var x = (t, r = {},
|
|
93
|
+
var x = (t, r = {}, e = 'chat') => {
|
|
94
94
|
if (!t) throw Error('\u8BF7\u4F20\u5165\u4F60\u7684 prompt !');
|
|
95
|
-
if (
|
|
96
|
-
let
|
|
97
|
-
{system: n, ...
|
|
98
|
-
return (n && (
|
|
95
|
+
if (e === 'chat') {
|
|
96
|
+
let o = Array.isArray(t) ? t : [{role: 'user', content: t}],
|
|
97
|
+
{system: n, ...s} = r;
|
|
98
|
+
return (n && (o = [{role: 'system', content: n}, ...o]), {messages: o, ...s});
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
101
|
-
let {instructions:
|
|
102
|
-
return (
|
|
100
|
+
if (e === 'responses') {
|
|
101
|
+
let {instructions: o, system: n, ...s} = r;
|
|
102
|
+
return (o || (s.instructions = n), {input: t, ...s});
|
|
103
103
|
}
|
|
104
104
|
return {prompt: Array.isArray(t) ? t.slice(-1)[0]?.content : t, ...r};
|
|
105
105
|
},
|
|
106
|
-
y = ({options: t,
|
|
107
|
-
let
|
|
108
|
-
|
|
109
|
-
return (
|
|
106
|
+
y = ({options: t, ...r}, e = {}, c) => {
|
|
107
|
+
let o = {...e.params, ...r},
|
|
108
|
+
n = {...e.options, ...t};
|
|
109
|
+
return (c === 'openai' ? (o.extra_body = n) : (o.options = n), o);
|
|
110
110
|
};
|
|
111
111
|
var L = {
|
|
112
112
|
openai: (t = {}, r = {}) => {
|
|
113
|
-
let {config:
|
|
114
|
-
{host: n, baseURL:
|
|
115
|
-
|
|
113
|
+
let {config: e, params: c, options: o} = A,
|
|
114
|
+
{host: n, baseURL: s, ...a} = t,
|
|
115
|
+
i = new H({fetch: w, ...e, ...a, baseURL: n || s}),
|
|
116
116
|
{options: p, extra_body: u, ...m} = r,
|
|
117
|
-
h = {...
|
|
117
|
+
h = {params: {...c, ...m}, options: {...o, ...u, ...p}};
|
|
118
118
|
return {
|
|
119
119
|
chat: async (f, l = {}, g) => {
|
|
120
120
|
let d = P,
|
|
121
121
|
_ = x(f, l, 'chat'),
|
|
122
|
-
R = await
|
|
122
|
+
R = await i.chat.completions.create(y(_, h, 'openai'));
|
|
123
123
|
return d(R, _.stream, g);
|
|
124
124
|
},
|
|
125
125
|
responses: async (f, l = {}, g) => {
|
|
126
126
|
let d = C,
|
|
127
127
|
_ = x(f, l, 'responses'),
|
|
128
|
-
R = await
|
|
128
|
+
R = await i.responses.create(y(_, h, 'openai'));
|
|
129
129
|
return d(R, _.stream, g);
|
|
130
130
|
},
|
|
131
131
|
};
|
|
132
132
|
},
|
|
133
133
|
ollama: (t = {}, r = {}) => {
|
|
134
|
-
let {config:
|
|
135
|
-
n = new B({fetch: w, ...
|
|
136
|
-
{options:
|
|
137
|
-
p = {...
|
|
134
|
+
let {config: e, params: c, options: o} = I,
|
|
135
|
+
n = new B({fetch: w, ...e, ...t}),
|
|
136
|
+
{options: s, extra_body: a, ...i} = r,
|
|
137
|
+
p = {params: {...c, ...i}, options: {...o, ...a, ...s}};
|
|
138
138
|
return {
|
|
139
139
|
chat: async (u, m = {}, h) => {
|
|
140
140
|
let f = O,
|
|
@@ -157,6 +157,6 @@ var L = {
|
|
|
157
157
|
};
|
|
158
158
|
},
|
|
159
159
|
};
|
|
160
|
-
var j = (t = 'ollama', r,
|
|
160
|
+
var j = (t = 'ollama', r, e) => (L[t] ?? L.ollama)(r, e),
|
|
161
161
|
et = j;
|
|
162
162
|
export {et as default, j as startApi};
|