Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add client factory #75

Merged
merged 9 commits into from
Mar 17, 2023
Merged

feat: add client factory #75

merged 9 commits into from
Mar 17, 2023

Conversation

gehrisandro
Copy link
Collaborator

This adds the ability to configure the client instance via a new factory:

Excerpt from the updated README.

$yourApiKey = getenv('YOUR_API_KEY');

$client = OpenAI::factory()
    ->withApiKey($yourApiKey)
    ->withOrganization('your-organization') // default: null
    ->withBaseUrl('openai.example.com/v1') // default: api.openai.com/v1
    ->withHttpHeader('X-My-Header', 'foo')
    ->withHttpClient(new \GuzzleHttp\Client([])) // default: HTTP client found using PSR-18 HTTP Client Discovery
    ->make();

This change is breaking as the "guzzlehttp/guzzle" has been removed. Existing projects without an explicitly installed HTTP client have to install the Guzzle Client manually:

composer require guzzlehttp/guzzle

With this change we can resolve various issues:

@gehrisandro
Copy link
Collaborator Author

I am going to fix the failing checks later today...

@gehrisandro
Copy link
Collaborator Author

@GromNaN @nicolas-grekas What do you think? Does this what you need for the symfony integration?

@GromNaN
Copy link
Contributor

GromNaN commented Mar 14, 2023

What do you think? Does this what you need for the symfony integration?

The factory is useful pattern, but personally I prefer parameters (and named parameters), this is less methods to define and call.

README.md Outdated Show resolved Hide resolved
@seebyyu
Copy link

seebyyu commented Mar 15, 2023

@gehrisandro Hello, please adjust it as soon as possible openai-php/laravel

composer.json Outdated Show resolved Hide resolved
composer.json Show resolved Hide resolved
@gehrisandro gehrisandro marked this pull request as ready for review March 17, 2023 19:27
@gehrisandro gehrisandro merged commit ce8a7c7 into main Mar 17, 2023
gehrisandro added a commit that referenced this pull request Mar 20, 2023
---------

Co-authored-by: Nuno Maduro <enunomaduro@gmail.com>
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.

6 participants