承接 muhammetsafak/openai-client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

muhammetsafak/openai-client

最新稳定版本:1.0

Composer 安装命令:

composer require muhammetsafak/openai-client

包简介

README 文档

README

This library was created to facilitate communication with OpenAI services in the simplest and most understandable way using PHP.

Installation

composer require muhammetsafak/openai-client

Required

  • PHP 7.4 or later
  • cURL Extension

Usage

Completions

use MuhammetSafak\OpenAI\OpenAI;
use MuhammetSafak\OpenAI\Services\Completions;
const SECRET_KEY = "";

$openai = new OpenAI(SECRET_KEY);
$openai->setPrompt($_GET['prompt'])
    ->setTemperature(0.7);

$res = (new Completions($openai))->get();

echo $res['response']['choices'][0]['text'];

The exact equivalent of the $res variable should be something similar to the following.

[
    'status'        => true,
    'message'       => '',
    'response'      => [
        "id" => "cmpl-8WlS2x6looAGlj8Z182D3M...",
        "object" => "text_completion",
        "created" => 1702819590,
        "model" => "davinci-002",
        "choices" => [
            0 => [
                "text" => "...",
                "index" => 0,
                "logprobs" => null,
                "finish_reason" => "stop",
            ],
        ],
        "usage" => [
                "prompt_tokens" => 1,
                "completion_tokens" => 81,
                "total_tokens" => 32,
        ],
    ]
]

Chat

use MuhammetSafak\OpenAI\OpenAI;
use MuhammetSafak\OpenAI\Services\Chat;
const SECRET_KEY = "";

$openai = new OpenAI(SECRET_KEY);
$openai->setPrompt($systemMessage)
    ->setTemperature(0.7);
    
$res = (new Chat($openai))
    ->setUserMessage($userMessage)
    ->get();

echo $res['response']['choices'][0]['message']['content'];

The exact equivalent of the $res variable should be something similar to the following.

[
    'status'        => true,
    'message'       => '',
    'response'      => [
        "id" => "chatcmpl-8WmzZ2uCDqBZ83BFWbAaifeDNHmlG",
        "object" => "chat.completion",
        "created" => 1702825513,
        "model" => "gpt-3.5-turbo-0613",
        "choices" => [
            0 => [
                "index" => 0,
                "message" => [
                    "role" => "assistant",
                    "content" => "",
                ],
                "logprobs" => null,
                "finish_reason" => "stop",
            ],
        ],
        "usage" => [
                "prompt_tokens" => 121,
                "completion_tokens" => 8,
                "total_tokens" => 129,
        ],
        "system_fingerprint" => null,
    ]
]

Getting Help

If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.

Getting Involved

All contributions to this project will be published under the MIT License. By submitting a pull request or filing a bug, issue, or feature request, you are agreeing to comply with this waiver of copyright interest.

There are two primary ways to help:

  • Using the issue tracker, and
  • Changing the code-base.

Using the issue tracker

Use the issue tracker to suggest feature requests, report bugs, and ask questions. This is also a great way to connect with the developers of the project as well as others who are interested in this solution.

Use the issue tracker to find ways to contribute. Find a bug or a feature, mention in the issue that you will take on that effort, then follow the Changing the code-base guidance below.

Changing the code-base

Generally speaking, you should fork this repository, make changes in your own fork, and then submit a pull request. All new code should have associated unit tests that validate implemented features and the presence or lack of defects. Additionally, the code should follow any stylistic and architectural guidelines prescribed by the project. In the absence of such guidelines, mimic the styles and patterns in the existing code-base.

Credits

License

Copyright © 2023 MIT License

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-17