ChatAssist
An advanced, provider-agnostic Python library for chatting with LLMs.
Works with OpenAI, OpenRouter, a local Ollama server, or any endpoint that
speaks the OpenAI-compatible /chat/completions format.
Made by تیروتیر — tirotir.ir.
What's new in 0.2.0
- Multi-provider support:
provider="openai","openrouter","ollama", or a fully custombase_url - Streaming responses:
stream_message()yields text as it's generated - Multi-turn context: pass
history=to keep a real conversation going, not just single-shot messages - System prompts: set a persona/instructions once, reused across turns
- API key optional: not required for local Ollama
- Env var support:
CHATASSIST_API_KEYorOPENAI_API_KEY - Fixed CLI packaging:
chatassist-clinow actually installs as a command (this was broken in 0.1.0) - Interactive CLI chat mode: just run
chatassist-cliwith no message for a REPL - Markdown export for conversations, alongside JSON
ChatGPTAPIis kept as a backward-compatible alias for existing code
Installation
pip install chatassist
Quick start
OpenAI
from chatassist import LLMClient
client = LLMClient(provider="openai", api_key="sk-...")
print(client.send_message("Hello!"))
OpenRouter
client = LLMClient(
provider="openrouter",
api_key="sk-or-...",
model="anthropic/claude-3.5-sonnet",
)
print(client.send_message("Hello!"))
Local Ollama (no API key needed)
client = LLMClient(provider="ollama", model="llama3.2")
print(client.send_message("Hello!"))
Any custom OpenAI-compatible endpoint
client = LLMClient(
base_url="https://my-llm-gateway.internal/v1/chat/completions",
api_key="...",
model="my-model",
)
Streaming
for chunk in client.stream_message("Write a short poem about the sea."):
print(chunk, end="", flush=True)
Multi-turn conversations
from chatassist import LLMClient, Conversation
client = LLMClient(provider="ollama", model="llama3.2", system_prompt="You are terse.")
conversation = Conversation(system_prompt="You are terse.")
for user_msg in ["Hi!", "What's 2+2?", "And times 10?"]:
reply = client.send_message(user_msg, history=conversation.as_api_messages())
conversation.add_message("user", user_msg)
conversation.add_message("assistant", reply)
print(reply)
conversation.save_to_file("conversation.json")
conversation.export_markdown("conversation.md")
Command-line interface
# One-shot message
chatassist-cli "What is the capital of France?" --provider openai --api-key sk-...
# OpenRouter with a specific model
chatassist-cli "Summarize the plot of Dune" --provider openrouter --api-key sk-or-... --model anthropic/claude-3.5-sonnet
# Local Ollama, streamed
chatassist-cli "Tell me a joke" --provider ollama --model llama3.2 --stream
# Interactive REPL (omit the message)
chatassist-cli --provider ollama --model llama3.2
# Export the session
chatassist-cli "Hello" --export chat.json --export-markdown chat.md
Graphical User Interface
python -m chatassist.gui
On launch you'll get a small setup dialog to pick a provider, model, and API key (skip the key for Ollama) before the chat window opens.
20 examples, simple → advanced
The examples/ directory is a full lesson plan: 20
standalone, runnable scripts going from a one-line "hello world" up to
streaming multi-turn chat, provider fallback, side-by-side model
comparison, and a small FastAPI web service. See
examples/README.md for the full index (in
Persian, with English code/comments).
git clone https://github.com/tirotir-ir/chatassist.git
cd chatassist
pip install -e .
export OPENAI_API_KEY=sk-...
python examples/01_hello_world_openai.py
Development
pip install -e ".[dev]"
pytest tests/ -v # runs fully offline, no API key needed
Configuration reference
| Parameter | Description |
|---|---|
provider |
"openai", "openrouter", or "ollama" preset |
base_url |
Custom endpoint, overrides the provider preset |
model |
Model name; defaults to a sensible per-provider default |
api_key |
API key; falls back to CHATASSIST_API_KEY / OPENAI_API_KEY env vars, then api_key.txt |
system_prompt |
Optional system message sent with every request |
temperature, top_p, max_tokens |
Standard sampling controls |
proxies |
Optional requests-style proxy dict |
Contributing
See CONTRIBUTING.md.
License
MIT License — see LICENSE.
ساخته و نگهداریشده توسط تیروتیر
Metadata
Release files for chatassist 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chatassist-0.2.0.tar.gz | 15.1 kB | Without provenance | Details for chatassist-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chatassist-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for chatassist-0.2.0-py3-none-any.whl |
Total release size: 29.0 kB
Release files / chatassist-0.2.0.tar.gz
| Download URL | chatassist-0.2.0.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fe82dfe8e732465ecfa988bc677905cd9f98646f1f59e7367327afad0c8ad26
|
|
BLAKE2b-256 checksum How to use checksums |
6c99003d72defefb7aaf4d497a1a60e91afd438e2b40cf98ec560db23ba4319c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / chatassist-0.2.0-py3-none-any.whl
| Download URL | chatassist-0.2.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fd24adf8036f39c87f8ce4904c05967a46ed6d13122b0ce65b08c525e48d8e3
|
|
BLAKE2b-256 checksum How to use checksums |
00aa91bc15950485854d21922b8c4c46965823cc6361c8b01b17b8116736ad65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for chatassist 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.