How do you implement OpenAI GPT-3 Api Client in PHP?

题意:如何在 PHP 中实现 OpenAI GPT-3 API 客户端?

问题背景:

I need help understanding the vague instructions on https://packagist.org/packages/orhanerday/open-ai

我需要帮助来理解这些模糊的说明...

I downloaded the package from https://github.com/orhanerday/open-ai

我从 https://github.com/orhanerday/open-ai 下载了这个包。

I installed the package by running "composer require orhanerday/open-ai" in my Command Prompt

我通过在命令提示符中运行 composer require orhanerday/open-ai 安装了这个包。

Instructions stop making sense from there.....

从那以后,说明就不太清楚了......

What does the "use Orhanerday\OpenAi\OpenAi;" code mean and where is it applied? Am I to create a php file say index.php with content:

代码 use Orhanerday\OpenAi\OpenAi; 是什么意思,应该在哪里使用?我是要创建一个包含以下内容的 PHP 文件,比如 index.php 吗?

php 复制代码
<?php

use Orhanerday\OpenAi\OpenAi;

$complete = $open_ai->complete([

   'engine' => 'davinci',
   'prompt' => 'Hello',
   'temperature' => 0.9,
   'max_tokens' => 150,
   'frequency_penalty' => 0,
   'presence_penalty' => 0.6,
]
?>

how and where do I add my api key? Do I create a file Orhanerday\OpenAi\OpenAi.php and enter my api key there? i.e. OPENAI_API_KEY=sk-**********************************************

我应该如何以及在哪里添加我的 API 密钥?我需要创建一个 Orhanerday\OpenAi\OpenAi.php 文件并在其中输入我的 API 密钥吗?例如 OPENAI_API_KEY=sk-**********************************************

问题解决:

You should define the $open_ai variable as an OpenAI object by passing your private KEY value. for example; new OpenAi('Your-OPENAI-KEY');

你应该通过传入你的私密密钥值,将 $open_ai 变量定义为一个 OpenAI 对象。例如:new OpenAi('Your-OPENAI-KEY');

Complete code; 完整的代码

php 复制代码
<?php


use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi('OPEN-AI-KEY');// <- define the variable.

$complete = $open_ai->complete([
    'engine' => 'davinci',
    'prompt' => 'Hello',
    'temperature' => 0.9,
    'max_tokens' => 150,
    'frequency_penalty' => 0,
    'presence_penalty' => 0.6,
]);

I also added the Quick Start Part to orhanerday/OpenAI readme.

我还在 orhanerday/OpenAI 的自述文件中添加了快速入门部分。

相关推荐
win4r1 小时前
🔥超越cursor!Cline+Context7 MCP文档搜索功能高级用法!自定义指令+.clinerules轻松开启vibe coding!零代码构建Au
aigc·openai·cline
亿坊电商2 小时前
PHP框架在微服务迁移中能发挥什么作用?
开发语言·微服务·php
帅云毅2 小时前
Web漏洞--XSS之订单系统和Shell箱子
前端·笔记·web安全·php·xss
keep intensify3 小时前
Linux常用指令
linux·服务器·php
ALex_zry4 小时前
Docker Macvlan网络配置实战:解决“network already exists“错误
网络·docker·php
布尼卡6 小时前
mac brew 无法找到php7.2 如何安装php7.2
php·mac
ALe要立志成为web糕手6 小时前
[BJDCTF2020]EzPHP
web安全·网络安全·php·ctf
农民也会写代码8 小时前
dedecms织梦arclist标签noflag属性过滤多个参数
开发语言·数据库·sql·php·dedecms
Zhuai-行淮10 小时前
施磊老师基于muduo网络库的集群聊天服务器(七)
服务器·网络·php
言之。16 小时前
别学了,打会王者吧
java·python·mysql·容器·spark·php·html5