@auipage/model 0.1.0-alpha.5 → 0.1.0
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/AUTHORS.txt +6 -6
- package/CHANGELOG +4 -4
- package/README.md +93 -93
- package/dist/index.js +460 -460
- package/package.json +3 -3
- package/src/completions.js +62 -62
- package/src/index.js +11 -11
- package/src/parseString.js +15 -15
- package/src/reasoning.js +78 -78
- package/src/streamHandler.js +51 -51
- package/types/completions.d.ts +31 -31
- package/types/index.d.ts +13 -13
- package/types/model.d.ts +33 -33
package/AUTHORS.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Authors ordered by first contribution.
|
|
2
|
-
|
|
3
|
-
zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
|
|
4
|
-
|
|
5
|
-
-----------------------------------------------------
|
|
6
|
-
We thank all of them for their contributions!
|
|
1
|
+
Authors ordered by first contribution.
|
|
2
|
+
|
|
3
|
+
zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
|
|
4
|
+
|
|
5
|
+
-----------------------------------------------------
|
|
6
|
+
We thank all of them for their contributions!
|
package/CHANGELOG
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
v0.1.0:
|
|
2
|
-
date:
|
|
3
|
-
changes:
|
|
4
|
-
- 初始化版本
|
|
1
|
+
v0.1.0:
|
|
2
|
+
date:2026-10-25
|
|
3
|
+
changes:
|
|
4
|
+
- 初始化版本
|
package/README.md
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
# [@auipage/model](https://github.com/handless-ui/auipage/packages/model/README.md)
|
|
2
|
-
|
|
3
|
-
OpenAI 风格 `chat/completions` 的流式封装:负责请求拼装、SSE 增量解析、工具调用切片拼接,兼容同协议的其他模型服务(DeepSeek 等)。
|
|
4
|
-
|
|
5
|
-
<p>
|
|
6
|
-
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@auipage/model&interval=7">
|
|
7
|
-
<img src="https://img.shields.io/npm/dm/@auipage/model.svg" alt="downloads">
|
|
8
|
-
</a>
|
|
9
|
-
<a href="https://www.npmjs.com/package/@auipage/model">
|
|
10
|
-
<img src="https://img.shields.io/npm/v/@auipage/model.svg" alt="npm">
|
|
11
|
-
</a>
|
|
12
|
-
<a href="https://github.com/handless-ui/auipage" target='_blank'>
|
|
13
|
-
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/handless-ui/auipage?style=social">
|
|
14
|
-
</a>
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
<img src="https://nodei.co/npm/@auipage/model.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
18
|
-
|
|
19
|
-
## 安装
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
npm install --save @auipage/model
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## 创建实例
|
|
26
|
-
|
|
27
|
-
```javascript
|
|
28
|
-
import { Model } from "@auipage/model";
|
|
29
|
-
|
|
30
|
-
const model = new Model({
|
|
31
|
-
model: "deepseek-chat", // 模型名
|
|
32
|
-
apiKey: "your-api-key",
|
|
33
|
-
baseURL: "https://api.deepseek.com/v1" // 请求时拼接 /chat/completions
|
|
34
|
-
});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## completions
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
model.completions(
|
|
41
|
-
{
|
|
42
|
-
messages: ChatMessage[], // OpenAI 格式消息
|
|
43
|
-
tools?: Tool[], // 可选,默认 [];自动取每项的 description 作为 tools 提交
|
|
44
|
-
stream?: boolean // 默认 false
|
|
45
|
-
},
|
|
46
|
-
logback?, // (delta: string) => void,正文增量回调
|
|
47
|
-
thinkback? // (reasoning: string) => void,推理过程回调
|
|
48
|
-
): Promise<{ content: string, tool_calls: ModelToolCall[] }>
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
- `thinkback` 接收 `delta.reasoning` / `delta.reasoning_content`;正文中的 `<think>...</think>` 标签会被剥除,剩余内容并入 `content`。
|
|
52
|
-
- `stream: false` 时两个回调仍会调用,只是在响应结束后各触发一次。
|
|
53
|
-
- 返回的 `tool_calls` 已按 `id` 切片、拼好 `function.arguments`。
|
|
54
|
-
|
|
55
|
-
## 示例
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
model.completions({
|
|
59
|
-
messages: [
|
|
60
|
-
{ role: "system", content: "你是一个助手。" },
|
|
61
|
-
{ role: "user", content: "查一下南京今天的天气" }
|
|
62
|
-
],
|
|
63
|
-
tools: [
|
|
64
|
-
{
|
|
65
|
-
description: {
|
|
66
|
-
type: "function",
|
|
67
|
-
function: {
|
|
68
|
-
name: "getWeather",
|
|
69
|
-
description: "查询指定城市的天气",
|
|
70
|
-
parameters: {
|
|
71
|
-
type: "object",
|
|
72
|
-
properties: { city: { type: "string" } },
|
|
73
|
-
required: ["city"]
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
stream: true
|
|
80
|
-
}, (chunk) => {
|
|
81
|
-
process.stdout.write(chunk); // 正文增量
|
|
82
|
-
}, (reasoning) => {
|
|
83
|
-
console.log("[think]", reasoning); // 推理增量
|
|
84
|
-
}).then(({ content, tool_calls }) => {
|
|
85
|
-
console.log(content, tool_calls);
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## 版权
|
|
90
|
-
|
|
91
|
-
MIT License
|
|
92
|
-
|
|
93
|
-
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|
|
1
|
+
# [@auipage/model](https://github.com/handless-ui/auipage/packages/model/README.md)
|
|
2
|
+
|
|
3
|
+
OpenAI 风格 `chat/completions` 的流式封装:负责请求拼装、SSE 增量解析、工具调用切片拼接,兼容同协议的其他模型服务(DeepSeek 等)。
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@auipage/model&interval=7">
|
|
7
|
+
<img src="https://img.shields.io/npm/dm/@auipage/model.svg" alt="downloads">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/@auipage/model">
|
|
10
|
+
<img src="https://img.shields.io/npm/v/@auipage/model.svg" alt="npm">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/handless-ui/auipage" target='_blank'>
|
|
13
|
+
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/handless-ui/auipage?style=social">
|
|
14
|
+
</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<img src="https://nodei.co/npm/@auipage/model.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install --save @auipage/model
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 创建实例
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import { Model } from "@auipage/model";
|
|
29
|
+
|
|
30
|
+
const model = new Model({
|
|
31
|
+
model: "deepseek-chat", // 模型名
|
|
32
|
+
apiKey: "your-api-key",
|
|
33
|
+
baseURL: "https://api.deepseek.com/v1" // 请求时拼接 /chat/completions
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## completions
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
model.completions(
|
|
41
|
+
{
|
|
42
|
+
messages: ChatMessage[], // OpenAI 格式消息
|
|
43
|
+
tools?: Tool[], // 可选,默认 [];自动取每项的 description 作为 tools 提交
|
|
44
|
+
stream?: boolean // 默认 false
|
|
45
|
+
},
|
|
46
|
+
logback?, // (delta: string) => void,正文增量回调
|
|
47
|
+
thinkback? // (reasoning: string) => void,推理过程回调
|
|
48
|
+
): Promise<{ content: string, tool_calls: ModelToolCall[] }>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- `thinkback` 接收 `delta.reasoning` / `delta.reasoning_content`;正文中的 `<think>...</think>` 标签会被剥除,剩余内容并入 `content`。
|
|
52
|
+
- `stream: false` 时两个回调仍会调用,只是在响应结束后各触发一次。
|
|
53
|
+
- 返回的 `tool_calls` 已按 `id` 切片、拼好 `function.arguments`。
|
|
54
|
+
|
|
55
|
+
## 示例
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
model.completions({
|
|
59
|
+
messages: [
|
|
60
|
+
{ role: "system", content: "你是一个助手。" },
|
|
61
|
+
{ role: "user", content: "查一下南京今天的天气" }
|
|
62
|
+
],
|
|
63
|
+
tools: [
|
|
64
|
+
{
|
|
65
|
+
description: {
|
|
66
|
+
type: "function",
|
|
67
|
+
function: {
|
|
68
|
+
name: "getWeather",
|
|
69
|
+
description: "查询指定城市的天气",
|
|
70
|
+
parameters: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: { city: { type: "string" } },
|
|
73
|
+
required: ["city"]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
stream: true
|
|
80
|
+
}, (chunk) => {
|
|
81
|
+
process.stdout.write(chunk); // 正文增量
|
|
82
|
+
}, (reasoning) => {
|
|
83
|
+
console.log("[think]", reasoning); // 推理增量
|
|
84
|
+
}).then(({ content, tool_calls }) => {
|
|
85
|
+
console.log(content, tool_calls);
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 版权
|
|
90
|
+
|
|
91
|
+
MIT License
|
|
92
|
+
|
|
93
|
+
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|