这是一个可以将 Huggingface Spaces魔搭创空间 及 Gradio ChatBot 自动转成免费 API 的 Npm 包。理论上支持所有带 chatbot 的空间,目前完美支持了 GPT4Free,ChatGPT,Llama 2,Vicuna,MPT-30B,Falcon,ChatGLM,通义千问 等众多模型空间

项目地址:https://github.com/weaigc/gradio-chatbot

直接使用:https://weaigc.github.io/gradio-chatbot-ui

快速上手

NPM

  • 体验 ChatGPT

npx gradio-chatbot
# or
npm install -g gradio-chatbot
chatbot
  • 体验 Llama2

chatbot 2
# 或者
chatbot https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat

更多用法请输入 chatbot help

Docker

docker build . -t gradio-server
docker run --rm -it -p 8000:8000 gradio-server

asciicasthttps://asciinema.org/a/0ki5smP795eyXdXGlx53UDmTB

安装

你可以使用 npm 或者 yarn 来安装 gradio-chatbot,Node 版本需要 >= 18。

npm install gradio-chatbot
# or
yarn add gradio-chatbot

使用

目前支持三种模式。

CLI模式

参考 快速上手

API服务

为了方便使用,提供了两种形式的接口。

curl http://127.0.0.1:8000/api/conversation \
  -H "Content-Type: application/json" \
  -d '{
     "model": "gpt-3.5-turbo",
     "messages": [{"role": "user", "content": "hello"}],
   }'

API函数

import { GradioChatBot } from 'gradio-chatbot'

const bot = new GradioChatBot();

async function start() {
  const message = await bot.chat('hello', {
    onMessage(partialMsg) {
      console.log('stream output:', partialMsg);
    }
  });
  console.log('message', message);
}

start();

你也可以把你想要转换的空间地址输入进去,如 https://huggingface.co/spaces/h2oai/h2ogpt-chatbot

import { GradioChatBot } from 'gradio-chatbot'

const bot = new GradioChatBot({
  url: 'https://huggingface.co/spaces/h2oai/h2ogpt-chatbot',
  fnIndex: 35,
}); // 调用自定义 ChatBot 模型

async function start() {
  console.log(await bot.chat('Hello'));
}

start();

除此之外,Npm 包里面已经内置了 10 个流行的 Huggingface Spaces魔搭创空间,你可以直接传入模型序号使用

import { GradioChatBot } from 'gradio-chatbot';

const bot = new GradioChatBot('1'); // 使用内置1号模型
async function start() {
  console.log(await bot.chat('Tell me about ravens.'));
}

start();

更多示例请前往目录: Examples

注意:Huggingface 上的部分模型可能会收集你输入的信息,如果你对数据安全有要求,建议不要使用,使用自己搭建的模型是一个更好的选择。

    来自NOISE资源阁-noisevip.cn
    NOISE宝藏阁 » 支持在线、离线all in one的AI模型空间入口

    发表回复

    微信
    我会尽快回复。
    取消