This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Antonio Cheong edited this page Apr 10, 2023
·
14 revisions
A simple wrapper for the official ChatGPT API
class Chatbot()
Official ChatGPT API
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)
def add_to_conversation(message: str,
role: str,
convo_id: str = "default") -> None
Add a message to the conversation
def get_token_count(convo_id: str = "default") -> int
Get token count
def get_max_tokens(convo_id: str) -> int
Get max tokens
def ask_stream(prompt: str,
role: str = "user",
convo_id: str = "default",
**kwargs)
Ask a question
async def ask_stream_async(prompt: str,
role: str = "user",
convo_id: str = "default",
**kwargs) -> AsyncGenerator[str, None]
Ask a question
async def ask_async(prompt: str,
role: str = "user",
convo_id: str = "default",
**kwargs) -> str
Non-streaming ask
def ask(prompt: str,
role: str = "user",
convo_id: str = "default",
**kwargs) -> str
Non-streaming ask
def rollback(n: int = 1, convo_id: str = "default") -> None
Rollback the conversation
def reset(convo_id: str = "default", system_prompt: str = None) -> None
Reset the conversation
def save(file: str, *keys: str) -> None
Save the Chatbot configuration to a JSON file
def load(file: str, *keys_: str) -> None
Load the Chatbot configuration from a JSON file
class ChatbotCLI(Chatbot)
Command Line Interface for Chatbot
def print_config(convo_id: str = "default") -> None
Prints the current configuration
def print_help() -> None
Prints the help message
def handle_commands(prompt: str, convo_id: str = "default") -> bool
Handle chatbot commands
def main() -> NoReturn
Main function