You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Awesome package, thanks for it!! One issue am facing is that I could not mock the response from the images-resource to return me b64_json encoded image. It instead returns me a response with a url no matter what i pass in
In my controller, I just call something like (real time facade)
$response = ImageClient::generate('can you generate for me a cover image for a book about mars exploding');
which works fine - ie, it returns me an image in the format b64_json & I get that base 64 string as expected, do some magic & save the image to laravel local disk storage
However, in my tests, i have the following; (i've shown the relevant imports here)
useOpenAI\Laravel\Facades\OpenAI;
useOpenAI\Responses\Images\CreateResponse;
useTests\TestCase;
classCoverImageClientTestextendsTestCase
{
publicfunctiontest_calls_the_images_api(): void
{
OpenAI::fake([
CreateResponse::fake(
['data' => [['b64_json' => 'b64_string']]],
)
]);
$prompt = 'can you generate for me a cover image for a book about mars exploding';
$response = ImageClient::generate($prompt);
dd($response);
}
}
In the dd($response) I added there in the test, the response has the url & b64_json properties that have the following values url = "https://openai.com/fake-image.png" & b64_json = ""
I was able to have the response have the b64_json that i passed by looking at the logic here in this foreach & tweaking the CreateResponseFixture ATTRIBUTES to have the b64_json included as anything, just made it null for my source diving - to see how it goes
Second on this. I have the same issue. @RrNn FYI I fixed this issue by editing the following file: vendor/openai-php/client/src/Testing/Responses/Fixtures/Images/CreateResponseFixture.php and adding the
'b64_json' => 'test_string' by myself in the fixture.
Description
Awesome package, thanks for it!! One issue am facing is that I could not mock the response from the images-resource to return me
b64_json
encoded image. It instead returns me a response with aurl
no matter what i pass inSteps To Reproduce
My steps are;
I have a class
In my controller, I just call something like (real time facade)
which works fine - ie, it returns me an image in the format
b64_json
& I get that base 64 string as expected, do some magic & save the image to laravel local disk storageHowever, in my tests, i have the following; (i've shown the relevant imports here)
In the
dd($response)
I added there in the test, the response has theurl
&b64_json
properties that have the following valuesurl
="https://openai.com/fake-image.png"
&b64_json
=""
The
dd
generally looks like this;I was able to have the response have the
b64_json
that i passed by looking at the logic here in this foreach & tweaking the CreateResponseFixture ATTRIBUTES to have theb64_json
included as anything, just made itnull
for my source diving - to see how it goes& after doing this tweak, I could get my mock
b64_json
string returned.Not sure whether thats the fix or whether I am missing something, but thats the issue I am facing rn
OpenAI PHP Client Version
v0.8.0-beta.1
PHP Version
8.2.16
Notes
No response
The text was updated successfully, but these errors were encountered: