TLS-based ChatGPT API with auto token regeneration, conversation tracking, proxy support and more.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core conversation functionality for interacting with ChatGPT, including message sending, response handling, conversation context management, and interactive CLI sessions.
Main conversation handler that manages ChatGPT sessions with authentication, conversation tracking, and session persistence.
class Chat:
"""
Main interface for ChatGPT conversations with authentication, session management, and conversation tracking.
Args:
email (str): User's OpenAI account email address
password (str): User's OpenAI account password
options (Options or None): Configuration options for the chat session
conversation_id (str or None): ID to resume an existing conversation
previous_convo_id (str or None): Previous conversation context ID
"""
def __init__(
self,
email: str,
password: str,
options: Options or None = None,
conversation_id: str or None = None,
previous_convo_id: str or None = None
): ...Send messages to ChatGPT and receive responses with conversation context tracking.
def ask(
self,
prompt: str,
previous_convo_id: str or None = None,
conversation_id: str or None = None,
rep_queue: Queue or None = None
) -> Tuple[str or None, str or None, str or None] or None:
"""
Send a message to ChatGPT and get response.
Args:
prompt (str): The message to send to ChatGPT
previous_convo_id (str or None): Override previous conversation ID
conversation_id (str or None): Override conversation ID
rep_queue (Queue or None): Queue to put response for threading
Returns:
Tuple[str or None, str or None, str or None] or None:
(response_text, previous_conversation_id, conversation_id) or None if request fails
Raises:
PyChatGPTException: If prompt is invalid or authentication fails
"""from pychatgpt import Chat
chat = Chat(email="user@example.com", password="password")
# Simple question
response, prev_id, conv_id = chat.ask("What is Python?")
print(f"ChatGPT: {response}")
# Continue conversation with context
response, prev_id, conv_id = chat.ask(
"Can you give me an example?",
previous_convo_id=prev_id,
conversation_id=conv_id
)
print(f"ChatGPT: {response}")Start an interactive command-line conversation session with ChatGPT.
def cli_chat(self, rep_queue: Queue or None = None) -> None:
"""
Start an interactive CLI chat session.
Args:
rep_queue (Queue or None): Queue to put responses for threading
Returns:
None: Method returns None when session ends or if authentication fails
Note:
Type 'exit' to end the session. Conversation will be automatically saved
if tracking is enabled in options.
Raises:
PyChatGPTException: If authentication fails or queue is invalid
"""from pychatgpt import Chat, Options
options = Options()
options.track = True # Save conversation history
chat = Chat(
email="user@example.com",
password="password",
options=options
)
# Start interactive session
chat.cli_chat()
# User can now type messages and receive responses
# Type 'exit' to quitSave conversation data to files when tracking is enabled.
def save_data(self):
"""
Save conversation history and IDs to configured log files.
Only functions when options.track is True. Saves conversation history
to chat_log file and conversation IDs to id_log file.
Raises:
PyChatGPTException: If file operations fail
"""Control console output for debugging and monitoring.
def log(self, inout):
"""
Log message to stderr if logging is enabled.
Args:
inout: Message to log (any type)
Note:
Only outputs if options.log is True
"""The chat interface supports multi-threaded usage through response queues:
import threading
from queue import Queue
from pychatgpt import Chat
def chat_worker(chat, prompt, response_queue):
response, prev_id, conv_id = chat.ask(prompt, rep_queue=response_queue)
return response, prev_id, conv_id
# Create chat instance
chat = Chat(email="user@example.com", password="password")
# Use with threading
response_queue = Queue()
thread = threading.Thread(
target=chat_worker,
args=(chat, "Hello!", response_queue)
)
thread.start()
# Get response from queue
prompt, response = response_queue.get()
print(f"You: {prompt}")
print(f"ChatGPT: {response}")Install with Tessl CLI
npx tessl i tessl/pypi-chatgptpy