dneustadt/openai-client

OpenAI API 客户端

0.2.2 2022-11-05 20:03 UTC

This package is auto-updated.

Last update: 2024-09-06 00:23:21 UTC


README

OpenAI 是一家 AI 研究和部署公司。我们的使命是确保通用人工智能造福全人类。

安装与使用

要求

PHP 7.2 及以上版本。

Composer

通过Composer安装

composer require dneustadt/openai-client

入门指南

请按照安装过程进行操作,然后运行以下命令

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: api_key
$config = OpenAI\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');

$apiInstance = new OpenAI\Client\Api\AnswerApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$open_ai_organization = 'open_ai_organization_example'; // optional
$answer_payload = new \OpenAI\Client\Model\AnswerPayload(); // \OpenAI\Client\Model\AnswerPayload

try {
    $result = $apiInstance->postAnswer($open_ai_organization, $answer_payload);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AnswerApi->postAnswer: ', $e->getMessage(), PHP_EOL;
}

API 端点

所有 URI 都相对于 https://api.openai.com/v1

模型

请求负载

响应模型