File tree 4 files changed +61
-3
lines changed
4 files changed +61
-3
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,23 @@ OPENAI_API_KEY=
71
71
OPENAI_ORGANIZATION=
72
72
```
73
73
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
+
74
91
### Request Timeout
75
92
76
93
The timeout may be used to specify the maximum number of seconds to wait
Original file line number Diff line number Diff line change 15
15
'api_key ' => env ('OPENAI_API_KEY ' ),
16
16
'organization ' => env ('OPENAI_ORGANIZATION ' ),
17
17
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
+
18
39
/*
19
40
|--------------------------------------------------------------------------
20
41
| Request Timeout
Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ private function copyConfig(): void
78
78
79
79
private function addEnvKeys (string $ envFile ): void
80
80
{
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
+
81
90
$ fileContent = file_get_contents (base_path ($ envFile ));
82
91
83
92
if ($ fileContent === false ) {
Original file line number Diff line number Diff line change @@ -25,17 +25,28 @@ public function register(): void
25
25
$ this ->app ->singleton (ClientContract::class, static function (): Client {
26
26
$ apiKey = config ('openai.api_key ' );
27
27
$ organization = config ('openai.organization ' );
28
+ $ project = config ('openai.project ' );
29
+ $ baseUri = config ('openai.base_uri ' );
28
30
29
31
if (! is_string ($ apiKey ) || ($ organization !== null && ! is_string ($ organization ))) {
30
32
throw ApiKeyIsMissing::create ();
31
33
}
32
34
33
- return OpenAI::factory ()
35
+ $ client = OpenAI::factory ()
34
36
->withApiKey ($ apiKey )
35
37
->withOrganization ($ organization )
36
38
->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 ();
39
50
});
40
51
41
52
$ this ->app ->alias (ClientContract::class, 'openai ' );
You can’t perform that action at this time.
0 commit comments