Skip to content

[Bug]: fopen(https://172.66.0.243/v1/chat/completions): Failed to open stream: HTTP request failed! #534

Open
@tw-ict

Description

@tw-ict

Description

When doing the request, i sometimes get a error thrown "fopen(https://172.66.0.243/v1/chat/completions): Failed to open stream: HTTP request failed!"

Steps To Reproduce

public static function chat(string $systemChat, string $userChat, string $responseType = 'text')
  {

    $parameters = [
      'model' => 'gpt-4o-mini',
      'messages' => [
        ['role' => 'system', 'content' => $systemChat],
        ['role' => 'user', 'content' => $userChat],
      ],
      'temperature' => 0.002,
    ];

    if ($responseType == 'json') {
      // Tell OpenAI to return the response as a JSON object
      $parameters['response_format'] = ['type' => 'json_object'];
    }
    $client = self::getClient();
    $result = $client->chat()->create($parameters);

    if ($responseType == 'json') {
      return json_decode($result->choices[0]->message->content, true);
    }


    return $result->choices[0]->message->content;
  }

OpenAI PHP Client Version

V0.10.3

PHP Version

8.3.1

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions