Skip to content

Commit 73a50c0

Browse files
authored
Merge pull request #105 from dfinke/try-catch-for-function-call
Wrap tool invocation in Invoke-OAIFunctionCall with try/catch and ret…
2 parents 69bd5f4 + f5aacf1 commit 73a50c0

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Public/Invoke-OAIFunctionCall.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ function Invoke-OAIFunctionCall {
2626
Write-Verbose "$toolFunctionName $($toolFunctionArgs | ConvertTo-Json -Compress)"
2727

2828
if (Get-Command $toolFunctionName -ErrorAction SilentlyContinue) {
29-
$result = & $toolFunctionName @toolFunctionArgs
29+
try {
30+
$result = & $toolFunctionName @toolFunctionArgs
31+
}
32+
catch {
33+
$result = "Error invoking function $($toolFunctionName) with arguments $($toolCall.function.arguments): $_"
34+
}
3035
}
3136
else {
3237
$result = "Function $toolFunctionName not found"

0 commit comments

Comments
 (0)