Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
Antonio Cheong edited this page Apr 10, 2023 · 14 revisions

revChatGPT.V3

A simple wrapper for the official ChatGPT API

Chatbot Objects

class Chatbot()

Official ChatGPT API

__init__

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,
    truncate_limit: int = None,
    system_prompt:
    str = "You are ChatGPT, a large language model trained by OpenAI. Respond conversationally"
) -> None

Initialize Chatbot with API key (from https://platform.openai.com/account/api-keys)

add_to_conversation

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

Add a message to the conversation

get_token_count

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

Get token count

get_max_tokens

def get_max_tokens(convo_id: str) -> int

Get max tokens

ask_stream

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

Ask a question

ask_stream_async

async def ask_stream_async(prompt: str,
                           role: str = "user",
                           convo_id: str = "default",
                           **kwargs) -> AsyncGenerator[str, None]

Ask a question

ask_async

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

Non-streaming ask

ask

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

Non-streaming ask

rollback

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

Rollback the conversation

reset

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

Reset the conversation

save

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

Save the Chatbot configuration to a JSON file

load

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

Load the Chatbot configuration from a JSON file

ChatbotCLI Objects

class ChatbotCLI(Chatbot)

Command Line Interface for Chatbot

print_config

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

Prints the current configuration

print_help

def print_help() -> None

Prints the help message

handle_commands

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

Handle chatbot commands

main

def main() -> NoReturn

Main function