openai-php / client

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

[Bug]: system_fingerprint is always null when using CreateResponse.fake #300

Closed elliotmassen closed 9 months ago

elliotmassen commented 9 months ago

Description

When I'm creating a fake chat response via CreateResponse.fake and I attempt to override the system fingerprint field, it is always set to null in the client's response. This means that I'm unable to use the fake method to test code that relies on system_fingerprint. The current workaround is to use CreateResponse.from and provide the full attributes array (including the system fingerprint).

Steps To Reproduce

<?php

use OpenAI\Responses\Chat\CreateResponse;
use OpenAI\Testing\ClientFake;

// Create a fake client and override the `system_fingerprint` field
$client = new ClientFake([
  CreateResponse::fake([
    'system_fingerprint' => 'abcxyz123'
  ]),
]);

// Make a call to the fake client
$response = $client->chat()->create([
  'model' => 'gpt-4',
  'messages' => [
    ['role' => 'system', 'content' => 'Some system prompt'],
    ['role' => 'user', 'content' => 'Some user prompt']
  ]
]);

// The response's system fingerprint property is `null`
var_dump($response->systemFingerprint);

OpenAI PHP Client Version

v0.8.0

PHP Version

8.1.24

Notes

It appears that because the system_fingerprint field isn't specified in the CreateResponseFixture, it can't be overwritten by Fakeable.buildAttributes. It seems that support for system_fingerprint was added in November, but it wasn't included in the fixture.

gehrisandro commented 9 months ago

Fixed in https://github.com/openai-php/client/pull/308