Skip to content

Latest commit

 

History

History
367 lines (230 loc) · 6.33 KB

V1.md

File metadata and controls

367 lines (230 loc) · 6.33 KB

revChatGPT.V1

标准 ChatGPT

日志记录

def logger(is_timed: bool)

日志记录装饰器

参数:

  • is_timed 布尔类型 - 是否在退出日志中包含函数运行时间

返回值:

  • _type_ - 装饰函数

Chatbot对象

class Chatbot()

ChatGPT 的 Chatbot 对象

__init__

@logger(is_timed=True)
def __init__(config: dict[str, str],
             conversation_id: str | None = None,
             parent_id: str | None = None,
             session_client=None,
             lazy_loading: bool = False) -> None

初始化一个 Chatbot

参数:

  • config dict[str, str] - 登录名和代理信息。示例

{

  • "email" - "OpenAI 账户邮箱",
  • "password" - "OpenAI 账户密码",
  • "session_token" - "<session_token>"
  • "access_token" - "<access_token>"
  • "proxy" - "<proxy_url_string>",
  • "paid" - True/False #是不是plus帐户

}

有关这些的更多详细信息,请访问 https://github.com/acheong08/ChatGPT#configuration

  • conversation_id str | None, optional - 要继续 conversation 的 ID。默认为 None
  • parent_id str | None, optional - 要继续的上一条响应消息的 ID。默认为 None
  • session_client type, optional - 描述. 默认为 None

错误对象:

  • Exception - 描述

设置访问令牌

@logger(is_timed=False)
def set_access_token(access_token: str) -> None

在请求标头和 self.config 中设置访问令牌,然后将其缓存到文件中。

参数:

  • access_token str - 访问令牌

询问

@logger(is_timed=True)
def ask(prompt: str,
        conversation_id: str | None = None,
        parent_id: str | None = None,
        timeout: float = 360) -> str

给 chatbot 提问题

参数:

  • prompt str - 问题
  • conversation_id str | None, optional - UUID 用于继续对话。默认为 None
  • parent_id str | None, optional - 用于继续发送消息的 UUID。默认为 None
  • timeout float, optional - 获取完整响应的超时,单位为秒。默认为 360 秒

错误对象:

  • Error - 描述
  • Exception - 描述
  • Error - 描述
  • Error - 描述
  • Error - 描述

生成器:

  • _type_ - 描述

获取 conversations

@logger(is_timed=True)
def get_conversations(offset: int = 0,
                      limit: int = 20,
                      encoding: str | None = None) -> list

获取 conversations

参数:

  • offset: int
  • limit: int

获取信息历史

@logger(is_timed=True)
def get_msg_history(convo_id: str, encoding: str | None = None) -> list

获取消息的历史记录

参数:

  • id: conversation 的 UUID
  • encoding: str

获取标题

@logger(is_timed=True)
def gen_title(convo_id: str, message_id: str) -> str

生成 conversation 的标题

修改标题

@logger(is_timed=True)
def change_title(convo_id: str, title: str) -> None

修改 conversation 的标题

参数:

  • id: conversation 的 UUID
  • title: str

删除 conversation

@logger(is_timed=True)
def delete_conversation(convo_id: str) -> None

删除 conversation

参数:

  • id: conversation 的 UUID

清理 conversation

@logger(is_timed=True)
def clear_conversations() -> None

删除所有的 conversation

重置 Chatbot

@logger(is_timed=False)
def reset_chat() -> None

重置 conversation ID 和父类 ID。

返回值:

None

回滚 conversation

@logger(is_timed=False)
def rollback_conversation(num: int = 1) -> None

回滚 conversation

参数:

  • num: int. 要回滚的消息数

返回值:

None

异步Chatbot对象

class AsyncChatbot(Chatbot)

用于 ChatGPT 的异步 Chatbot 对象

询问

async def ask(prompt: str,
              conversation_id: str | None = None,
              parent_id: str | None = None,
              timeout: int = 360) -> dict

问 Chatbot 问题

获取 conversation

async def get_conversations(offset: int = 0, limit: int = 20) -> list

获取 conversation

参数:

  • offset: int
  • limit: int

获取信息历史

async def get_msg_history(convo_id: str,
                          encoding: str | None = "utf-8") -> dict

获取消息的历史

参数:

  • id: conversation 的 UUID

获取标题

async def gen_title(convo_id: str, message_id: str) -> None

生成 conversation 的标题

修改标题

async def change_title(convo_id: str, title: str) -> None

修改 conversation 的标题

参数:

  • convo_id: conversation 的 UUID
  • title: str

删除 conversation

async def delete_conversation(convo_id: str) -> None

删除 conversation

参数:

  • convo_id: conversation 的 UUID

清理 conversation

async def clear_conversations() -> None

删除所有的 conversation

配置

@logger(is_timed=False)
def configure() -> dict

在以下位置查找配置文件:

主函数

@logger(is_timed=False)
def main(config: dict) -> NoReturn

ChatGPT 命令行程序主要功能