Skip to main content

A simple library to add memory and semantic search to AI chatbots

Project description

StateCall

A simple Python library that adds memory to AI chatbots. StateCall remembers your conversations so AI can reference previous messages.

What it does

Most AI chatbots forget everything when you start a new conversation. StateCall saves your chat history so the AI can remember what you talked about before.

Features

  • Works with any AI service (OpenAI, Groq, Claude, etc.)
  • Built-in Groq support
  • Saves conversations locally on your computer
  • No database or internet connection needed
  • Simple to use
  • Export/import conversations (JSON/CSV)
  • Conversation statistics and analytics
  • NEW: Semantic search across conversations (find by meaning, not just keywords)

Installation

pip install statecall

Quick start

Basic usage

from statecall.memory import append_to_history, load_context
import openai

openai.api_key = "your-openai-api-key"
session_id = "my-chat"

# Save a message
append_to_history(session_id, "user", "Tell me a joke.")
history = load_context(session_id)

# Get AI response
response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=history
)

assistant_msg = response["choices"][0]["message"]["content"]
append_to_history(session_id, "assistant", assistant_msg)

print("AI:", assistant_msg)

Using Groq

from statecall.groq_client import GroqClient
from statecall.memory import append_to_history, get_session_history

session_id = "groq-chat"
client = GroqClient(api_key="your-groq-api-key")

append_to_history(session_id, "user", "Who won the World Cup in 2022?")
history = get_session_history(session_id)
response = client.chat(history)

append_to_history(session_id, "assistant", response)
print("AI:", response)

Export and Import

Export a conversation to JSON or CSV:

from statecall.memory import export_conversation, import_conversation

# Export to JSON
export_conversation("my-chat", "conversation.json", "json")

# Export to CSV
export_conversation("my-chat", "conversation.csv", "csv")

# Import a conversation
imported_session = import_conversation("conversation.json")

Get conversation statistics:

from statecall.memory import get_conversation_stats

stats = get_conversation_stats()
print(f"Total sessions: {stats['total_sessions']}")
print(f"Total messages: {stats['total_messages']}")

Semantic Search (NEW!)

Find conversations by meaning, not just keywords. Requires sentence-transformers:

pip install sentence-transformers

Search across all conversations:

from statecall import search_conversations

# Find conversations about programming
results = search_conversations("Python programming and coding")

for result in results:
    print(f"Found in {result['session_id']}: {result['content']}")
    print(f"Similarity: {result['similarity']:.3f}")

Find similar conversations:

from statecall import find_similar_conversations

# Find conversations similar to a specific session
similar = find_similar_conversations("my-coding-session", threshold=0.7)

for session in similar:
    print(f"Similar session: {session['session_id']} ({session['similarity']:.3f})")

Search within a session:

from statecall import search_in_session

# Search for specific topics within a conversation
results = search_in_session("my-session", "machine learning algorithms")

Extract conversation themes:

from statecall import get_conversation_themes

# Get main themes discussed in a conversation
themes = get_conversation_themes("my-session", num_themes=3)

for theme in themes:
    print(f"Theme {theme['theme_id']}: {len(theme['representative_messages'])} messages")

How it works

StateCall saves your conversations in local files on your computer:

  • .statecall_history.json - stores all your messages
  • .statecall_sessions.json - tracks your chat sessions
  • .statecall_embeddings.json - caches semantic embeddings for fast search

This way your conversations are saved between app restarts without needing a database.

Examples

Check the examples/ folder:

  • custom_llm_openai_example.py - using OpenAI
  • groq_chat_example.py - using Groq
  • export_import_example.py - export/import features
  • semantic_search_example.py - semantic search capabilities

To run an example:

python examples/groq_chat_example.py

License

MIT License

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

statecall-0.2.1.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

statecall-0.2.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file statecall-0.2.1.tar.gz.

File metadata

  • Download URL: statecall-0.2.1.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for statecall-0.2.1.tar.gz
Algorithm Hash digest
SHA256 037db3ff41506d070441d3163b0a8dba2136f55a37b1da203fa91ddf186c0f67
MD5 e60732f852aa407911e603b0b788dcca
BLAKE2b-256 ec663527f76a2581cb221e8be50e2f16486203f23f23bb77c8112bea97152711

See more details on using hashes here.

File details

Details for the file statecall-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: statecall-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for statecall-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e9fa0b0503386c23883a12f434a1d3651216e83021f5136a27dd063b9523c22
MD5 6f4f9f9df1657aefe7f4dbd42bf71dbd
BLAKE2b-256 a3632e012822a6a1f5391e4e167943c615e9b7894fe5fe726ca0ddb4f46722b6

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