@zhongqian97-code/ecode 0.5.3 → 0.5.4
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 +24 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -148,33 +148,30 @@ function createOpenAIProvider(profile) {
|
|
|
148
148
|
stream(messages, tools, signal) {
|
|
149
149
|
return {
|
|
150
150
|
[Symbol.asyncIterator]: async function* () {
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
i = start + 7;
|
|
151
|
+
let thinkPhase = "pre";
|
|
152
|
+
let afterReasoningDetails = false;
|
|
153
|
+
function processContent(raw) {
|
|
154
|
+
if (!raw) return { text: "", thinking: "" };
|
|
155
|
+
if (afterReasoningDetails) {
|
|
156
|
+
afterReasoningDetails = false;
|
|
157
|
+
thinkPhase = "post";
|
|
158
|
+
return { text: raw.startsWith("</think>") ? raw.slice(8) : raw, thinking: "" };
|
|
159
|
+
}
|
|
160
|
+
if (thinkPhase === "post") return { text: raw, thinking: "" };
|
|
161
|
+
if (thinkPhase === "pre") {
|
|
162
|
+
if (raw.startsWith("<think>")) {
|
|
163
|
+
thinkPhase = "in";
|
|
164
|
+
raw = raw.slice(7);
|
|
166
165
|
} else {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
thinking += raw.slice(i);
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
thinking += raw.slice(i, end);
|
|
173
|
-
inThinkBlock = false;
|
|
174
|
-
i = end + 8;
|
|
166
|
+
thinkPhase = "post";
|
|
167
|
+
return { text: raw, thinking: "" };
|
|
175
168
|
}
|
|
176
169
|
}
|
|
177
|
-
|
|
170
|
+
const endIdx = raw.indexOf("</think>");
|
|
171
|
+
if (endIdx === -1) return { text: "", thinking: raw };
|
|
172
|
+
const thinking = raw.slice(0, endIdx);
|
|
173
|
+
thinkPhase = "post";
|
|
174
|
+
return { text: raw.slice(endIdx + 8), thinking };
|
|
178
175
|
}
|
|
179
176
|
const requestParams = {
|
|
180
177
|
model: profile.model,
|
|
@@ -200,6 +197,7 @@ function createOpenAIProvider(profile) {
|
|
|
200
197
|
reasoningAccumulator += delta.reasoning_content;
|
|
201
198
|
}
|
|
202
199
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
200
|
+
afterReasoningDetails = true;
|
|
203
201
|
for (const rd of delta.reasoning_details) {
|
|
204
202
|
const id = rd.id ?? "";
|
|
205
203
|
const text = rd.text ?? "";
|
|
@@ -235,8 +233,8 @@ function createOpenAIProvider(profile) {
|
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
const isLast = choice.finish_reason != null;
|
|
238
|
-
const raw = delta.content ?? "";
|
|
239
|
-
const { text: filteredText, thinking: thinkContent } =
|
|
236
|
+
const raw = delta.reasoning_details && delta.reasoning_details.length > 0 ? "" : delta.content ?? "";
|
|
237
|
+
const { text: filteredText, thinking: thinkContent } = processContent(raw);
|
|
240
238
|
if (thinkContent) {
|
|
241
239
|
reasoningAccumulator += thinkContent;
|
|
242
240
|
}
|