Skip to content

Fix: Clarify HTTP client variable in factory example#132

Merged
Plytas merged 3 commits into
google-gemini-php:mainfrom
rema424:fix/readme-http-client-example
Jul 11, 2025
Merged

Fix: Clarify HTTP client variable in factory example#132
Plytas merged 3 commits into
google-gemini-php:mainfrom
rema424:fix/readme-http-client-example

Conversation

@rema424

@rema424 rema424 commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Summary

  • Fixed undefined $client variable reference in README factory example
  • Explicitly defined the client variable for better clarity

Description

The README example for configuring the Gemini client factory contained a reference to an undefined $client variable within the withStreamHandler method. This change explicitly defines the $client variable when configuring withHttpClient to make the example clearer and prevent potential confusion for users.

Changes

  • Added explicit variable assignment: $client = new \GuzzleHttp\Client([]) in the withHttpClient method call

Test plan

  • Verified the example code is syntactically correct
  • Confirmed the change improves documentation clarity

This is a documentation-only change that improves the code example's clarity.

The example in the README was using an undefined $client variable
within the withStreamHandler method. This change explicitly defines
the $client variable when configuring withHttpClient to make the
example clearer and prevent potential confusion.
@Plytas

Plytas commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator

Thanks! But maybe we could use a different name for the variable like $guzzleClient as $client is already being defined above?

@Plytas

Plytas commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator

Also to note. You might not need the withHttpClient() call if it's the same as default

client/src/Factory.php

Lines 146 to 148 in 84ffe3d

if ($client instanceof GuzzleClient) {
return fn (RequestInterface $request): ResponseInterface => $client->send($request, [RequestOptions::STREAM => true]);
}

rema424 added 2 commits July 11, 2025 18:15
Renamed the HTTP client variable from $client to $guzzleClient to
avoid confusion with the Gemini client instance and make the code
example more explicit about which client is being referenced.
Added a timeout configuration to the Guzzle client example to
demonstrate best practices for HTTP client configuration. This
helps users understand how to configure client options properly.
@rema424

rema424 commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

@Plytas I've improved the example by renaming the variable to $guzzleClient for clarity and adding a timeout configuration. What do you think?

    ->withHttpClient($guzzleClient = new \GuzzleHttp\Client(['timeout' => 30]))  // default: HTTP client found using PSR-18 HTTP Client Discovery
    ->withStreamHandler(fn(RequestInterface $request): ResponseInterface => $guzzleClient->send($request, [
        'stream' => true // Allows to provide a custom stream handler for the http client.
    ]))

@Plytas
Plytas merged commit b8da8a2 into google-gemini-php:main Jul 11, 2025
10 checks passed
@Plytas

Plytas commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator

Awesome, thanks!

@rema424
rema424 deleted the fix/readme-http-client-example branch July 11, 2025 09:21
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