@hopemyl619/deepseek 0.1.2 → 0.3.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/dist/index.js +81 -209
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/deepseek-provider.ts +68 -55
- package/src/index.ts +18 -15
- package/src/utils/request-transformer.ts +44 -21
- package/src/utils/response-transformer.ts +33 -10
- package/src/utils/stream-parser.ts +10 -0
- package/dist/index.d.ts +0 -184
- package/src/utils/chinese-params-preprocessor.ts +0 -161
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// 中文参数预处理器
|
|
2
|
-
|
|
3
|
-
import type { DeepSeekRequest } from '../types';
|
|
4
|
-
|
|
5
|
-
export class ChineseParamsPreprocessor {
|
|
6
|
-
private cityMap: Record<string, string> = {
|
|
7
|
-
// 中国城市
|
|
8
|
-
'北京': 'Beijing',
|
|
9
|
-
'上海': 'Shanghai',
|
|
10
|
-
'广州': 'Guangzhou',
|
|
11
|
-
'深圳': 'Shenzhen',
|
|
12
|
-
'杭州': 'Hangzhou',
|
|
13
|
-
'南京': 'Nanjing',
|
|
14
|
-
'成都': 'Chengdu',
|
|
15
|
-
'武汉': 'Wuhan',
|
|
16
|
-
'西安': 'Xi\'an',
|
|
17
|
-
'重庆': 'Chongqing',
|
|
18
|
-
'天津': 'Tianjin',
|
|
19
|
-
'苏州': 'Suzhou',
|
|
20
|
-
'长沙': 'Changsha',
|
|
21
|
-
'青岛': 'Qingdao',
|
|
22
|
-
'大连': 'Dalian',
|
|
23
|
-
'厦门': 'Xiamen',
|
|
24
|
-
'宁波': 'Ningbo',
|
|
25
|
-
'无锡': 'Wuxi',
|
|
26
|
-
'佛山': 'Foshan',
|
|
27
|
-
'东莞': 'Dongguan',
|
|
28
|
-
'合肥': 'Hefei',
|
|
29
|
-
'郑州': 'Zhengzhou',
|
|
30
|
-
'福州': 'Fuzhou',
|
|
31
|
-
'济南': 'Jinan',
|
|
32
|
-
'昆明': 'Kunming',
|
|
33
|
-
'沈阳': 'Shenyang',
|
|
34
|
-
'长春': 'Changchun',
|
|
35
|
-
'哈尔滨': 'Harbin',
|
|
36
|
-
'石家庄': 'Shijiazhuang',
|
|
37
|
-
'太原': 'Taiyuan',
|
|
38
|
-
'南昌': 'Nanchang',
|
|
39
|
-
'南宁': 'Nanning',
|
|
40
|
-
'贵阳': 'Guiyang',
|
|
41
|
-
'兰州': 'Lanzhou',
|
|
42
|
-
'海口': 'Haikou',
|
|
43
|
-
'呼和浩特': 'Hohhot',
|
|
44
|
-
'银川': 'Yinchuan',
|
|
45
|
-
'西宁': 'Xining',
|
|
46
|
-
'乌鲁木齐': 'Urumqi',
|
|
47
|
-
'拉萨': 'Lhasa',
|
|
48
|
-
// 国际城市
|
|
49
|
-
'伦敦': 'London',
|
|
50
|
-
'纽约': 'New York',
|
|
51
|
-
'东京': 'Tokyo',
|
|
52
|
-
'巴黎': 'Paris',
|
|
53
|
-
'柏林': 'Berlin',
|
|
54
|
-
'悉尼': 'Sydney',
|
|
55
|
-
'洛杉矶': 'Los Angeles',
|
|
56
|
-
'多伦多': 'Toronto',
|
|
57
|
-
'新加坡': 'Singapore',
|
|
58
|
-
'香港': 'Hong Kong',
|
|
59
|
-
'台北': 'Taipei',
|
|
60
|
-
'首尔': 'Seoul',
|
|
61
|
-
'曼谷': 'Bangkok',
|
|
62
|
-
'迪拜': 'Dubai',
|
|
63
|
-
'莫斯科': 'Moscow',
|
|
64
|
-
'旧金山': 'San Francisco',
|
|
65
|
-
'波士顿': 'Boston',
|
|
66
|
-
'芝加哥': 'Chicago',
|
|
67
|
-
'华盛顿': 'Washington',
|
|
68
|
-
'休斯顿': 'Houston',
|
|
69
|
-
'费城': 'Philadelphia',
|
|
70
|
-
'凤凰城': 'Phoenix',
|
|
71
|
-
'圣迭戈': 'San Diego',
|
|
72
|
-
'达拉斯': 'Dallas',
|
|
73
|
-
'圣何塞': 'San Jose',
|
|
74
|
-
'奥斯汀': 'Austin',
|
|
75
|
-
'温哥华': 'Vancouver',
|
|
76
|
-
'蒙特利尔': 'Montreal',
|
|
77
|
-
'卡尔加里': 'Calgary',
|
|
78
|
-
'渥太华': 'Ottawa',
|
|
79
|
-
'魁北克': 'Quebec',
|
|
80
|
-
'埃德蒙顿': 'Edmonton',
|
|
81
|
-
'温尼伯': 'Winnipeg',
|
|
82
|
-
'哈利法克斯': 'Halifax',
|
|
83
|
-
'维多利亚': 'Victoria',
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
process(request: DeepSeekRequest): DeepSeekRequest {
|
|
87
|
-
const processed = JSON.parse(JSON.stringify(request));
|
|
88
|
-
|
|
89
|
-
// 处理消息内容
|
|
90
|
-
if (processed.messages) {
|
|
91
|
-
processed.messages = this.processMessages(processed.messages);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 处理工具参数
|
|
95
|
-
if (processed.tools) {
|
|
96
|
-
processed.tools = this.processTools(processed.tools);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return processed;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private processMessages(messages: any[]): any[] {
|
|
103
|
-
return messages.map(msg => {
|
|
104
|
-
if (msg.content && typeof msg.content === 'string') {
|
|
105
|
-
msg.content = this.replaceCityNames(msg.content);
|
|
106
|
-
} else if (Array.isArray(msg.content)) {
|
|
107
|
-
msg.content = msg.content.map((part: any) => {
|
|
108
|
-
if (part.type === 'text' && part.text) {
|
|
109
|
-
part.text = this.replaceCityNames(part.text);
|
|
110
|
-
}
|
|
111
|
-
return part;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return msg;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private processTools(tools: any[]): any[] {
|
|
119
|
-
return tools.map(tool => {
|
|
120
|
-
if (tool.function?.parameters?.properties) {
|
|
121
|
-
this.processProperties(tool.function.parameters.properties);
|
|
122
|
-
}
|
|
123
|
-
if (tool.function?.description) {
|
|
124
|
-
tool.function.description = this.replaceCityNames(tool.function.description);
|
|
125
|
-
}
|
|
126
|
-
return tool;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private processProperties(properties: any): void {
|
|
131
|
-
for (const key in properties) {
|
|
132
|
-
if (properties[key].description) {
|
|
133
|
-
properties[key].description = this.replaceCityNames(properties[key].description);
|
|
134
|
-
}
|
|
135
|
-
if (properties[key].example) {
|
|
136
|
-
const exampleStr = JSON.stringify(properties[key].example);
|
|
137
|
-
properties[key].example = JSON.parse(this.replaceCityNames(exampleStr));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private replaceCityNames(text: string): string {
|
|
143
|
-
let result = text;
|
|
144
|
-
for (const [chinese, english] of Object.entries(this.cityMap)) {
|
|
145
|
-
// 使用正则表达式替换,避免替换部分匹配的词
|
|
146
|
-
const regex = new RegExp(`\\b${chinese}\\b`, 'g');
|
|
147
|
-
result = result.replace(regex, english);
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 添加自定义城市映射
|
|
153
|
-
addCityMapping(chinese: string, english: string): void {
|
|
154
|
-
this.cityMap[chinese] = english;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 批量添加城市映射
|
|
158
|
-
addCityMappings(mappings: Record<string, string>): void {
|
|
159
|
-
Object.assign(this.cityMap, mappings);
|
|
160
|
-
}
|
|
161
|
-
}
|