This release is a pre-release and may not be stable for production use.
A Python 2+ library for conversations with LLMs providing an OpenAI Chat Completions-compatible API. That includes OpenAI's models, Google Gemini, DeepSeek, and anything you can run on ollama.
Features
- Compatibility: Unlike openai, works on Python 2+ with zero non-Python dependencies.
- Streaming Responses: Obtain responses as they're generated.
- Conversation Persistence: Save/load conversations in JSON format.
Installation
pip install chat-completions-conversation
Usage
Suppose we interface with a VLM, and have the following messages.json file under the current working directory:
[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/640px-PNG_transparency_demonstration_1.png"
}
},
{"type": "text", "text": "Describe what's in this image."},
{"type": "text", "text": "Then, describe this dog."},
{
"type": "image_url",
"image_url": {
"url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d"
}
},
{"type": "text", "text": "What are the main differences between them?"}
]
}
]
By running this code:
# coding=utf-8
from __future__ import print_function
from chat_completions_conversation import ChatCompletionsConversation
# Initialize conversation
conv = ChatCompletionsConversation(
api_key=u'...',
base_url=u'https://api.openai.com/v1',
model=u'gpt-4.1'
)
# Load conversation
conv.load_from_json_file(u'messages.json')
# Add a message to the model's message list without obtaining a response
conv.append_user_message(u'Also give me subjective feedback regarding the images.')
# Print messages
print(u'Messages: """', end=u'')
print(conv.export_to_text(), end=u'')
print(u'"""')
print()
# Create message and stream response
print(u'Assistant response: """', end=u'')
for chunk in conv.send_and_stream_response(u'Help me with the above tasks.'):
print(chunk, end=u'')
print(u'"""')
print()
# Save conversation
conv.save_to_json_file(u'new-messages.json')
# Print messages
print(u'Messages after assistant response: """', end=u'')
print(conv.export_to_text(), end=u'')
print(u'"""')
we can get this output:
Messages: """..."""
Assistant response: """..."""
Messages after assistant response: """..."""
What ... actually varies from model to model and from run to run. We embrace randomness and make ZERO effort in regularizing model output.
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Release files for chat-completions-conversation 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chat_completions_conversation-0.1.0a1.tar.gz | 7.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chat_completions_conversation-0.1.0a1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 15.4 kB
Release files / chat_completions_conversation-0.1.0a1.tar.gz
| Download URL | chat_completions_conversation-0.1.0a1.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a67c553b8aa6b90d5c871074b47d84d1fba79da9380170cca7b462e4f5a3fdb6
|
|
BLAKE2b-256 checksum How to use checksums |
3b8237b26640c4365a6b902875ad89857da6262d3ecd8bdfb23520f9a1beafbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|
Release files / chat_completions_conversation-0.1.0a1-py2.py3-none-any.whl
| Download URL | chat_completions_conversation-0.1.0a1-py2.py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1eb18d96c85ece502d3572783b07ac2e976ac17275123313f3c70cdd4a7a9d49
|
|
BLAKE2b-256 checksum How to use checksums |
9a96b29680db399dcb31caa564237b8549ccdbf77ddb61303098777cf634816f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.2
|