openai-php / openai-php/client

[Bug]: Undefined array key "usage" with Vision endpoint on Azure

Open
#338 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Non-OpenAI Model
Dominant language
PHP
Stars
5.8k
Forks
679
Avg merge
19m
Merged PRs (30d)
2

Description

Description

I'm trying to use vision on Azure, this was working before.

It seems that Azure has changed the format of their response for the Vision endpoint.

I am creating the client with the factory etc. But since today the code that had been working has stopped working.
This results in the error Undefined array key "usage"
I'm running the latests version of the client.

Steps To Reproduce
         $baseUri = 'https://tellet-azure-sweden.openai.azure.com/openai/deployments/tellet-gpt-4-vision-preview';
        
        $client = OpenAI::factory()
        ->withBaseUri($baseUri)
        ->withHttpClient(new \GuzzleHttp\Client(['timeout' => 300, 'connect_timeout' => 300]))
        ->withHttpHeader('api-key', $apiKey)
        ->withQueryParam('api-version', '2023-12-01-preview')
        ->make();
        
         $base64Image = $this->imageToBase64($image);
         $encoded = 'data:image/jpeg;base64,'.$base64Image;

    $imageArray[] = [
        'type' => 'text',
        'text' => 'Analyse this photograph and provide a detailed description of its contents. Focus on identifying and listing all visible items, with particular attention to food items present. '
    ];
    
    $imageArray[] = [
        'type' => 'image_url',
        'image_url' => ['url' => $encoded]
    ];

    $messagesArray = array();
    $messagesArray[] = [
        'role' => 'user',
        'content' => $imageArray
    ];
    
    $settings['messages'] = $messagesArray;
    $settings['max_tokens'] = 1200;
    $settings['messages'] = $messagesArray;
    $response = $client->chat()->create($settings);
OpenAI PHP Client Version

v0.8.4

PHP Version

8.1

Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the chat()->create entry point and reproduce the request against the Azure Vision endpoint using the configuration and image payload in the issue. Inspect where the response's usage field is accessed; done means the documented Azure response format no longer causes an undefined array key error, with a regression test if the existing test structure identifies a suitable location.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, php
Domain
api, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.