Skip to content

simple, stateful conversations with OpenAI's chat models, including truncation and token metering

License

Notifications You must be signed in to change notification settings

LionKimbro/gptsession

Repository files navigation

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

About

simple, stateful conversations with OpenAI's chat models, including truncation and token metering

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages