适用于 PHP 应用程序的 GPT-4 和 GPT-3.5 ChatGPT API 客户端
ChatGPT 文本完成(GPT-4 和 GPT-3.5)¶
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY'))); /** @var \Tectalic\OpenAi\Models\ChatCompletions\CreateResponse $response */$response = $openaiClient->chatCompletions()->create( new \Tectalic\OpenAi\Models\ChatCompletions\CreateRequest([ 'model' => 'gpt-4', 'messages' => [ ['role' => 'system', 'content' => 'You are a helpful assistant'], ['role' => 'user', 'content' => 'Who won the world series in 2020?'], ['role' => 'assistant', 'content' => 'The Los Angeles Dodgers won the World Series in 2020.'], ['role' => 'user', 'content' => 'Where was it played?'], ], ]))->toModel(); echo $response->choices[0]->message->content;// The 2020 World Series was played at Globe Life Field in Arlington, Texas. It was a neutral site due to COVID-19 pandemic restrictions.
使用 Whisper 进行语音转文本¶
音频转录¶
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY'))); /** @var \Tectalic\OpenAi\Models\AudioTranscriptions\CreateResponse $response */$response = $openaiClient->audioTranscriptions()->create( new \Tectalic\OpenAi\Models\AudioTranscriptions\CreateRequest([ 'file' => '/full/path/to/audio/file.mp3', 'model' => 'whisper-1', ]))->toModel(); echo $response->text;// Your audio transcript in one of 50+ source languages...
音频翻译¶
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY'))); /** @var \Tectalic\OpenAi\Models\AudioTranslations\CreateResponse $response */$response = $openaiClient->audioTranslations()->create( new \Tectalic\OpenAi\Models\AudioTranslations\CreateRequest([ 'file' => '/full/path/to/audio/file.mp3', 'model' => 'whisper-1', ]))->toModel(); echo $response->text;// Your audio transcript in English...
其他特性¶
- 用于所有 API 请求和响应的完全类型化数据传输对象 (DTO) 。
- IDE 自动完成:所有 API 端点、请求和响应都在 Visual Studio Code 或 PhpStorm 等高级 IDE 中完整记录。
- 用于与 OpenAI API 交互的便捷流畅的界面。
- 支持所有 23 个 API 端点:请参阅文档以获取支持的 API 方法的完整列表。
- 由我们的开发人员进行了全面测试,包括单元和功能集成测试。提供了所有测试用例。
- 由我们澳大利亚开发团队的全力支持。
开始使用¶
您可以tectalic/openai在Packagist.org和GitHub上找到可用的软件包。
闪电发卡ChatGPT产品推荐:
ChatGPT独享账号:https://www.chatgptzh.com/post/86.html
ChatGPT Plus共享账号:https://www.chatgptzh.com/post/319.html
ChatGPT Plus独享账号(购买充值代充订阅):https://www.chatgptzh.com/post/306.html
ChatGPT APIKey购买充值(直连+转发):https://www.chatgptzh.com/post/305.html
ChatGPT Plus国内镜像逆向版:https://www.chatgptzh.com/post/312.html
ChatGPT国内版(AIChat):https://www.chatgptzh.com/post/318.html