simple, stateful conversations with OpenAI's chat models, including truncation and token metering
Project description
gptsession
Simple, stateful conversations with OpenAI's chat models, including truncation and token metering.
gptsession is a lightweight Python module for managing structured, multi-turn conversations with OpenAI’s ChatGPT models. It supports multiple concurrent sessions, automatic token tracking, message truncation, and full conversation recording.
📦 Installation
pip install gptsession
✨ Features
- Supports multiple parallel chat sessions
- Token-aware truncation based on model limits
- Tracks actual tokens sent and received
- Maintains full untruncated conversation history
- Clean, minimal API:
setup(),say(),system(),model(), etc.
🚀 Quick Start
import gptsession
gptsession.setup(open("mykey.txt").read().strip())
gptsession.new()
gptsession.model("gpt-3.5-turbo")
gptsession.system("You are a helpful assistant.")
reply = gptsession.say("Hello! Can you explain recursion?")
print("ChatGPT:", reply)
if gptsession.truncated():
print("[Note: Earlier messages were removed to stay within token limits.]")
🔄 Multiple Sessions Example
import gptsession as gpt
gpt.setup(open("mykey.txt").read().strip())
s1 = gpt.new()
gpt.system("You are a bird.")
s2 = gpt.new()
gpt.system("You are a robot.")
gpt.sel(s1)
print(gpt.say("Where do you live?"))
gpt.sel(s2)
print(gpt.say("Where do you live?"))
📄 License
MIT License
© 2025 Lion Kimbro
🌐 Project Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gptsession-1.0.0.tar.gz.
File metadata
- Download URL: gptsession-1.0.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9992d3217479c526e278bac599871141bb4fa6671b344b0c01df35c24cc0d7f9
|
|
| MD5 |
c895fde8d206fff6020e1d1263b65fe6
|
|
| BLAKE2b-256 |
5da35c372879ca9a010e920427a0287cbb0134a399867ea5c1700c04fd341f91
|
File details
Details for the file gptsession-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gptsession-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d563f9462d3cdcbd15b432c850fd769bb08a1152c253bfdbf1021404c85921d4
|
|
| MD5 |
798a5eb6acd57c1e2184e4b28fdc2a23
|
|
| BLAKE2b-256 |
4a96e5c56f7ea580a13cd75ff86e4c15c57e2a6747b7e379f8b6ab6f8fcc06f8
|