From 2299f8c56eaa6cced7205b30dc7084325de6564a Mon Sep 17 00:00:00 2001 From: Stanislas Lange Date: Sat, 7 Dec 2024 00:54:52 +0100 Subject: [PATCH] feat: add base URI configuration with OPENAI_BASE_URI --- README.md | 9 +++++++++ config/openai.php | 12 ++++++++++++ src/ServiceProvider.php | 1 + 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 57cc5a8..b78a3c2 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,15 @@ for a response. By default, the client will time out after 30 seconds. OPENAI_REQUEST_TIMEOUT= ``` +### Base URI + +The base URI may be used to specify the base URI of the OpenAI API. +By default, the client will use the OpenAI API base URI. + +```env +OPENAI_BASE_URI= +``` + ## Usage For usage examples, take a look at the [openai-php/client](https://github.com/openai-php/client) repository. diff --git a/config/openai.php b/config/openai.php index 67806b4..7f89c60 100644 --- a/config/openai.php +++ b/config/openai.php @@ -25,4 +25,16 @@ */ 'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30), + + /* + |-------------------------------------------------------------------------- + | Base URI + |-------------------------------------------------------------------------- + | + | The base URI is the root URL that the client will use to make requests. + | By default, the client will use the OpenAI API base URI. + | The schema can be specified (http or https). + | e.g.: http://localhost:11434/v1 for a local Ollama instance. + */ + 'base_uri' => env('OPENAI_BASE_URI', 'api.openai.com/v1'), ]; diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index a6e6808..94eecc9 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -35,6 +35,7 @@ public function register(): void ->withOrganization($organization) ->withHttpHeader('OpenAI-Beta', 'assistants=v2') ->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)])) + ->withBaseUri(config('openai.base_uri')) ->make(); });