编程

Open AI 的 PHP SDK

5744 2021-12-29 22:12:32

orhanerday/open-ai 扩展包是 OpenAI GPT-3 API 的 PHP SDK 。它支持完整、搜索、分类、答案和引擎 API。

用例:

$response = $open_ai->classification([
    "examples" => [
        ["A happy moment", "Positive"],
        ["I am sad.", "Negative"],
        ["I am feeling awesome", "Positive"]
  ],
  "labels" => ["Positive", "Negative", "Neutral"],
  "query" => "It is a rainy day :(",
  "search_model" => "ada",
  "model" => "curie",
]);

你将获得以下关于”It is a rainy day :(“ 查询的分类信息:

{
  "completion": "cmpl-4KKvYbROfgIroNbeTBPmAmAzKZcUC",
  "label": "Negative",
  "model": "curie:2020-05-03",
  "object": "classification",
  "search_model": "ada",
  "selected_examples": [
    {
      "document": 1,
      "label": "Negative",
      "text": "I am sad."
    },
    {
      "document": 0,
      "label": "Positive",
      "text": "A happy moment"
    },
    {
      "document": 2,
      "label": "Positive",
      "text": "I am feeling awesome"
    }
  ]
}

这个包是轻量级的,除了cURL 和 JSON 的 PHP 扩展外,没有额外的依赖。你需要 对 JSON API 的响应进行解码:

$response = $open_ai->classification([/* ... */]);
$data = json_decode($response, true);

要入门这个包,你需要先去熟悉 OpenAI API 文档和用例。

更多详情及完整的安装指引,请查看看GitHub源码