chore: docs todo
This commit is contained in:
@@ -25,10 +25,9 @@ export function zodToOpenAITool(name: string, tool: Tool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Although we require tool calls to be returned following the specified format,
|
* Although some models cannot guarantee correct response. Common issues are fixable:
|
||||||
* some models cannot guarantee correctness:
|
* - Instead of returning a proper tool call. Return the tool call parameters in the message content.
|
||||||
* - Don't return tool calls at all but instead return tool call parameters as a JSON string in the message.
|
* - Returned tool calls or messages don't follow the nested MacroToolInput format.
|
||||||
* - Returned tool calls or messages don't follow the correct nested MacroToolInput format.
|
|
||||||
*/
|
*/
|
||||||
export function lenientParseMacroToolCall(
|
export function lenientParseMacroToolCall(
|
||||||
responseData: any,
|
responseData: any,
|
||||||
@@ -77,11 +76,7 @@ export function lenientParseMacroToolCall(
|
|||||||
arg = toolCall?.arguments ?? null
|
arg = toolCall?.arguments ?? null
|
||||||
|
|
||||||
if (arg && toolCall.name !== 'AgentOutput') {
|
if (arg && toolCall.name !== 'AgentOutput') {
|
||||||
// throw new InvokeError(
|
// TODO: check if toolCall.name is a valid action name
|
||||||
// InvokeErrorType.INVALID_TOOL_ARGS,
|
|
||||||
// `Expected function name "AgentOutput", got "${toolCall.name}"`,
|
|
||||||
// null
|
|
||||||
// )
|
|
||||||
// case: instead of AgentOutput, the model returned a action name as tool call
|
// case: instead of AgentOutput, the model returned a action name as tool call
|
||||||
console.log(chalk.yellow('lenientParseMacroToolCall: #1 fixing incorrect tool call'))
|
console.log(chalk.yellow('lenientParseMacroToolCall: #1 fixing incorrect tool call'))
|
||||||
let tmpArg
|
let tmpArg
|
||||||
@@ -137,6 +132,7 @@ export function lenientParseMacroToolCall(
|
|||||||
}
|
}
|
||||||
} else if (parsedArgs.type && parsedArgs.function) {
|
} else if (parsedArgs.type && parsedArgs.function) {
|
||||||
// case: upper level function call format provided. only keep its arguments
|
// case: upper level function call format provided. only keep its arguments
|
||||||
|
// TODO: check if function name is a valid action name
|
||||||
if (parsedArgs.function.name !== 'AgentOutput')
|
if (parsedArgs.function.name !== 'AgentOutput')
|
||||||
throw new InvokeError(
|
throw new InvokeError(
|
||||||
InvokeErrorType.INVALID_TOOL_ARGS,
|
InvokeErrorType.INVALID_TOOL_ARGS,
|
||||||
@@ -148,6 +144,7 @@ export function lenientParseMacroToolCall(
|
|||||||
parsedArgs = parsedArgs.function.arguments
|
parsedArgs = parsedArgs.function.arguments
|
||||||
} else if (parsedArgs.name && parsedArgs.arguments) {
|
} else if (parsedArgs.name && parsedArgs.arguments) {
|
||||||
// case: upper level function call format provided. only keep its arguments
|
// case: upper level function call format provided. only keep its arguments
|
||||||
|
// TODO: check if function name is a valid action name
|
||||||
if (parsedArgs.name !== 'AgentOutput')
|
if (parsedArgs.name !== 'AgentOutput')
|
||||||
throw new InvokeError(
|
throw new InvokeError(
|
||||||
InvokeErrorType.INVALID_TOOL_ARGS,
|
InvokeErrorType.INVALID_TOOL_ARGS,
|
||||||
@@ -159,6 +156,7 @@ export function lenientParseMacroToolCall(
|
|||||||
parsedArgs = parsedArgs.arguments
|
parsedArgs = parsedArgs.arguments
|
||||||
} else {
|
} else {
|
||||||
// case: only action parameters provided, wrap into MacroToolInput
|
// case: only action parameters provided, wrap into MacroToolInput
|
||||||
|
// TODO: check if action name is valid
|
||||||
console.log(chalk.yellow('lenientParseMacroToolCall: #5 fixing incorrect tool call'))
|
console.log(chalk.yellow('lenientParseMacroToolCall: #5 fixing incorrect tool call'))
|
||||||
parsedArgs = { action: parsedArgs } as MacroToolInput
|
parsedArgs = { action: parsedArgs } as MacroToolInput
|
||||||
}
|
}
|
||||||
@@ -185,6 +183,8 @@ export function lenientParseMacroToolCall(
|
|||||||
const actionName = Object.keys(action)[0] || 'unknown'
|
const actionName = Object.keys(action)[0] || 'unknown'
|
||||||
const actionArgs = JSON.stringify(action[actionName] || 'unknown')
|
const actionArgs = JSON.stringify(action[actionName] || 'unknown')
|
||||||
|
|
||||||
|
// TODO: check if action name is valid. give a readable error message
|
||||||
|
|
||||||
throw new InvokeError(
|
throw new InvokeError(
|
||||||
InvokeErrorType.INVALID_TOOL_ARGS,
|
InvokeErrorType.INVALID_TOOL_ARGS,
|
||||||
`Tool arguments validation failed: action "${actionName}" with args ${actionArgs}`,
|
`Tool arguments validation failed: action "${actionName}" with args ${actionArgs}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user