mirage-ai/php-mirage-api

Mirage API PHP 封装器。

1.5.0 2023-12-21 14:02 UTC

This package is auto-updated.

Last update: 2024-09-21 15:30:13 UTC


README

Build and Release Version Downloads

Mirage API NodeJS 封装器。访问 AI 推理服务。

版权所有 2023 Crisp IM SAS。有关复制信息,请参阅 LICENSE。

用法

安装库

composer require mirage-ai/php-mirage-api

然后,导入它

require __DIR__."/vendor/autoload.php";

使用您的 user_idsecret_key 令牌创建一个新的认证 Mirage 客户端。

$client = new Mirage("ui_xxxxxx", "sk_xxxxxx");

然后,使用客户端进行操作,例如将包含语音的音频文件转录为文本

$data = $client->task->transcribeSpeech([
  "locale" => [
    "to" => "en"
  ],

  "media" => [
    "type" => "audio/webm",
    "url" => "https://files.mirage-ai.com/dash/terminal/samples/transcribe-speech/hey-there.weba"
  ]
]);

认证

为了对 API 进行认证,获取您的令牌(user_idsecret_key)。

然后,在实例化 Mirage 客户端时一次性传递这些令牌,如下所示

# Make sure to replace 'user_id' and 'secret_key' with your tokens
$client = new Mirage("user_id", "secret_key");

资源方法

此库实现了 Mirage API 提供的所有方法。请参阅 API 文档,了解可用方法的参考,以及返回数据的格式。

任务 API

➡️ 转录语音

  • 方法: $client->task->transcribeSpeech(data)

  • 参考: 转录语音

  • 请求

$client->task->transcribeSpeech([
  "locale" => [
    "to" => "en"
  ],

  "media" => [
    "type" => "audio/webm",
    "url" => "https://files.mirage-ai.com/dash/terminal/samples/transcribe-speech/hey-there.weba"
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "locale": "en",

    "parts": [
      {
        "start": 5.0,
        "end": 9.0,
        "text": " I'm just speaking some seconds to see if the translation is correct"
      }
    ]
  }
}

➡️ 回答提示

  • 方法: $client->task->answerPrompt(data)

  • 参考: 回答提示

  • 请求

$client->task->answerPrompt([
  "prompt" => "Generate an article about Alpacas"
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "answer": "The alpaca (Lama pacos) is a species of South American camelid mammal. It is similar to, and often confused with, the llama. However, alpacas are often noticeably smaller than llamas. The two animals are closely related and can successfully crossbreed. Both species are believed to have been domesticated from their wild relatives, the vicuña and guanaco. There are two breeds of alpaca: the Suri alpaca and the Huacaya alpaca."
  }
}

➡️ 回答问题

  • 方法: $client->task->answerQuestion(data)

  • 参考: 回答问题

  • 请求

$client->task->answerQuestion([
  "question" => "Should I pay more for that?",

  "answer" => [
    "start" => "Sure,"
  ],

  "context" => [
    "primary_id" => "cf4ccdb5-df44-4668-a9e7-3ab31bebf89b",

    "conversation" => [
      "messages" => [
        [
          "from" => "customer",
          "text" => "Hey there!"
        ],

        [
          "from" => "agent",
          "text" => "Hi. How can I help?"
        ],

        [
          "from" => "customer",
          "text" => "I want to add more sub-domains to my website."
        ]
      ]
    ]
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "answer": "You can add the Crisp chatbox to your website by following this guide: https://help.crisp.chat/en/article/how-to-add-crisp-chatbox-to-your-website-dkrg1d/ :)",
    "sources": []
  }
}

➡️ 摘要段落

  • 方法: $client->task->summarizeParagraphs(data)

  • 参考: 摘要段落

  • 请求

$client->task->summarizeParagraphs([
  "paragraphs" => [
    [
      "text" => "GPT-4 is getting worse over time, not better."
    ],

    [
      "text" => "Many people have reported noticing a significant degradation in the quality of the model responses, but so far, it was all anecdotal."
    ]
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "summary": "GPT-4 is getting worse over time, not better. We have a new version of GPT-4 that is not improving, but it is regressing."
  }
}

➡️ 摘要对话

  • 方法: $client->task->summarizeConversation(data)

  • 参考: 摘要对话

  • 请求

$client->task->summarizeConversation([
  "transcript" => [
    [
      "name" => "Valerian",
      "text" => "Hello! I have a question about the Crisp chatbot, I am trying to setup a week-end auto-responder, how can I do that?"
    ],

    [
      "name" => "Baptiste",
      "text" => "Hi. Baptiste here. I can provide you an example bot scenario that does just that if you'd like?"
    ]
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "summary": "Valerian wants to set up a week-end auto-responder on Crisp chatbot. Baptiste can give him an example."
  }
}

➡️ 分类对话

  • 方法: $client->task->categorizeConversations(data)

  • 参考: 分类对话

  • 请求

$client->task->categorizeConversations([
  "conversations" => [
    [
      "transcript" => [
        [
          "from" => "customer",
          "text" => "Hello! I have a question about the Crisp chatbot, I am trying to setup a week-end auto-responder, how can I do that?"
        ],

        [
          "from" => "agent",
          "text" => "Hi. Baptiste here. I can provide you an example bot scenario that does just that if you'd like?"
        ]
      ]
    ]
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "categories": [
      "Chatbot Configuration Issue"
    ]
  }
}

➡️ 排序问题

  • 方法: $client->task->rankQuestion(data)

  • 参考: 排序问题

  • 请求

$client->task->rankQuestion([
  "question" => "Hi! I am having issues setting up DNS records for my Crisp helpdesk. Can you help?",

  "context" => [
    "source" => "helpdesk",
    "primary_id" => "cf4ccdb5-df44-4668-a9e7-3ab31bebf89b"
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "results": [
      {
        "id": "15fd3f24-56c8-435e-af8e-c47d4cd6115c",
        "score": 9,
        "grouped_text": "Setup your Helpdesk domain name\ntutorials for most providers",

        "items": [
          {
            "source": "helpdesk",
            "primary_id": "51a32e4c-1cb5-47c9-bcc0-3e06f0dce90a",
            "secondary_id": "15fd3f24-56c8-435e-af8e-c47d4cd6115c",
            "text": "Setup your Helpdesk domain name\ntutorials for most providers",
            "timestamp": 1682002198552,

            "metadata": {
              "title": "Setup your Helpdesk domain name"
            }
          }
        ]
      }
    ]
  }
}

➡️ 翻译文本

  • 方法: $client->task->translateText(data)

  • 参考: 翻译文本

  • 请求

$client->task->translateText([
  "locale" => [
    "from" => "fr",
    "to" => "en"
  ],

  "type" => "html",
  "text" => "Bonjour, comment puis-je vous aider <span translate=\"no\">Mr Saliou</span> ?"
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "translation": "Hi, how can I help you Mr Saliou?"
  }
}

➡️ 欺诈垃圾邮件度

$client->task->fraudSpamicity([
  "name" => "Crisp",
  "domain" => "crisp.chat",
  "email_domain" => "mail.crisp.chat"
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "fraud": false,
    "score": 0.13
  }
}

数据 API

➡️ 上下文摄取

$client->data->contextIngest([
  "items" => [
    [
      "operation": "index",
      "primary_id" => "pri_cf44dd72-4ba9-4754-8fb3-83c4261243c4",
      "secondary_id" => "sec_6693a4a2-e33f-4cce-ba90-b7b5b0922c46",
      "tertiary_id" => "ter_de2bd6e7-74e1-440d-9a23-01964cd4b7da",

      "text" => "Text to index here...",
      "source" => "chat",
      "timestamp" => 1682002198552,

      "metadata" => [
        "custom_key" => "custom_value",
        "another_key" => "another_value"
      ]
    ]
  ]
]);
  • 响应
{
  "reason": "processed",

  "data": {
    "imported": true
  }
}