huxy-llm-api 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +47 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huxy-llm-api",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "一个简洁、易用的用于简化 Ollama 和 OpenAI API 调用的 Node.js 库。",
5
5
  "type": "module",
6
6
  "module": "./src/index.js",
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "ollama": "^0.6.3",
38
38
  "openai": "^6.15.0",
39
- "undici": "^7.16.0"
39
+ "undici": "^7.18.2"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=20.0.0"
package/src/index.js CHANGED
@@ -9,113 +9,113 @@ var T = {
9
9
  params: {model: 'qwen3-vl:latest', temperature: 1, max_tokens: 4096, top_p: 0.95},
10
10
  options: {top_k: 20, repeat_penalty: 1.05, thinking: !0},
11
11
  },
12
- A = T;
12
+ P = T;
13
13
  var b = {
14
14
  config: {apiKey: process.env.OLLM_API_KEY || 'ah.yiru@gmail.com', host: process.env.OLLM_API_HOST || 'http://127.0.0.1:11434'},
15
15
  params: {model: 'qwen3-vl:latest', keep_alive: -1},
16
16
  options: {temperature: 1, num_ctx: 4096, top_k: 20, top_p: 0.95, repeat_penalty: 1.05},
17
17
  },
18
- I = b;
18
+ A = b;
19
19
  var q = ['response.reasoning_text.delta', 'response.reasoning_summary_text.delta'],
20
- P = async (t, a, s) => {
20
+ I = async (t, a, o) => {
21
21
  if (a) {
22
22
  let r = '',
23
23
  e = '';
24
24
  for await (let n of t) {
25
- let {type: o, delta: i} = n;
26
- (q.includes(o) && (e += i), o === 'response.output_text.delta' && (r += i), s?.({content: r, reasoning: e}, n));
25
+ let {type: s, delta: i} = n;
26
+ (q.includes(s) && (e += i), s === 'response.output_text.delta' && (r += i), o?.({content: r, reasoning: e}, n));
27
27
  }
28
28
  return {content: r, reasoning: e};
29
29
  }
30
- return (s?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
30
+ return (o?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
31
31
  },
32
- C = async (t, a, s) => {
32
+ C = async (t, a, o) => {
33
33
  if (a) {
34
34
  let n = '',
35
- o = '';
35
+ s = '';
36
36
  for await (let i of t) {
37
37
  let {delta: p} = i.choices?.[0] ?? {},
38
38
  {reasoning: l, content: u} = p ?? {};
39
- (l && (o += l), u && (n += u), s?.({content: n, reasoning: o}, i));
39
+ (l && (s += l), u && (n += u), o?.({content: n, reasoning: s}, i));
40
40
  }
41
- return {content: n, reasoning: o};
41
+ return {content: n, reasoning: s};
42
42
  }
43
- s?.(t);
43
+ o?.(t);
44
44
  let {message: c} = t.choices?.[0] ?? {},
45
45
  {content: r, reasoning: e} = c;
46
46
  return {content: r, reasoning: e};
47
47
  };
48
48
  var S = ['response.reasoning_text.delta', 'response.reasoning_summary_text.delta'],
49
- k = async (t, a, s) => {
49
+ O = async (t, a, o) => {
50
50
  if (a) {
51
51
  let r = '',
52
52
  e = '';
53
53
  for await (let n of t) {
54
- let {type: o, delta: i} = n;
55
- (S.includes(o) && (e += i), o === 'response.output_text.delta' && (r += i), s?.({content: r, reasoning: e}, n));
54
+ let {type: s, delta: i} = n;
55
+ (S.includes(s) && (e += i), s === 'response.output_text.delta' && (r += i), o?.({content: r, reasoning: e}, n));
56
56
  }
57
57
  return {content: r, reasoning: e};
58
58
  }
59
- return (s?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
59
+ return (o?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
60
60
  },
61
- v = async (t, a, s) => {
61
+ k = async (t, a, o) => {
62
62
  if (a) {
63
63
  let e = '',
64
64
  n = '';
65
- for await (let o of t) {
66
- let i = o.reasoning ?? o.thinking,
67
- p = o.content ?? o.response;
68
- (i && (n += i), p && (e += p), s?.({content: e, reasoning: n}, o));
65
+ for await (let s of t) {
66
+ let i = s.reasoning ?? s.thinking,
67
+ p = s.content ?? s.response;
68
+ (i && (n += i), p && (e += p), o?.({content: e, reasoning: n}, s));
69
69
  }
70
70
  return {content: e, reasoning: n};
71
71
  }
72
- s?.(t);
72
+ o?.(t);
73
73
  let c = t.reasoning ?? t.thinking;
74
74
  return {content: t.content ?? t.response, reasoning: c};
75
75
  },
76
- O = async (t, a, s) => {
76
+ v = async (t, a, o) => {
77
77
  if (a) {
78
78
  let n = '',
79
- o = '';
79
+ s = '';
80
80
  for await (let i of t) {
81
81
  let {message: p} = i,
82
82
  l = p.reasoning ?? p.thinking,
83
83
  u = p.content ?? p.response;
84
- (l && (o += l), u && (n += u), s?.({content: n, reasoning: o}, i));
84
+ (l && (s += l), u && (n += u), o?.({content: n, reasoning: s}, i));
85
85
  }
86
- return {content: n, reasoning: o};
86
+ return {content: n, reasoning: s};
87
87
  }
88
88
  let {message: c} = t;
89
- s?.(t);
89
+ o?.(t);
90
90
  let r = c.reasoning ?? c.thinking;
91
91
  return {content: c.content ?? c.response, reasoning: r};
92
92
  };
93
- var B = (t, a = {}, s = 'chat') => {
93
+ var B = (t, a = {}, o = 'chat') => {
94
94
  if (!t) throw Error('\u8BF7\u4F20\u5165\u4F60\u7684 prompt !');
95
- if (s === 'chat') {
95
+ if (o === 'chat') {
96
96
  let r = Array.isArray(t) ? t : [{role: 'user', content: t}],
97
97
  {system: e, ...n} = a;
98
98
  return (e && (r = [{role: 'system', content: e}, ...r]), {messages: r, ...n});
99
99
  }
100
- if (s === 'responses') {
100
+ if (o === 'responses') {
101
101
  let {instructions: r, system: e, ...n} = a;
102
102
  return (r || (n.instructions = e), {input: t, ...n});
103
103
  }
104
104
  return {prompt: Array.isArray(t) ? t.slice(-1)[0]?.content : t, ...a};
105
105
  };
106
106
  var w =
107
- (t = {}, a) =>
108
- (s, c, r) => {
109
- let {options: e, ...n} = B(s, c, r),
110
- o = {...t.params, ...n},
111
- i = {...t.options, ...e};
112
- return (a === 'openai' ? (o.extra_body = i) : (o.options = i), o);
107
+ ({params: t, options: a} = {}, o) =>
108
+ (c, r = {}, e) => {
109
+ let {options: n, ...s} = r,
110
+ i = B(c, {...t, ...s}, e),
111
+ p = {...a, ...n};
112
+ return (o === 'openai' ? (i.extra_body = p) : (i.options = p), i);
113
113
  };
114
114
  var L = {
115
115
  openai: (t = {}, a = {}) => {
116
- let {config: s, params: c, options: r} = A,
117
- {host: e, baseURL: n, ...o} = t,
118
- i = new j({fetch: R, ...s, ...o, baseURL: e || n}),
116
+ let {config: o, params: c, options: r} = P,
117
+ {host: e, baseURL: n, ...s} = t,
118
+ i = new j({fetch: R, ...o, ...s, baseURL: e || n}),
119
119
  {options: p, extra_body: l, ...u} = a,
120
120
  h = {params: {...c, ...u}, options: {...r, ...l, ...p}},
121
121
  x = w(h, 'openai');
@@ -128,40 +128,40 @@ var L = {
128
128
  },
129
129
  responses: async (m, f = {}, g) => {
130
130
  let y = x(m, f, 'responses'),
131
- _ = P,
131
+ _ = I,
132
132
  d = await i.responses.create(y);
133
133
  return _(d, y.stream, g);
134
134
  },
135
135
  };
136
136
  },
137
137
  ollama: (t = {}, a = {}) => {
138
- let {config: s, params: c, options: r} = I,
139
- e = new H({fetch: R, ...s, ...t}),
140
- {options: n, extra_body: o, ...i} = a,
141
- p = {params: {...c, ...i}, options: {...r, ...o, ...n}},
138
+ let {config: o, params: c, options: r} = A,
139
+ e = new H({fetch: R, ...o, ...t}),
140
+ {options: n, extra_body: s, ...i} = a,
141
+ p = {params: {...c, ...i}, options: {...r, ...s, ...n}},
142
142
  l = w(p, 'ollama');
143
143
  return {
144
144
  chat: async (u, h = {}, x) => {
145
145
  let m = l(u, h, 'chat'),
146
- f = O,
146
+ f = v,
147
147
  g = await e.chat(m);
148
148
  return f(g, m.stream, x);
149
149
  },
150
150
  generate: async (u, h = {}, x) => {
151
151
  let m = l(u, h, 'generate'),
152
- f = v,
152
+ f = k,
153
153
  g = await e.generate(m);
154
154
  return f(g, m.stream, x);
155
155
  },
156
156
  responses: async (u, h = {}, x) => {
157
157
  let m = l(u, h, 'responses'),
158
- f = k,
158
+ f = O,
159
159
  g = await e.responses(m);
160
160
  return f(g, m.stream, x);
161
161
  },
162
162
  };
163
163
  },
164
164
  };
165
- var z = (t = 'ollama', a, s) => (L[t] ?? L.ollama)(a, s),
165
+ var z = (t = 'ollama', a, o) => (L[t] ?? L.ollama)(a, o),
166
166
  ot = z;
167
167
  export {ot as default, z as startApi};