friendsofhyperf/openai-client
最新稳定版本:v3.2.0-beta.1
Composer 安装命令:
composer require friendsofhyperf/openai-client
包简介
The openai client component for Hyperf.
README 文档
README
OpenAI PHP for Laravel is a supercharged community PHP API client that allows you to interact with the Open AI API.
Note: This repository contains the integration code of the OpenAI PHP for Hyperf. If you want to use the OpenAI PHP client in a framework-agnostic way, take a look at the openai-php/client repository.
Get Started
Requires PHP 8.1+
First, install OpenAI via the Composer package manager:
composer require friendsofhyperf/openai-client
Next, publish the configuration file:
php bin/hyperf.php vendor:publish friendsofhyperf/openai-client
This will create a config/autoload/openai.php configuration file in your project, which you can modify to your needs
using environment variables:
OPENAI_API_KEY=sk-...
Finally, you may use the OpenAI\Client instance from container to access the OpenAI API:
use OpenAI\Client; $result = di(OpenAI\Client::class)->completions()->create([ 'model' => 'text-davinci-003', 'prompt' => 'PHP is', ]); echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.
Azure
In order to use the Azure OpenAI Service, it is necessary to construct the client manually using the factory.
$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();
To use Azure, you must deploy a model, identified by the {deployment-id}, which is already incorporated into the API calls. As a result, you do not have to provide the model during the calls since it is included in the BaseUri.
Therefore, a basic sample completion call would be:
$result = $client->completions()->create([ 'prompt' => 'PHP is' ]);
Usage
For usage examples, take a look at the openai-php/client repository.
Contact
License
OpenAI PHP for Hyperf is an open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 3.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-28