tallesairan/oobapi-php

此包的最新版本(1.2)没有可用的许可证信息。

oobabooga的text-generation-webui的PHP包装器

1.2 2023-07-27 18:08 UTC

This package is auto-updated.

Last update: 2024-09-30 01:41:19 UTC


README

oobabooga的text-generation-webui的PHP包装器

这是一个用于与WebSocket和HTTP端点交互的Text Generation API的PHP客户端。客户端允许你向服务器发送请求,并从WebSocket和HTTP端点接收响应。

本文档提供了关于 oobapi-php 库的信息,该库是oobabooga的text-generation-webui的PHP包装器。库包含两个主要类,ApiClientStreamClient,分别负责与不同的API端点交互。

目录

安装

要使用 oobapi-php 库,您需要安装PHP 7.4或更高版本。此外,该库依赖于以下包

  • guzzlehttp/guzzle 版本 7.0或更高
  • textalk/websocket 版本 1.6.1或更高

您可以通过Composer安装库。将以下内容添加到您的 composer.json 文件中,并运行 composer install

要求

  • PHP 7.4或更高
  • Composer
composer require tallesairan/oobapi-php

ApiClient

ApiClient 类允许您通过HTTP请求与oobabooga的text-generation-webui API进行交互。

构造函数

通过提供API的基本URL创建一个新的 ApiClient 实例。

use Airan\OobApi\ApiClient;

$baseUrl = 'http://example.com'; // Replace with your API base URL
$apiClient = new ApiClient($baseUrl);

方法

generate

基于给定的提示和可选参数生成文本。

/**
* Generate text based on a given prompt and optional parameters.
*
* @param string $prompt The input prompt for text generation.
* @param array $params Optional parameters to customize text generation.
* @return array An array containing the generated text and additional data.
  */
  public function generate($prompt, $params = []) {
  // Implementation details...
  }

chat

与API进行聊天,基于用户输入和历史生成交互式文本。

/**
* Chat with the API to generate interactive text based on user input and history.
*
* @param string $userInput The user's input text.
* @param string $history The conversation history.
* @param array $params Optional parameters to customize the chat.
* @return array An array containing the generated response and additional data.
  */
  public function chat($userInput, $history, $params = []) {
  // Implementation details...
  }

stopStream

停止文本生成流。

/**
* Stop the text generation stream.
*
* @return array An array containing the response data.
  */
  public function stopStream() {
  // Implementation details...
  }

StreamClient

  • 注意,此功能处于开发中

StreamClient 类使您能够通过WebSocket与oobabooga的text-generation-webui API进行交互。

构造函数

通过提供WebSocket基本URL创建一个新的 StreamClient 实例。

use Airan\OobApi\StreamClient;

$webSocketBaseUrl = 'ws://example.com'; // Replace with your WebSocket base URL
$streamClient = new StreamClient($webSocketBaseUrl);

方法

stream

基于给定的提示和可选参数使用WebSocket流生成文本。

/**
* Generate text using WebSocket streaming based on a given prompt and optional parameters.
*
* @param string $prompt The input prompt for text generation.
* @param array $params Optional parameters to customize text generation.
* @return array An array containing the generated text and additional data.
  */
  public function stream($prompt, $params = []) {
  // Implementation details...
  }

chatStream

使用WebSocket流进行聊天,基于用户输入和历史生成交互式文本。

/**
* Chat using WebSocket streaming to generate interactive text based on user input and history.
*
* @param string $userInput The user's input text.
* @param string $history The conversation history.
* @param array $params Optional parameters to customize the chat.
* @return array An array containing the generated response and additional data.
  */
  public function chatStream($userInput, $history, $params = []) {
  // Implementation details...
  }

请注意,上述文档提供了 oobapi-php 库及其主要类的概述。有关更具体的实现细节和用法示例,请参阅库本身的源代码和文档。

贡献

欢迎贡献!如果您发现任何问题或想改进客户端,请随时提交拉取请求。

许可证

本项目采用MIT许可证。有关详细信息,请参阅LICENSE文件。

请确保将使用部分中的WebSocket和HTTP端点URL调整到匹配您的WebSocket和HTTP服务器的实际实现。同时,根据需要更新WebSocket服务器和HTTP服务器部分的信息。