client icon indicating copy to clipboard operation
client copied to clipboard

[Bug]: Warning: undefined array key 'id' using chat()

Open the-fermi-paradox opened this issue 8 months ago • 4 comments

Description

Another error with using the client to interact with Gemini - once again, Google doesn't provide a field (id) that the client expects to be present in the response.

Steps To Reproduce

return $client->chat()->create([
            'model' => 'gemini-2.0-flash',
            'messages' => [
                ['role' => 'user', 'content' => $text],
            ],
        ]);

OpenAI PHP Client Version

v0.10.3

PHP Version

8.4

Notes

No response

the-fermi-paradox avatar Apr 27 '25 15:04 the-fermi-paradox

I wonder whether marking these fields as nullable is a long term solution. It's clear that LLM providers are:

  1. eager to provide support for the OpenAI API
  2. unwilling to present the same interfaces for responses as OpenAI does

It's clear OpenAI never intended the id field of all things to be null. Providing support for Gemini (and other providers) degrades the type safety of the responses, yet clearly is a business need we need to support. Maybe we need a better way to support these third-party LLM providers. Something like a 'GoogleResponse' class whose interface we can change as Google's OpenAI API implementation does.

the-fermi-paradox avatar Apr 27 '25 15:04 the-fermi-paradox

I have been debating this exact problem and haven't really come up with a good solution, but I do like the different response class. My grip is kinda with Google.

There is like 10+ "drop-in" replacements for AWS S3 and they all have near perfect parity with S3. I haven't had a single issue with Wasabi or MinIO with my existing AWS/S3 PHP library. I don't understand how these other models can provide an OpenAI compatibility layer and then not match it.

I was even brainstorming a dumb poly-fill that was like "google_fake_uuid_do_not_use_{uuid}"

iBotPeaches avatar Apr 27 '25 16:04 iBotPeaches

Any update here?

jtsternberg avatar Jun 25 '25 14:06 jtsternberg

Maybe this has already been solved? See https://github.com/LLPhant/LLPhant/pull/359

f-lombardo avatar Jun 25 '25 20:06 f-lombardo