client icon indicating copy to clipboard operation
client copied to clipboard

[Bug]: failed to upload files with Azure OpenAI

Open chris-lee-lb opened this issue 6 months ago • 1 comments

Description

Currently can not upload files with Azure OpenAI successfully. Will receive this error messages.

{
  "error": {
    "code": "invalidPayload",
    "message": "purpose contains an invalid purpose."
  }
}

Steps To Reproduce

<?php

$client = OpenAI::factory()
    ->withBaseUri('<azure_openai_endpoint>')
    ->withHttpHeader('api-key', '<azure_openai_api_key>')
    ->withQueryParam('api-version', '2024-05-01-preview')
    ->withHttpClient(new \GuzzleHttp\Client(['timeout' => 60]))
    ->make();

$client->files()->upload([
    'file'    => fopen('<file_path>', 'r'),
    'purpose' => 'assistants',
]);

OpenAI PHP Client Version

v0.10.1

PHP Version

8.3.10

Notes

After further root cause analysis, it was discovered that the issue was due to the Azure OpenAI API Server being unable to correctly parse the content-length in the multipart/form-data request body sent by the OpenAI HTTP client (came from this class - Http\Message\MultipartStream\MultipartStreamBuilder). Once this content-length is removed, the upload works as expected. Currently, there is a related pull request (https://github.com/guzzle/psr7/pull/581) for the GuzzleHttp Client that is awaiting merge.

chris-lee-lb avatar Aug 10 '24 09:08 chris-lee-lb