特殊情况下为工具调用生成备用的id
Browse files- src/api/client.js +2 -1
- src/utils/idGenerator.js +7 -1
src/api/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import tokenManager from '../auth/token_manager.js';
|
| 2 |
import config from '../config/config.js';
|
|
|
|
| 3 |
|
| 4 |
export async function generateAssistantResponse(requestBody, callback) {
|
| 5 |
const token = await tokenManager.getToken();
|
|
@@ -64,7 +65,7 @@ export async function generateAssistantResponse(requestBody, callback) {
|
|
| 64 |
callback({ type: 'text', content: part.text });
|
| 65 |
} else if (part.functionCall) {
|
| 66 |
toolCalls.push({
|
| 67 |
-
id: part.functionCall.id,
|
| 68 |
type: 'function',
|
| 69 |
function: {
|
| 70 |
name: part.functionCall.name,
|
|
|
|
| 1 |
import tokenManager from '../auth/token_manager.js';
|
| 2 |
import config from '../config/config.js';
|
| 3 |
+
import { generateToolCallId } from '../utils/idGenerator.js';
|
| 4 |
|
| 5 |
export async function generateAssistantResponse(requestBody, callback) {
|
| 6 |
const token = await tokenManager.getToken();
|
|
|
|
| 65 |
callback({ type: 'text', content: part.text });
|
| 66 |
} else if (part.functionCall) {
|
| 67 |
toolCalls.push({
|
| 68 |
+
id: part.functionCall.id || generateToolCallId(),
|
| 69 |
type: 'function',
|
| 70 |
function: {
|
| 71 |
name: part.functionCall.name,
|
src/utils/idGenerator.js
CHANGED
|
@@ -16,8 +16,14 @@ function generateProjectId() {
|
|
| 16 |
const randomNum = Math.random().toString(36).substring(2, 7);
|
| 17 |
return `${randomAdj}-${randomNoun}-${randomNum}`;
|
| 18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
export {
|
| 20 |
generateProjectId,
|
| 21 |
generateSessionId,
|
| 22 |
-
generateRequestId
|
|
|
|
| 23 |
}
|
|
|
|
| 16 |
const randomNum = Math.random().toString(36).substring(2, 7);
|
| 17 |
return `${randomAdj}-${randomNoun}-${randomNum}`;
|
| 18 |
}
|
| 19 |
+
|
| 20 |
+
function generateToolCallId() {
|
| 21 |
+
return `call_${randomUUID().replace(/-/g, '')}`;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
export {
|
| 25 |
generateProjectId,
|
| 26 |
generateSessionId,
|
| 27 |
+
generateRequestId,
|
| 28 |
+
generateToolCallId
|
| 29 |
}
|