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