How can I use factory for Azure
DC-Sebastian opened this issue · comments
Can i use
$client = OpenAI::factory() ->withBaseUri('{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}') ->withHttpHeader('api-key', '{your-api-key}') ->withQueryParam('api-version', '{version}') ->make();
for Azure as described here?
I don't know exactly how to implement this with OpenAI PHP for Laravel.
One way is to override the singleton in your service provider:
$this->app->singleton(ClientContract::class, static function (): Client {
$apiKey = config('openai.api_key');
if (! is_string($apiKey)) {
throw ApiKeyIsMissing::create();
}
return OpenAI::factory()
->withBaseUri('{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}')
->withHttpHeader('api-key', '{your-api-key}')
->withQueryParam('api-version', '{version}')
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)]))
->make();
});
Here is the original implementation from the package provided.
https://github.com/openai-php/laravel/blob/main/src/ServiceProvider.php#L24
Hope this helps.