本技能由 JacobLinCool 开源,用于在 AI Agent 中处理调用 ChatGPT API 的命令行工具。以下为官方技能说明文档:
ChatGPT CLI
This is a library, a CLI, and a Discord bot for the unofficial ChatGPT API with progressive responses and more.
You can find READMEs for the library, CLI, and Discord bot in their respective folders in packages/.
The library documentation is available at https://jacoblincool.github.io/ChatGPT-Agent/.
The CLI is available on npm.
And you can invite the Discord bot to your server with this link. (Or host it by yourself: clone the repo, setup .env, and run docker compose up.)
[Features](#features) | [Usage](#usage) | [Configuration](#configuration)
// refresh_token is optional
const agent = new Agent(token, refresh_token);
// multiple sessions can be created
const session = agent.session();
const first_conv = session.talk("Hello");
first_conv.on("partial", partial);
console.log("completed", await first_conv.response);
first_conv.off("partial", partial);
const second_conv = session.talk("Tell me a joke");
second_conv.on("partial", partial);
console.log("completed", await second_conv.response);
second_conv.off("partial", partial);
console.log("history", session.history);
Agent is the main class for the library. It represents a single user, and handles the token (and refresh token), and can create multiple sessions.
Session is a class that represents a single context just like the new ChatGPT tab you opened in the browser. It can be created with Agent.session(). It has a history property that is an array of messages, and a talk method that takes a message and returns a Conversation object.
Conversation is a class that represents a single conversation. It has a response property that is a promise that resolves to the full response, and an on method that takes an event name and a callback. You can listen to partial events, which are fired when the response is updated, and complete events, which are fired when the response is complete. Also, error events are fired when an error occurs.
You can configure the backend URL and the request timeout for the agent.
const agent = new Agent(token, refresh_token, {
backend: "https://chat.openai.com/backend-api",
timeout: 60_000,
});
The default backend URL is https://chat.openai.com/backend-api, and the default timeout is 60 seconds.
You can also configure them using environment variables.
CHATGPT_BACKEND="https://chat.openai.com/backend-api"
CHATGPT_TIMEOUT=60000
CHATGPT_RETRY=1
本技能来源于官方仓库,可通过技能管理器安装:
# 安装到当前项目
npx skills add chatgpt-cli
# 全局安装
npx skills add chatgpt-cli -g
JacobLinCool
评论区