Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expect delta to not exist #408

Merged
merged 1 commit into from
May 28, 2024

Conversation

beliven-daniele-sarnari
Copy link
Contributor

What:

  • Bug Fix
  • New Feature

Description:

On Azure, with Asynchronous Filter enabled, in the stream a different packet can exist and throw the following 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

Normal packet:

array(3) {
  ["delta"]=>
  array(1) {
    ["content"]=>
    string(6) "amento"
  }
  ["finish_reason"]=>
  NULL
  ["index"]=>
  int(0)
}

Asynchronous Filter packet:

array(4) {
  ["content_filter_offsets"]=>
  array(3) {
    ["check_offset"]=>
    int(61342)
    ["start_offset"]=>
    int(61342)
    ["end_offset"]=>
    int(62102)
  }
  ["content_filter_results"]=>
  array(4) {
    ["hate"]=>
    array(2) {
      ["filtered"]=>
      bool(false)
      ["severity"]=>
      string(4) "safe"
    }
    ["self_harm"]=>
    array(2) {
      ["filtered"]=>
      bool(false)
      ["severity"]=>
      string(4) "safe"
    }
    ["sexual"]=>
    array(2) {
      ["filtered"]=>
      bool(false)
      ["severity"]=>
      string(4) "safe"
    }
    ["violence"]=>
    array(2) {
      ["filtered"]=>
      bool(false)
      ["severity"]=>
      string(4) "safe"
    }
  }
  ["finish_reason"]=>
  NULL
  ["index"]=>
  int(0)
}

Related:

#407

@gehrisandro
Copy link
Collaborator

Checkout discussion here: #407

@gehrisandro gehrisandro self-assigned this May 27, 2024
@gehrisandro gehrisandro merged commit 7b61b9b into openai-php:main May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants