stuarttodd/openai-php-client

此软件包最新版本(1.0.0)没有可用的许可信息。

OpenAPI PHP 客户端。当前正在建设中,但已有一些有限的功能可用。

1.0.0 2023-07-27 20:34 UTC

This package is auto-updated.

Last update: 2024-09-27 23:20:12 UTC


README

OpenAPI PHP 客户端。当前正在建设中,但已有一些有限的功能可用。

Composer 安装

composer require stuarttodd/openai-php-client

聊天完成

<?php

use Stuarttodd\OpenAiPhpClient\OpenAI;

$apiKey = "YOUR_API_KEY_HERE";

$response = OpenAI::client($apiKey)
    ->chatCompletions()
    ->setConfig([
        'model' => 'gpt-3.5-turbo', // if not set, defaults to 'gpt-3.5-turbo'
        'temperature' => 0.9, // if not set, defaults to 0.7
        'message' => 'Tell me you love me' // If not set, defaults to giving you a random Chuck Norris joke
    ])
    ->fetch(function($response) { // use of closure is optional
        return json_decode($response)->choices[0]->message->content;
    }); 

echo $response; // "As an AI, I do not have the capability to feel emotions or love. However, I am here to assist you with any questions or tasks you may have."