Skip to main content

chat-object

doctest coverage license python version PyPI Downloads

A simple library for creating and managing chat objects and messages for LLM applications.

Installation

From PyPI:

pip install chat-object

From GitHub:

pip install git+https://github.com/fresh-milkshake/chat-object.git

Or from source:

git clone https://github.com/fresh-milkshake/chat-object.git
cd chat-object
pip install -e .

Quick Start

Basic Chat Usage

Create a chat object and add messages to it:

import openai
from chat_object import Chat, Message, Role

client = openai.OpenAI()

chat = Chat(
    Message(Role.System, "You are a helpful assistant"),
    Message(Role.User, "Hello!")
)

response = client.chat.completions.create(
    model="gpt-5-nano",
    messages=chat.as_dict()
)

print(response.choices[0].message.content)

Using the Prompt Class

The Prompt class automatically handles indentation and formatting:

from chat_object import Prompt

# Clean indentation automatically
prompt = Prompt("""
    You are a helpful assistant.
    Please help me with the following task:
    
    def example_function():
        return "hello world"
    
    Explain what this function does.
""")

# Multiple arguments are joined with newlines
prompt = Prompt(
    "You are a helpful assistant.",
    "Please be concise in your responses.",
    "Focus on practical solutions."
)

# String operations work naturally
prompt += "\n\nAdditional context here"

QOL Features for Quick Development

Use convenience functions for faster development:

from chat_object import chat, msg_user, msg_system, msg_assistant, prmt

# 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 today?")
)

# Quick prompt creation
prompt = prmt("You are a helpful assistant.")

# Convert to dict for API calls
messages = chat_obj.as_dict()

[!TIP] See examples folder for more comprehensive examples.

Features

  • Well-tested code: Comprehensive test coverage with doctests throughout the codebase (90% coverage)
  • Type safety: Full type hints and enum-based roles
  • Backward compatibility: seamless integration with existing APIs like OpenAI, Anthropic, Together, Ollama, etc.
  • QOL features: Quick and easy message creation with msg_user, msg_assistant, msg_system, prmt, msgs, chat (Recommended, but not required). Pretty rich example usage of qol features is in examples/openai_use_case.py.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Release files for chat-object 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chat-object 2.0.2
File Size Uploaded
chat_object-2.0.2.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chat-object 2.0.2
File Interpreter ABI Platform
chat_object-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / chat_object-2.0.2.tar.gz

Download URL chat_object-2.0.2.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a8a9da1ee5e8ca3cf028bc7276631299ba89b512ec84792c6b8403cca3f9c1db
BLAKE2b-256 checksum
How to use checksums
8f521c71308aaf873213b56937fd018b562037914f70523cdb4252cb61261a6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.11

Release files / chat_object-2.0.2-py3-none-any.whl

Download URL chat_object-2.0.2-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0afe6ad2ce8dc32651dac71c05ee5e0edade14f4f0596ce406d6a23073cebec2
BLAKE2b-256 checksum
How to use checksums
1d87da6ebb56f7625d72cdb5a6c07708421bccbdd16ad521db1f258a9375450f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.11

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page