doomiaichat 6.0.5 → 6.0.6

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/azureai.js CHANGED
@@ -160,7 +160,7 @@ class AzureAI extends openaibase_1.default {
160
160
  currentIndex = toolCalls[0].index;
161
161
  has_tool_calls = 1;
162
162
  // 检查index是否发生变化
163
- console.log('currentIndex,previous_index', currentIndex, previous_index);
163
+ //console.log('currentIndex,previous_index', currentIndex, previous_index)
164
164
  if (currentIndex !== previous_index) {
165
165
  tool_calls.push({
166
166
  id: toolCalls[0].id,
package/dist/openai.js CHANGED
@@ -84,7 +84,8 @@ class OpenAIGpt extends openaibase_1.default {
84
84
  // tools: (callChatOption?.enableToolCall === 1 && callChatOption?.tools) ? callChatOption.tools : undefined,
85
85
  // tool_choice: callChatOption?.enableToolCall === 1 ? 'auto' : undefined,
86
86
  }, axiosOption);
87
- return { successed: true, message: response.data.choices, usage: response.data.usage };
87
+ // console.log('response.data', response)
88
+ return { successed: true, message: response.choices, usage: response.usage };
88
89
  }
89
90
  catch (error) {
90
91
  console.log('result is error ', error);
@@ -124,16 +125,39 @@ class OpenAIGpt extends openaibase_1.default {
124
125
  stream: true
125
126
  }, axiosOption);
126
127
  let replytext = [];
128
+ let has_tool_calls = 0, currentIndex, previous_index = -1, tool_calls = []; // 使用数组来存储工具调用
127
129
  try {
128
- // let has_tool_calls = 0, currentIndex, previous_index = -1, tool_calls: any[] = [];// 使用数组来存储工具调用
129
130
  for (var _d = true, response_1 = __asyncValues(response), response_1_1; response_1_1 = yield response_1.next(), _a = response_1_1.done, !_a;) {
130
131
  _c = response_1_1.value;
131
132
  _d = false;
132
133
  try {
133
134
  const chunk = _c;
134
- const [choice] = chunk.choices, { finish_reason: finishreason, index, usage } = choice, { content } = choice.delta;
135
- replytext.push(content);
136
- let output = { successed: true, requestid, segment: content, text: replytext.join(''), finish_reason: finishreason, index, usage };
135
+ const [choice] = chunk.choices, { finish_reason: finishreason, index, usage } = choice, { content, tool_calls: toolCalls } = choice.delta;
136
+ if (toolCalls && toolCalls.length) {
137
+ currentIndex = toolCalls[0].index;
138
+ has_tool_calls = 1;
139
+ // 检查index是否发生变化
140
+ //console.log('currentIndex,previous_index', currentIndex, previous_index)
141
+ if (currentIndex !== previous_index) {
142
+ tool_calls.push({
143
+ id: toolCalls[0].id,
144
+ type: 'function',
145
+ function: {
146
+ name: toolCalls[0].function.name,
147
+ arguments: toolCalls[0].function.arguments
148
+ }
149
+ });
150
+ // 更新previousIndex以供下次比较
151
+ previous_index = currentIndex;
152
+ }
153
+ else {
154
+ tool_calls[previous_index].function.arguments += toolCalls[0].function.arguments;
155
+ }
156
+ }
157
+ else {
158
+ replytext.push(content);
159
+ }
160
+ let output = { successed: true, requestid, segment: content, text: replytext.join(''), finish_reason: finishreason, index, usage, has_tool_calls: has_tool_calls, tool_calls: tool_calls };
137
161
  if (attach)
138
162
  output = Object.assign({}, output, attach);
139
163
  this.emit(finishreason ? 'chatdone' : 'chattext', output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "6.0.5",
3
+ "version": "6.0.6",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/azureai.ts CHANGED
@@ -142,7 +142,7 @@ export default class AzureAI extends OpenAIBase<OpenAIClient> {
142
142
  currentIndex = toolCalls[0].index;
143
143
  has_tool_calls = 1;
144
144
  // 检查index是否发生变化
145
- console.log('currentIndex,previous_index', currentIndex, previous_index)
145
+ //console.log('currentIndex,previous_index', currentIndex, previous_index)
146
146
  if (currentIndex !== previous_index) {
147
147
  tool_calls.push({
148
148
  id: toolCalls[0].id,
package/src/openai.ts CHANGED
@@ -60,7 +60,8 @@ export default class OpenAIGpt extends OpenAIBase<OpenAI> {
60
60
  // tools: (callChatOption?.enableToolCall === 1 && callChatOption?.tools) ? callChatOption.tools : undefined,
61
61
  // tool_choice: callChatOption?.enableToolCall === 1 ? 'auto' : undefined,
62
62
  }, axiosOption);
63
- return { successed: true, message: response.data.choices, usage: response.data.usage };
63
+ // console.log('response.data', response)
64
+ return { successed: true, message: response.choices, usage: response.usage };
64
65
  } catch (error) {
65
66
  console.log('result is error ', error)
66
67
  return { successed: false, error };
@@ -97,13 +98,34 @@ export default class OpenAIGpt extends OpenAIBase<OpenAI> {
97
98
  stream:true
98
99
  }, axiosOption);
99
100
  let replytext: string[] = [];
100
- // let has_tool_calls = 0, currentIndex, previous_index = -1, tool_calls: any[] = [];// 使用数组来存储工具调用
101
+ let has_tool_calls = 0, currentIndex, previous_index = -1, tool_calls: any[] = [];// 使用数组来存储工具调用
101
102
  for await (const chunk of response) {
102
103
  const [choice] = chunk.choices,
103
104
  { finish_reason:finishreason, index, usage } = choice,
104
- { content} = choice.delta;
105
- replytext.push(content);
106
- let output = { successed: true, requestid, segment: content, text: replytext.join(''), finish_reason: finishreason, index, usage };
105
+ { content, tool_calls:toolCalls } = choice.delta;
106
+ if (toolCalls && toolCalls.length) {
107
+ currentIndex = toolCalls[0].index;
108
+ has_tool_calls = 1;
109
+ // 检查index是否发生变化
110
+ //console.log('currentIndex,previous_index', currentIndex, previous_index)
111
+ if (currentIndex !== previous_index) {
112
+ tool_calls.push({
113
+ id: toolCalls[0].id,
114
+ type: 'function',
115
+ function: {
116
+ name: toolCalls[0].function.name,
117
+ arguments: toolCalls[0].function.arguments
118
+ }
119
+ });
120
+ // 更新previousIndex以供下次比较
121
+ previous_index = currentIndex;
122
+ } else {
123
+ tool_calls[previous_index].function.arguments += toolCalls[0].function.arguments
124
+ }
125
+ } else {
126
+ replytext.push(content);
127
+ }
128
+ let output = { successed: true, requestid, segment: content, text: replytext.join(''), finish_reason: finishreason, index, usage, has_tool_calls: has_tool_calls, tool_calls: tool_calls };
107
129
  if (attach) output = Object.assign({}, output, attach);
108
130
  this.emit(finishreason ? 'chatdone' : 'chattext', output)
109
131
  }