跳转到主要内容

FreeAI::Server::OpenAI — 基于内置 AI 模型爬虫工具的 OpenAI API 服务器

OpenAI Server

爬虫工具概览

该爬虫工具允许您部署自己的 OpenAI 兼容 API 服务器,您可以从您的应用程序(例如 Cherry Studio、Cline 等)和脚本中连接到该服务器 —— 既可以通过官方 OpenAI SDK,也可以使用常规 HTTP 请求。该爬虫工具提供了对 A-Parser 抓取的免费和付费模型的访问。

支持的模型列表:

连接到 Cherry Studio

  • 设置(右上角)
  • 提供商列表,最下方点击“添加”
  • 设置任意名称,Provider type 必须为 OpenAI
  • 填写 API Key(任意密钥)
  • 填写主机地址(在 FreeAI::Server::OpenAI 中配置),默认为 http://127.0.0.1:3000
  • 点击“Manage”按钮添加所需的模型
查看连接视频

连接到 cherry studio

通过 OpenAI SDK 连接

Connection to FreeAI::Server::OpenAI via nodejs + openai sdk
示例代码
import OpenAI from "openai";

(async function () {
const openai = new OpenAI({
baseURL: "http://127.0.0.1:3000/v1", //部署 FreeAI::Server::OpenAI 的链接
apiKey: "123",
});

const completion = await openai.chat.completions.create({
model: "FreeAI::ChatGPT", //模型是 FreeAI::Server::OpenAI 列表中的爬虫工具名称,支持的模型列表见“爬虫工具概览”部分
messages: [{ role: "user", content: "Why is the sky blue?" }], //向模型发送请求
});

console.log(completion.choices[0].message.content); //输出 AI 模型的回答
})();

通过 HTTP 请求获取结果

Connection to FreeAI::Server::OpenAI via nodejs http request
示例代码
const resp = await fetch("http://127.0.0.1:3000/v1/chat/completions", {
method: "POST",
headers: {
Authorization: "Bearer 123",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "FreeAI::ChatGPT", //模型是 FreeAI::Server::OpenAI 列表中的爬虫工具名称,支持的模型列表见“爬虫工具概览”部分
messages: [{ role: "user", content: "nodejs 的应用领域" }], //向模型发送请求
}),
});

if (!resp.ok) {
const text = await resp.text();
throw new Error(`HTTP ${resp.status}: ${text}`);
}

const data = await resp.json();
console.log(data.choices?.[0]?.message?.content);

可用设置

参数名称默认值描述
Listen Host127.0.0.1服务接受传入连接的接口 IP 地址或主机名
Listen Port3000服务接受传入连接的端口号
FreeAI::ChatGPT presetdefaultFreeAI::ChatGPT 爬虫工具的预设
FreeAI::Copilot presetdefaultFreeAI::Copilot 爬虫工具的预设
FreeAI::DeepAI presetdefaultFreeAI::DeepAI 爬虫工具的预设
FreeAI::GoogleAI presetdefaultFreeAI::GoogleAI 爬虫工具的预设
FreeAI::Kimi presetdefaultFreeAI::Kimi 爬虫工具的预设
FreeAI::Perplexity presetdefaultFreeAI::Perplexity 爬虫工具的预设