@zhongqian97-code/ecode 0.0.4 → 0.0.5
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 +23 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -99,12 +99,16 @@ function createLLMClient(config2) {
|
|
|
99
99
|
}
|
|
100
100
|
const response = await openai.chat.completions.create(requestParams);
|
|
101
101
|
const tcAccumulator = /* @__PURE__ */ new Map();
|
|
102
|
+
let reasoningAccumulator = "";
|
|
102
103
|
for await (const chunk of response) {
|
|
103
104
|
const choice = chunk.choices[0];
|
|
104
105
|
if (!choice) continue;
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
|
|
106
|
+
const delta = choice.delta;
|
|
107
|
+
if (delta.reasoning_content) {
|
|
108
|
+
reasoningAccumulator += delta.reasoning_content;
|
|
109
|
+
}
|
|
110
|
+
if (delta.tool_calls) {
|
|
111
|
+
for (const tc of delta.tool_calls) {
|
|
108
112
|
if (!tcAccumulator.has(tc.index)) {
|
|
109
113
|
tcAccumulator.set(tc.index, {
|
|
110
114
|
id: tc.id ?? "",
|
|
@@ -121,14 +125,16 @@ function createLLMClient(config2) {
|
|
|
121
125
|
const isLast = choice.finish_reason !== null;
|
|
122
126
|
if (isLast) {
|
|
123
127
|
yield {
|
|
124
|
-
text:
|
|
128
|
+
text: delta.content ?? "",
|
|
125
129
|
done: true,
|
|
126
130
|
finishReason: choice.finish_reason,
|
|
127
|
-
toolCalls: tcAccumulator.size > 0 ? Array.from(tcAccumulator.values()) : void 0
|
|
131
|
+
toolCalls: tcAccumulator.size > 0 ? Array.from(tcAccumulator.values()) : void 0,
|
|
132
|
+
reasoning: reasoningAccumulator || void 0
|
|
128
133
|
};
|
|
129
134
|
} else {
|
|
130
135
|
yield {
|
|
131
|
-
text:
|
|
136
|
+
text: delta.content ?? "",
|
|
137
|
+
reasoning: delta.reasoning_content,
|
|
132
138
|
done: false
|
|
133
139
|
};
|
|
134
140
|
}
|
|
@@ -220,14 +226,16 @@ async function startRepl(config2) {
|
|
|
220
226
|
continueLoop = false;
|
|
221
227
|
process.stdout.write("assistant: ");
|
|
222
228
|
let assistantText = "";
|
|
229
|
+
let assistantReasoning;
|
|
223
230
|
const toolCalls = [];
|
|
224
231
|
for await (const chunk of llm.stream(messages, [BASH_TOOL])) {
|
|
225
232
|
if (chunk.text) {
|
|
226
233
|
process.stdout.write(chunk.text);
|
|
227
234
|
assistantText += chunk.text;
|
|
228
235
|
}
|
|
229
|
-
if (chunk.done
|
|
230
|
-
toolCalls.push(...chunk.toolCalls);
|
|
236
|
+
if (chunk.done) {
|
|
237
|
+
if (chunk.toolCalls) toolCalls.push(...chunk.toolCalls);
|
|
238
|
+
if (chunk.reasoning) assistantReasoning = chunk.reasoning;
|
|
231
239
|
}
|
|
232
240
|
}
|
|
233
241
|
if (toolCalls.length > 0) {
|
|
@@ -238,7 +246,8 @@ async function startRepl(config2) {
|
|
|
238
246
|
id: tc.id,
|
|
239
247
|
type: "function",
|
|
240
248
|
function: { name: tc.name, arguments: tc.arguments }
|
|
241
|
-
}))
|
|
249
|
+
})),
|
|
250
|
+
...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
|
|
242
251
|
});
|
|
243
252
|
for (const tc of toolCalls) {
|
|
244
253
|
if (tc.name === "bash") {
|
|
@@ -264,7 +273,11 @@ async function startRepl(config2) {
|
|
|
264
273
|
} else {
|
|
265
274
|
process.stdout.write("\n");
|
|
266
275
|
if (assistantText) {
|
|
267
|
-
messages.push({
|
|
276
|
+
messages.push({
|
|
277
|
+
role: "assistant",
|
|
278
|
+
content: assistantText,
|
|
279
|
+
...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
|
|
280
|
+
});
|
|
268
281
|
}
|
|
269
282
|
}
|
|
270
283
|
}
|