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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +65 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huxy-llm-api",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "一个简洁、易用的用于简化 Ollama 和 OpenAI API 调用的 Node.js 库。",
5
5
  "type": "module",
6
6
  "module": "./src/index.js",
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, o) => {
20
+ C = async (t, r, e) => {
21
21
  if (r) {
22
- let s = '',
22
+ let o = '',
23
23
  n = '';
24
- for await (let e of t) {
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));
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: s, reasoning: n};
28
+ return {content: o, reasoning: n};
29
29
  }
30
- return (o?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
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, o) => {
32
+ P = async (t, r, e) => {
33
33
  if (r) {
34
- let e = '',
34
+ let s = '',
35
35
  a = '';
36
- for await (let c of t) {
37
- let {delta: p} = c.choices?.[0] ?? {},
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 && (e += m), o?.({content: e, reasoning: a}, c));
39
+ (u && (a += u), m && (s += m), e?.({content: s, reasoning: a}, i));
40
40
  }
41
- return {content: e, reasoning: a};
41
+ return {content: s, reasoning: a};
42
42
  }
43
- o?.(t);
44
- let {message: i} = t.choices?.[0] ?? {},
45
- {content: s, reasoning: n} = i;
46
- return {content: s, reasoning: n};
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, o) => {
49
+ k = async (t, r, e) => {
50
50
  if (r) {
51
- let s = '',
51
+ let o = '',
52
52
  n = '';
53
- for await (let e of t) {
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));
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: s, reasoning: n};
57
+ return {content: o, reasoning: n};
58
58
  }
59
- return (o?.(t), {reasoning: (t.output?.[0]?.content ?? t.output?.[0]?.summary)?.[0]?.text, content: t.output_text});
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, o) => {
61
+ v = async (t, r, e) => {
62
62
  if (r) {
63
63
  let n = '',
64
- e = '';
64
+ s = '';
65
65
  for await (let a of t) {
66
- let c = a.reasoning ?? a.thinking,
66
+ let i = a.reasoning ?? a.thinking,
67
67
  p = a.content ?? a.response;
68
- (c && (e += c), p && (n += p), o?.({content: n, reasoning: e}, a));
68
+ (i && (s += i), p && (n += p), e?.({content: n, reasoning: s}, a));
69
69
  }
70
- return {content: n, reasoning: e};
70
+ return {content: n, reasoning: s};
71
71
  }
72
- o?.(t);
73
- let i = t.reasoning ?? t.thinking;
74
- return {content: t.content ?? t.response, reasoning: i};
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, o) => {
76
+ O = async (t, r, e) => {
77
77
  if (r) {
78
- let e = '',
78
+ let s = '',
79
79
  a = '';
80
- for await (let c of t) {
81
- let {message: p} = c,
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 && (e += m), o?.({content: e, reasoning: a}, c));
84
+ (u && (a += u), m && (s += m), e?.({content: s, reasoning: a}, i));
85
85
  }
86
- return {content: e, reasoning: a};
86
+ return {content: s, reasoning: a};
87
87
  }
88
- let {message: i} = t;
89
- o?.(t);
90
- let s = i.reasoning ?? i.thinking;
91
- return {content: i.content ?? i.response, reasoning: s};
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 = {}, o = 'chat') => {
93
+ var x = (t, r = {}, e = 'chat') => {
94
94
  if (!t) throw Error('\u8BF7\u4F20\u5165\u4F60\u7684 prompt !');
95
- if (o === 'chat') {
96
- let s = Array.isArray(t) ? t : [{role: 'user', content: t}],
97
- {system: n, ...e} = r;
98
- return (n && (s = [{role: 'system', content: n}, ...s]), {messages: s, ...e});
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 (o === 'responses') {
101
- let {instructions: s, system: n, ...e} = r;
102
- return (s || (e.instructions = n), {input: t, ...e});
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, 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);
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: o, params: i, options: s} = A,
114
- {host: n, baseURL: e, ...a} = t,
115
- c = new H({fetch: w, ...o, ...a, baseURL: n || e}),
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 = {...i, ...m, options: {...s, ...p, ...u}};
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 c.chat.completions.create(y(_, h, 'openai'));
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 c.responses.create(y(_, h, 'openai'));
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: 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}};
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, o) => (L[t] ?? L.ollama)(r, o),
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};