chat-object


Namechat-object JSON
Version 2.0.2 PyPI version JSON
download
home_pageNone
SummaryA simple library for creating and manipulating chat and message objects for LLM applications
upload_time2025-08-17 14:08:27
maintainerNone
docs_urlNone
authorfresh-milkshake
requires_python>=3.10
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # chat-object

[![doctest coverage](https://img.shields.io/badge/doctest-90%25_coverage-00796b)](https://gist.github.com/fresh-milkshake/48a14bcc9c753a99d0af6935eb96e056)
[![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE.txt)
![python](https://img.shields.io/badge/python-3.10%2B-306998)
[![version](https://img.shields.io/pypi/v/chat-object?color=white&label=version)](https://pypi.org/project/chat-object/)
[![PyPI Downloads](https://static.pepy.tech/badge/chat-object?color=6c757d)](https://pepy.tech/projects/chat-object)

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

## Installation

From PyPI:

```bash
pip install chat-object
```

From GitHub:

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

Or from source:

```bash
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:

```python
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:

```python
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:

```python
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](examples) folder for more comprehensive examples.

## Features

- **Well-tested code**: Comprehensive test coverage with doctests throughout the codebase ([90% coverage](https://gist.github.com/fresh-milkshake/48a14bcc9c753a99d0af6935eb96e056))
- **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](examples/openai_use_case.py).

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "chat-object",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "fresh-milkshake",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/8f/52/1c71308aaf873213b56937fd018b562037914f70523cdb4252cb61261a6e/chat_object-2.0.2.tar.gz",
    "platform": null,
    "description": "# chat-object\r\n\r\n[![doctest coverage](https://img.shields.io/badge/doctest-90%25_coverage-00796b)](https://gist.github.com/fresh-milkshake/48a14bcc9c753a99d0af6935eb96e056)\r\n[![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE.txt)\r\n![python](https://img.shields.io/badge/python-3.10%2B-306998)\r\n[![version](https://img.shields.io/pypi/v/chat-object?color=white&label=version)](https://pypi.org/project/chat-object/)\r\n[![PyPI Downloads](https://static.pepy.tech/badge/chat-object?color=6c757d)](https://pepy.tech/projects/chat-object)\r\n\r\nA simple library for creating and managing chat objects and messages for LLM applications.\r\n\r\n## Installation\r\n\r\nFrom PyPI:\r\n\r\n```bash\r\npip install chat-object\r\n```\r\n\r\nFrom GitHub:\r\n\r\n```bash\r\npip install git+https://github.com/fresh-milkshake/chat-object.git\r\n```\r\n\r\nOr from source:\r\n\r\n```bash\r\ngit clone https://github.com/fresh-milkshake/chat-object.git\r\ncd chat-object\r\npip install -e .\r\n```\r\n\r\n## Quick Start\r\n\r\n### Basic Chat Usage\r\n\r\nCreate a chat object and add messages to it:\r\n\r\n```python\r\nimport openai\r\nfrom chat_object import Chat, Message, Role\r\n\r\nclient = openai.OpenAI()\r\n\r\nchat = Chat(\r\n    Message(Role.System, \"You are a helpful assistant\"),\r\n    Message(Role.User, \"Hello!\")\r\n)\r\n\r\nresponse = client.chat.completions.create(\r\n    model=\"gpt-5-nano\",\r\n    messages=chat.as_dict()\r\n)\r\n\r\nprint(response.choices[0].message.content)\r\n```\r\n\r\n### Using the Prompt Class\r\n\r\nThe `Prompt` class automatically handles indentation and formatting:\r\n\r\n```python\r\nfrom chat_object import Prompt\r\n\r\n# Clean indentation automatically\r\nprompt = Prompt(\"\"\"\r\n    You are a helpful assistant.\r\n    Please help me with the following task:\r\n    \r\n    def example_function():\r\n        return \"hello world\"\r\n    \r\n    Explain what this function does.\r\n\"\"\")\r\n\r\n# Multiple arguments are joined with newlines\r\nprompt = Prompt(\r\n    \"You are a helpful assistant.\",\r\n    \"Please be concise in your responses.\",\r\n    \"Focus on practical solutions.\"\r\n)\r\n\r\n# String operations work naturally\r\nprompt += \"\\n\\nAdditional context here\"\r\n```\r\n\r\n### QOL Features for Quick Development\r\n\r\nUse convenience functions for faster development:\r\n\r\n```python\r\nfrom chat_object import chat, msg_user, msg_system, msg_assistant, prmt\r\n\r\n# Quick chat creation\r\nchat_obj = chat(\r\n    msg_system(\"You are a helpful assistant.\"),\r\n    msg_user(\"Hello!\"),\r\n    msg_assistant(\"Hi there! How can I help you today?\")\r\n)\r\n\r\n# Quick prompt creation\r\nprompt = prmt(\"You are a helpful assistant.\")\r\n\r\n# Convert to dict for API calls\r\nmessages = chat_obj.as_dict()\r\n```\r\n\r\n> [!TIP]\r\n> See [examples](examples) folder for more comprehensive examples.\r\n\r\n## Features\r\n\r\n- **Well-tested code**: Comprehensive test coverage with doctests throughout the codebase ([90% coverage](https://gist.github.com/fresh-milkshake/48a14bcc9c753a99d0af6935eb96e056))\r\n- **Type safety**: Full type hints and enum-based roles\r\n- **Backward compatibility**: seamless integration with existing APIs like OpenAI, Anthropic, Together, Ollama, etc.\r\n- **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](examples/openai_use_case.py).\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A simple library for creating and manipulating chat and message objects for LLM applications",
    "version": "2.0.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1d87da6ebb56f7625d72cdb5a6c07708421bccbdd16ad521db1f258a9375450f",
                "md5": "737fb6546a636a6bd9555b33df761f87",
                "sha256": "0afe6ad2ce8dc32651dac71c05ee5e0edade14f4f0596ce406d6a23073cebec2"
            },
            "downloads": -1,
            "filename": "chat_object-2.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "737fb6546a636a6bd9555b33df761f87",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12533,
            "upload_time": "2025-08-17T14:08:26",
            "upload_time_iso_8601": "2025-08-17T14:08:26.262947Z",
            "url": "https://files.pythonhosted.org/packages/1d/87/da6ebb56f7625d72cdb5a6c07708421bccbdd16ad521db1f258a9375450f/chat_object-2.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8f521c71308aaf873213b56937fd018b562037914f70523cdb4252cb61261a6e",
                "md5": "c09c6bfc4e5abf41cd1197151fc07e16",
                "sha256": "a8a9da1ee5e8ca3cf028bc7276631299ba89b512ec84792c6b8403cca3f9c1db"
            },
            "downloads": -1,
            "filename": "chat_object-2.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c09c6bfc4e5abf41cd1197151fc07e16",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 11595,
            "upload_time": "2025-08-17T14:08:27",
            "upload_time_iso_8601": "2025-08-17T14:08:27.501152Z",
            "url": "https://files.pythonhosted.org/packages/8f/52/1c71308aaf873213b56937fd018b562037914f70523cdb4252cb61261a6e/chat_object-2.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-17 14:08:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "chat-object"
}
        
Elapsed time: 1.91216s