dfinke / PSAI

PowerShell AI module. Brings OpenAI to the console and scripts
MIT License
45 stars 7 forks source link

AzureOpenAI not working in 0.2.0 #12

Closed Agazoth closed 1 day ago

Agazoth commented 1 week ago

When running with AzureOpenAI as OAIProvider, the module fails:

Invoke-OAIChat -UserInput "can you give me a list of the 10 largest countries in Africa and their capitals" -Instructions "You are a helpful chatbot"
Exception: C:\Users\axel\OneDrive\Dokumenter\PowerShell\Modules\psai\0.2.0\Private\Invoke-OAIBeta.ps1:137
Line |
 137 |          throw $targetError
     |          ~~~~~~~~~~~~~~~~~~
     | Response status code does not indicate success: 400 (Bad Request).
dfinke commented 1 week ago

Sorry, could you say a bit more.

Yes, it will throw an error if you set the provider to Azure and not set the endpoints.

Agazoth commented 1 week ago

I have set my AzOAISecrets to: image

And I ran:

Set-OAIProvider -Provider AzureOpenAI

Then the error gets generated, when the threads endpoint is called: image

The following change to New-OAIThread fixes the error:

    $body = $OAIProvider -eq 'OpenAI' ? @{
        messages       = $Messages
        tool_resources = $ToolResources
        metadata       = $Metadata
    } : ''

The Azure endpoint does not allow any body content when calliing the threads endpoint. The configuration with messages and tools is done on the assistant.

dfinke commented 1 week ago

Thanks for getting to the root cause!

I've gone off the OpenAI API docs. I was under the impression that when Microsoft onboarded their new models the API would be the same.

This seems like a breaking issue. I see your deployment name is GPT-4o.

I have gpt4-o deploy and will try.

Agazoth commented 1 week ago

I also tried with my GPT-35-Turbo and GPT-4-Turbo deplotments. They work with the fix too.

dfinke commented 1 week ago

Thanks for checking. Wonder for 3.5 and turbo if it works with the body. They may have tightened up the process.

Need to think about this. Seems like it would break others in the community too and don't know if they do a if() around the code.

I am hoping to avoid special casing these sort of things. Or come up with a more robust way to handle it.

dfinke commented 1 week ago

Strange. I interpreted the docs that the new-oaithread params go into the body.

Guess I jumped the gun thinking this was in Azure.

Not the best, this means the OpenAI interface will have newer APIs than what is deployed by Microsoft.

https://platform.openai.com/docs/api-reference/threads/createThread

image

The only difference is I'll check Get-OAIProvider

body = (Get-OAIProvider) -eq 'OpenAI' ? @{
        messages       = $Messages
        tool_resources = $ToolResources
        metadata       = $Metadata
    } : ''
dfinke commented 1 week ago

@Agazoth thanks for chasing that down. Published a new release.

https://github.com/dfinke/PSAI/releases/tag/v0.2.1