File tree Expand file tree Collapse file tree 4 files changed +61
-3
lines changed Expand file tree Collapse file tree 4 files changed +61
-3
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,23 @@ OPENAI_API_KEY=
7171OPENAI_ORGANIZATION=
7272```
7373
74+ ### OpenAI Project
75+
76+ For implementations that require a project ID, you can specify
77+ the OpenAI project ID in your environment variables.
78+
79+ ``` env
80+ OPENAI_PROJECT=proj_...
81+ ```
82+
83+ ### OpenAI API Base URL
84+
85+ The base URL for the OpenAI API. By default, this is set to ` api.openai.com/v1 ` .
86+
87+ ``` env
88+ OPENAI_BASE_URL=
89+ ```
90+
7491### Request Timeout
7592
7693The timeout may be used to specify the maximum number of seconds to wait
Original file line number Diff line number Diff line change 1515 'api_key ' => env ('OPENAI_API_KEY ' ),
1616 'organization ' => env ('OPENAI_ORGANIZATION ' ),
1717
18+ /*
19+ |--------------------------------------------------------------------------
20+ | OpenAI API Project
21+ |--------------------------------------------------------------------------
22+ |
23+ | Here you may specify your OpenAI API project. This is used optionally in
24+ | situations where you are using a legacy user API key and need association
25+ | with a project. This is not required for the newer API keys.
26+ */
27+ 'project ' => env ('OPENAI_PROJECT ' ),
28+
29+ /*
30+ |--------------------------------------------------------------------------
31+ | OpenAI Base URL
32+ |--------------------------------------------------------------------------
33+ |
34+ | Here you may specify your OpenAI API base URL used to make requests. This
35+ | is needed if using a custom API endpoint. Defaults to: api.openai.com/v1
36+ */
37+ 'base_uri ' => env ('OPENAI_BASE_URL ' ),
38+
1839 /*
1940 |--------------------------------------------------------------------------
2041 | Request Timeout
Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ private function copyConfig(): void
7878
7979 private function addEnvKeys (string $ envFile ): void
8080 {
81+ if (! is_writable (base_path ($ envFile ))) {
82+ View::render ('components.two-column-detail ' , [
83+ 'left ' => $ envFile ,
84+ 'right ' => 'File is not writable. ' ,
85+ ]);
86+
87+ return ;
88+ }
89+
8190 $ fileContent = file_get_contents (base_path ($ envFile ));
8291
8392 if ($ fileContent === false ) {
Original file line number Diff line number Diff line change @@ -25,17 +25,28 @@ public function register(): void
2525 $ this ->app ->singleton (ClientContract::class, static function (): Client {
2626 $ apiKey = config ('openai.api_key ' );
2727 $ organization = config ('openai.organization ' );
28+ $ project = config ('openai.project ' );
29+ $ baseUri = config ('openai.base_uri ' );
2830
2931 if (! is_string ($ apiKey ) || ($ organization !== null && ! is_string ($ organization ))) {
3032 throw ApiKeyIsMissing::create ();
3133 }
3234
33- return OpenAI::factory ()
35+ $ client = OpenAI::factory ()
3436 ->withApiKey ($ apiKey )
3537 ->withOrganization ($ organization )
3638 ->withHttpHeader ('OpenAI-Beta ' , 'assistants=v2 ' )
37- ->withHttpClient (new \GuzzleHttp \Client (['timeout ' => config ('openai.request_timeout ' , 30 )]))
38- ->make ();
39+ ->withHttpClient (new \GuzzleHttp \Client (['timeout ' => config ('openai.request_timeout ' , 30 )]));
40+
41+ if (is_string ($ project )) {
42+ $ client ->withProject ($ project );
43+ }
44+
45+ if (is_string ($ baseUri )) {
46+ $ client ->withBaseUri ($ baseUri );
47+ }
48+
49+ return $ client ->make ();
3950 });
4051
4152 $ this ->app ->alias (ClientContract::class, 'openai ' );
You can’t perform that action at this time.
0 commit comments