openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.99k stars 523 forks source link

[Bug]: Azure Asynchronous Filter #407

Closed beliven-daniele-sarnari closed 6 months ago

beliven-daniele-sarnari commented 6 months ago

Description

Enabling Asynchronous Filter will cause a Undefined array key "delta" error

ErrorException

  Undefined array key "delta"

  at vendor/openai-php/client/src/Responses/Chat/CreateStreamedResponseChoice.php:23
     19▕     public static function from(array $attributes): self
     20▕     {
     21▕         return new self(
     22▕             $attributes['index'],
  ➜  23▕             CreateStreamedResponseDelta::from($attributes['delta']),
     24▕             $attributes['finish_reason'] ?? null,
     25▕         );
     26▕     }
     27▕

      +2 vendor frames

  3   [internal]:0
      OpenAI\Responses\Chat\CreateStreamedResponse::OpenAI\Responses\Chat\{closure}()
      +2 vendor frames

Steps To Reproduce

  1. Enable Asynchronous Filter on Azure OpenAI Studio image

  2. Create a OpenAI client that works with Azure

    $this->clientGPT4 = OpenAI::factory()
            ->withBaseUri("{$endpoint}/openai/deployments/{$deploymentIdGPT4}")
            ->withHttpHeader('api-key', $apiKey)
            ->withQueryParam('api-version', $apiVersion)
            ->make();
  3. Use the chat()->createStreamed() function

    return $this->clientGPT4->chat()->createStreamed([
            'messages' => $messages,
        ]);

OpenAI PHP Client Version

v0.9.1

PHP Version

8.3.6

Notes

No response

gehrisandro commented 6 months ago

Hi @beliven-daniele-sarnari

Thank you for the issue and PR.

The Azure API and the default OpenAI API are becoming increasingly divergent. Not sure if it is the right way to modify this package more and more, because this will make the response objects harder to use in context of the original OpenAI and still not fully support OpenAI on Azure.

We will have to discuss how to proceed here.

beliven-daniele-sarnari commented 6 months ago

Hi @beliven-daniele-sarnari

Thank you for the issue and PR.

The Azure API and the default OpenAI API are becoming increasingly divergent. Not sure if it is the right way to modify this package more and more, because this will make the response objects harder to use in context of the original OpenAI and still not fully support OpenAI on Azure.

We will have to discuss how to proceed here.

Hello @gehrisandro, i fully agree with you. Imho a dedicated repository would be the right choice, but that would mean that two repositories needs to be updated and this generates further work on your side. What do you think is the best solution? Maybe a dedicated namespace inside this repository?

Meanwhile, can we merge the pull request so we can continue working? I would like to avoid forking two repositories (we use Laravel) just for one line of code :/

gehrisandro commented 6 months ago

I have merged your PR, as it affects the direct OpenAI users, not really. I will make a new release the next days.

But still, I think having a dedicated package would be the best choice. Having two different packages is of course a maintenance burden, but I can't think of a good way to have both in a single package.

Atm, I don't have time to create (and test) a full Azure implementation, but I will keep this in mind, for later. If you are interested in helping me out, I would love to hear from you 🙏🏼

berott commented 5 months ago

Thank you for this PR and the merge!

@gehrisandro I'm looking forward to the release :-) Is there a possibility to help?