Quick Start Guide
This guide will help you get started with chat-object in just a few minutes.
Installation
Install the package using pip:
pip install chat-object
First Steps
Import the library:
from chat_object import Chat, Message, Role
Create your first chat:
chat = Chat( Message(Role.System, "You are a helpful assistant"), Message(Role.User, "Hello!") )
Use with OpenAI:
import openai client = openai.OpenAI() response = client.chat.completions.create( model="gpt-5-nano", messages=chat.as_dict() )
Add the response to your chat:
chat.add_message(Message(Role.Assistant, response.choices[0].message.content))
Complete Example
Here’s a complete working example:
import openai
from chat_object import Chat, Message, Role
# Initialize OpenAI client
client = openai.OpenAI()
# Create a chat with system message
chat = Chat(
Message(Role.System, "You are a helpful coding assistant. Provide concise answers.")
)
# Add user message
chat.add_message(Message(Role.User, "Write a Python function to reverse a string"))
# Get response from OpenAI
response = client.chat.completions.create(
model="gpt-5-nano",
messages=chat.as_dict()
)
# Add assistant response to chat
assistant_message = response.choices[0].message.content
chat.add_message(Message(Role.Assistant, assistant_message))
# Continue the conversation
chat.add_message(Message(Role.User, "Can you make it handle None values?"))
# Get another response
response = client.chat.completions.create(
model="gpt-5-nano",
messages=chat.as_dict()
)
print(response.choices[0].message.content)
Using QOL Functions
For even faster development, use the convenience functions:
from chat_object import chat, msg_system, msg_user, msg_assistant
# Quick chat creation
chat_obj = chat(
msg_system("You are a helpful assistant"),
msg_user("Hello!"),
msg_assistant("Hi there! How can I help you?")
)
# Add more messages easily
chat_obj.add_message(msg_user("What's the weather like?"))
Using the Prompt Class
For better prompt formatting:
from chat_object import Prompt
# Automatic indentation cleanup
prompt = Prompt("""
You are a helpful assistant.
Please help me with this code:
def example():
return "hello"
""")
print(prompt) # Clean, properly formatted prompt
Next Steps
Read the Examples for more advanced usage
Check the API Reference for complete API reference
Explore the source code on GitHub