Skip to main content

Convert between common LLM chat schemas

Project description

chatmux

Convert to and from common LLM chat schemas.

All implementations are built on pydantic base models to be network ready.

Installation

pip install chatmux

Usage

Fully OpenAI compatible pydantic models

from chatmux.openai import UserMessage, TextContentPart, ImageContentPart, ImageUrl

# Example using Pydantic models (more robust):
user_message = UserMessage(
    role="user",
    content=[
        TextContentPart(type="text", text="Describe this image:"),
        ImageContentPart(
            type="image_url",
            image_url=ImageUrl(url="https://example.com/image.jpg")
        )
    ]
)
openai_messages = [user_message.model_dump(exclude_none=True)] # Convert model to dict

Conversion methods to and from other schemas

from chatmux.convert import oai_to_qwen

qwen_messages = oai_to_qwen(openai_messages)
print(qwen_messages)
# Expected Output (structure based on oai_to_qwen):
# [
#     {
#         'role': 'user',
#         'content': [
#             {'type': 'text', 'text': 'Describe this image:'},
#             {'type': 'image', 'image': 'https://example.com/image.jpg'}
#         ]
#     }
# ]

Supported Conversions (as implemented in src/chatmux/convert.py):

  • OpenAI-like -> Unsloth Inference: Converts multimodal messages, downloads images, and formats for Unsloth. Returns new schema and PIL Images. (convert_to_unsloth_inference)
  • OpenAI-like -> Unsloth: Converts messages (potentially from JSONL), handling image URLs/base64, embedding PIL Images. (oai_to_unsloth)
  • OpenAI-like -> Qwen: Converts multimodal messages, keeping image URLs as strings but adjusting the content structure. (oai_to_qwen)

Contributing

Please open an issue before submitting a PR.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatmux-0.1.2.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chatmux-0.1.2-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file chatmux-0.1.2.tar.gz.

File metadata

  • Download URL: chatmux-0.1.2.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.29

File hashes

Hashes for chatmux-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6cb22d2db472d5ead2180fd01a7771b3dbce6944dffb2fac54e27b03958937e8
MD5 154db0cb8b42791ea4077db7f1759b07
BLAKE2b-256 845a62b86ef5609f33fd375d15f1eff4e8d75d264d373b9caeff1983e2ee940e

See more details on using hashes here.

File details

Details for the file chatmux-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: chatmux-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.29

File hashes

Hashes for chatmux-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9d776dcba97bda22402ff77d01eb9efa7ec5f9ff59abfaf97d83ff9dccf33a70
MD5 9a43efa95abbf9b30e08c50f09687dd2
BLAKE2b-256 2428d8b754d58a611c29645890720d16af8d44f397c0fc44ec67a7ee62e93a8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page