Skip to content

Commit 49af2be

Browse files
committed
PowerShell 5.1 - 400 bad request error when calling the tool: get_current_weather
Fixes #241
1 parent 876ec61 commit 49af2be

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

code365scripts.openai/Public/New-ChatGPTConversation.ps1

+11-4
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ function New-ChatGPTConversation {
289289
}
290290
)
291291

292+
$messages += $systemPrompt
293+
292294
Write-Verbose "$($systemPrompt|ConvertTo-Json -Depth 10)"
293295

294296
while ($true) {
@@ -510,8 +512,14 @@ function New-ChatGPTConversation {
510512
while ($response.choices -and $response.choices[0].message.tool_calls) {
511513
# add the assistant message
512514
$this_message = $response.choices[0].message
513-
$body.messages += $this_message
515+
# $body.messages += $this_message
514516
$tool_calls = $this_message.tool_calls
517+
518+
$messages += [pscustomobject]@{
519+
role = "assistant"
520+
content = ""
521+
tool_calls = @($tool_calls)
522+
}
515523

516524
foreach ($tool in $tool_calls) {
517525
Write-Host ("`r$($resources.function_call): $($tool.function.name)" + (" " * 50)) -NoNewline
@@ -532,6 +540,8 @@ function New-ChatGPTConversation {
532540

533541
$body.messages = $messages
534542
$params.Body = ($body | ConvertTo-Json -Depth 10)
543+
Write-Verbose $params.Body
544+
535545
$response = Invoke-UniWebRequest $params
536546
}
537547

@@ -549,9 +559,6 @@ function New-ChatGPTConversation {
549559
Write-Error ($_.Exception.Message)
550560
}
551561
}
552-
553-
554-
555562
}
556563

557564
}

0 commit comments

Comments
 (0)