Skip to content

Commit

Permalink
perf: tool value type and complections body size (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Apr 26, 2024
1 parent c608f86 commit 89ab17e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const runToolWithFunctionCall = async (
> = {};
item.toolParams.forEach((item) => {
properties[item.key] = {
type: 'string',
type: item.valueType || 'string',
description: item.toolDescription || ''
};
});
Expand All @@ -76,6 +76,18 @@ export const runToolWithFunctionCall = async (
messages,
maxTokens: toolModel.maxContext - 500 // filter token. not response maxToken
});
const formativeMessages = filterMessages.map((item) => {
if (item.role === ChatCompletionRequestMessageRoleEnum.Assistant && item.function_call) {
return {
...item,
function_call: {
name: item.function_call?.name,
arguments: item.function_call?.arguments
}
};
}
return item;
});

/* Run llm */
const ai = getAIApi({
Expand All @@ -87,7 +99,7 @@ export const runToolWithFunctionCall = async (
model: toolModel.model,
temperature: 0,
stream,
messages: filterMessages,
messages: formativeMessages,
functions,
function_call: 'auto'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const runToolWithToolChoice = async (
> = {};
item.toolParams.forEach((item) => {
properties[item.key] = {
type: 'string',
type: item.valueType || 'string',
description: item.toolDescription || ''
};
});
Expand All @@ -86,7 +86,34 @@ export const runToolWithToolChoice = async (
messages,
maxTokens: toolModel.maxContext - 300 // filter token. not response maxToken
});

const formativeMessages = filterMessages.map((item) => {
if (item.role === 'assistant' && item.tool_calls) {
return {
...item,
tool_calls: item.tool_calls.map((tool) => ({
id: tool.id,
type: tool.type,
function: tool.function
}))
};
}
return item;
});
// console.log(
// JSON.stringify(
// {
// ...toolModel?.defaultConfig,
// model: toolModel.model,
// temperature: 0,
// stream,
// messages: formativeMessages,
// tools,
// tool_choice: 'auto'
// },
// null,
// 2
// )
// );
/* Run llm */
const ai = getAIApi({
timeout: 480000
Expand All @@ -97,7 +124,7 @@ export const runToolWithToolChoice = async (
model: toolModel.model,
temperature: 0,
stream,
messages: filterMessages,
messages: formativeMessages,
tools,
tool_choice: 'auto'
},
Expand Down
3 changes: 2 additions & 1 deletion packages/service/core/workflow/dispatch/tools/http468.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
headers: Object.keys(headers).length > 0 ? headers : undefined,
httpResult: rawResponse
},
[DispatchNodeResponseKeyEnum.toolResponses]: results,
[DispatchNodeResponseKeyEnum.toolResponses]:
Object.keys(results).length > 0 ? results : rawResponse,
[NodeOutputKeyEnum.httpRawResponse]: rawResponse,
...results
};
Expand Down
1 change: 1 addition & 0 deletions projects/app/src/pages/api/common/file/uploadImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

export const config = {
api: {
sizeLimit: '10mb',
bodyParser: {
sizeLimit: '16mb'
}
Expand Down

0 comments on commit 89ab17e

Please sign in to comment.