Skip to content
On this page

revChatGPT.V3

官方 ChatGPT API 的简单包装

Chatbot 对象

python
class Chatbot()

官方 ChatGPT API

初始化

python
def __init__(
    api_key: str,
    engine: str = os.environ.get("GPT_ENGINE") or "gpt-3.5-turbo",
    proxy: str = None,
    timeout: float = None,
    max_tokens: int = None,
    temperature: float = 0.5,
    top_p: float = 1.0,
    presence_penalty: float = 0.0,
    frequency_penalty: float = 0.0,
    reply_count: int = 1,
    system_prompt:
    str = "You are ChatGPT, a large language model trained by OpenAI. Respond conversationally"
) -> None

使用 API 密钥初始化 Chatbot (来自 https://platform.openai.com/account/api-keys)

增加 conversation

python
def add_to_conversation(message: str,
                        role: str,
                        convo_id: str = "default") -> None

给 conversation 增加消息

获取令牌数量

python
def get_token_count(convo_id: str = "default") -> int

获取令牌数量

获取最多的令牌数量

python
def get_max_tokens(convo_id: str) -> int

获取最多的令牌数量

问答流

python
def ask_stream(prompt: str,
               role: str = "user",
               convo_id: str = "default",
               **kwargs) -> str

流式询问

询问

python
def ask(prompt: str,
        role: str = "user",
        convo_id: str = "default",
        **kwargs) -> str

非流式询问

回滚

python
def rollback(n: int = 1, convo_id: str = "default") -> None

回滚 conversation

重置

python
def reset(convo_id: str = "default", system_prompt: str = None) -> None

重置 conversation

保存

python
def save(file: str, *keys: str) -> None

把 Chatbot 配置文件保存为 JSON 文件

加载

python
def load(file: str, *keys: str) -> None

从 JSON 文件加载 Chatbot 配置

ChatbotCLI 对象

python
class ChatbotCLI(Chatbot)

打印配置

python
def print_config(convo_id: str = "default") -> None

打印当前配置

打印帮助

python
def print_help() -> None

打印帮助信息

处理命令

python
def handle_commands(input: str, convo_id: str = "default") -> bool

处理 Chatbot 命令

主函数

python
def main() -> NoReturn

主要的函数

Released under the MIT License.