@zhongqian97-code/ecode 0.3.8 → 0.3.9
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 +38 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -148,6 +148,34 @@ function createOpenAIProvider(profile) {
|
|
|
148
148
|
stream(messages, tools, signal) {
|
|
149
149
|
return {
|
|
150
150
|
[Symbol.asyncIterator]: async function* () {
|
|
151
|
+
let inThinkBlock = false;
|
|
152
|
+
function stripThinkTags(raw) {
|
|
153
|
+
let text = "";
|
|
154
|
+
let thinking = "";
|
|
155
|
+
let i = 0;
|
|
156
|
+
while (i < raw.length) {
|
|
157
|
+
if (!inThinkBlock) {
|
|
158
|
+
const start = raw.indexOf("<think>", i);
|
|
159
|
+
if (start === -1) {
|
|
160
|
+
text += raw.slice(i);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
text += raw.slice(i, start);
|
|
164
|
+
inThinkBlock = true;
|
|
165
|
+
i = start + 7;
|
|
166
|
+
} else {
|
|
167
|
+
const end = raw.indexOf("</think>", i);
|
|
168
|
+
if (end === -1) {
|
|
169
|
+
thinking += raw.slice(i);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
thinking += raw.slice(i, end);
|
|
173
|
+
inThinkBlock = false;
|
|
174
|
+
i = end + 8;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { text, thinking };
|
|
178
|
+
}
|
|
151
179
|
const requestParams = {
|
|
152
180
|
model: profile.model,
|
|
153
181
|
messages,
|
|
@@ -206,11 +234,16 @@ function createOpenAIProvider(profile) {
|
|
|
206
234
|
existing.arguments += tc.function?.arguments ?? "";
|
|
207
235
|
}
|
|
208
236
|
}
|
|
209
|
-
const isLast = choice.finish_reason
|
|
237
|
+
const isLast = choice.finish_reason != null;
|
|
238
|
+
const raw = delta.content ?? "";
|
|
239
|
+
const { text: filteredText, thinking: thinkContent } = stripThinkTags(raw);
|
|
240
|
+
if (thinkContent) {
|
|
241
|
+
reasoningAccumulator += thinkContent;
|
|
242
|
+
}
|
|
210
243
|
if (isLast) {
|
|
211
244
|
const rawUsage = chunk.usage;
|
|
212
245
|
yield {
|
|
213
|
-
text:
|
|
246
|
+
text: filteredText,
|
|
214
247
|
done: true,
|
|
215
248
|
finishReason: choice.finish_reason,
|
|
216
249
|
// tcAccumulator 为空说明本轮没有工具调用,传 undefined 而非空数组,
|
|
@@ -227,10 +260,10 @@ function createOpenAIProvider(profile) {
|
|
|
227
260
|
} : void 0
|
|
228
261
|
};
|
|
229
262
|
} else {
|
|
230
|
-
const incrementalReasoning = delta.reasoning_content
|
|
263
|
+
const incrementalReasoning = delta.reasoning_content || thinkContent || (delta.reasoning_details && delta.reasoning_details.length > 0 ? delta.reasoning_details.map((rd) => rd.text ?? "").join("") : void 0) || void 0;
|
|
231
264
|
yield {
|
|
232
|
-
text:
|
|
233
|
-
reasoning: incrementalReasoning,
|
|
265
|
+
text: filteredText,
|
|
266
|
+
reasoning: incrementalReasoning || void 0,
|
|
234
267
|
done: false
|
|
235
268
|
};
|
|
236
269
|
}
|