mkht / PSOpenAI

PowerShell module for OpenAI API.
MIT License
41 stars 11 forks source link

Fix Auth on PS 5.1 #11

Closed potatoqualitee closed 6 months ago

potatoqualitee commented 6 months ago

Running the example in the Guides for VectorStore worked entirely on Core but only up until the thread run on PS 5.1. Then I'd get:

Start-ThreadRun -Stream -Message "how do i get started?" -VectorStoresForFileSearch xyz -MaxCompletionTokens 2048 -Assistant xyz
Invoke-OpenAIAPIRequestSSE : OpenAI API returned an 401 (Unauthorized) Error: Missing bearer or basic authentication
in header
At C:\github\PSOpenAI\Private\Invoke-OpenAIAPIRequest.ps1:150 char:9
+         Invoke-OpenAIAPIRequestSSE @params
mkht commented 6 months ago

Good catch!

This issue is most noticeable in PowerShell 5.1, but also occurs in PowerShell 7 when using -Stream.

Fundamentally, this is caused by Start-ThreadRun not setting the AuthType parameter to the correct value. Other functions set it correctly.

I will make a few changes to your PR.