承接 webboy/laravel-open-ai-api-client 相关项目开发

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

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

webboy/laravel-open-ai-api-client

最新稳定版本:1.0.5

Composer 安装命令:

composer require webboy/laravel-open-ai-api-client

包简介

Laravel package adapting PHP OpenAI API Client

README 文档

README

Community-maintained Laravel package adapting PHP OpenAI API Client

Note: This is not an official Laravel Package

Installation

Intsall the package using composer

composer require webboy/laravel-open-ai-api-client

Then publish the configuration file

php artisan vendor:publish --tag=openai-config

Add OPENAI_API_KEY={your OpenAI api key} to the .env file

That's it, you are all set up

Usage examples

An example Laravel Artisan command that uses OpenAIChat library:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use OpenAIClient;

class OpenAIChatCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'open-ai:chat-answer {question}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Answers a question using ChatGPT Chat API endpoint';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        $question = $this->argument('question');

        $data['model']      = 'gpt-3.5-turbo';
        $data['messages'] = [
            [
                'role'      => 'system',
                'content'   => 'You are a good and all knowing assistant'
            ],
            [
                'role'      => 'user',
                'content'   => $question
            ]
        ];

        $response = OpenAIClient::chat()->create($data);

        $this->info($response['choices'][0]['message']['content']);
    }
}

Use the facade OpenAIClient static methods to access all endpoints of thh OpenAI:

OpenAIClient::audio(): OpenAIAudio
OpenAIClient::chat(): OpenAIChat
OpenAIClient::completions(): OpenAICompletions
OpenAIClient::edits(): OpenAIEdits
OpenAIClient::embeddings(): OpenAIEmbeddings
OpenAIClient::files(): OpenAIFiles
OpenAIClient::fineTunes(): OpenAIFineTunes
OpenAIClient::images(): OpenAIImages
OpenAIClient::models(): OpenAIModels
OpenAIClient::moderations(): OpenAIModerations

Refer to the official API reference for more details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-21