Skip to main content

Echo is a lightweight and intuitive Python library for building and managing LLM-based chat conversations.

Project description

Echo

Echo is a lightweight and intuitive Python library for building and managing LLM-based chat conversations
It provides structured tools for managing chat, including FIFO queue management,
conversation topic evaluation, pertinence filtering, archiving, and more

Features

  • Capacity: Limit the number of messages stored in the conversation (FIFO)
  • Topic evaluation: Evaluate the topic of the conversation and update it dynamically
  • Pertinence filtering: Filter out irrelevant messages based on the current topic
  • Archive messages: Archive the original message, keep a summarized version in the chat

Algorithms

Topic Evaluation

  • Init Message Topic (IMT) - The conversation topic is inferred solely from the content of the first message
  • Nth Message Topic (NMT) - The conversation topic is inferred from the content of the first N messages
  • Anchored Topic Evaluation (ATE) - The conversation topic is initially anchored using the first N messages
    Afterward, the topic is dynamically re-evaluated with each new message,
    allowing the model to adapt to topic shifts while maintaining stability around the original anchor
    A new message may or may not affect the topic,
    depending on whether it introduces a significant shift in content relative to the anchor

gemini.py

import google.generativeai as genai
from synapse import Synapse

class GeminiClient(Synapse):
    def __init__(self, model_name: str = "gemini-2.5-flash-lite"):
        genai.configure(api_key='<API Key>')
        self.model = genai.GenerativeModel(model_name)

    def prompt(self, text: str) -> str:
        """ Sends a single string to the model and returns the text response """
        try:
            response = self.model.generate_content(text)
            return response.text
        except Exception as e:
            return f"An error occurred: {e}"

main.py

# main.py

client = GeminiClient()

rec = Record(
    synapse=client,
    topic_evaluation_algorithm='SATE2'
)

rec.add(
    Message(
        text="Hello World",
        author='John Doe'
    )
)

Examples

Archive Example

[Message]
"""
The capital city of England is London.
London is a large, historic, and highly influential city located in the southeast of England, along the River Thames.
It has been a major settlement for nearly 2,000 years, originally founded by the Romans as Londinium.
Key characteristics:
- Political center: Home to the UK government, Parliament, and the Prime Minister’s residence at 10 Downing Street.
- Cultural hub: Famous landmarks include Big Ben, Buckingham Palace, Tower Bridge, and the British Museum.
- Economic powerhouse: One of the world’s leading financial centers, especially around the City of London and Canary Wharf.
- Diverse and global: Known for its multicultural population, languages, food, and arts.
- Transport and infrastructure: Extensive public transport, including the London Underground, one of the oldest metro systems in the world.
- London combines deep historical roots with modern global influence, making it one of the most important cities in the world.
"""

[Distilled Message]
"Description of London, England. (Archived 9e63c59908b84572bb6356af3db6a015)"

Pertinence Filter and Topic Evaluation Examples

1. Topic Evaluation Algorithm: Non-Strict Init Message Topic (NSIMT)

[Messages]
"The sky is blue."
"The sun is yellow."
"My name is John Doe."
"I am 21 years old."

[Evaluated Topic]
"Observations of the world"

[Included Messages]
"The sky is blue."
"The sun is yellow."

[Excluded Messages]
"My name is John Doe."
"I am 21 years old."

2. Topic Evaluation Algorithm: Strict Init Message Topic (SIMT)

[Messages]
"The sky is blue."
"The sun is yellow."
"My name is John Doe."
"I am 21 years old."

[Evaluated Topic]
"The Sky's Color"

[Included Messages]
"The sky is blue."
"The sun is yellow."

[Excluded Messages]
"My name is John Doe."
"I am 21 years old."

3. Topic Evaluation Algorithm: Non-Strict Nth Message Topic - First 2 Messages (NSNMT2)

[Messages]
"The sky is blue."
"The sun is yellow."
"My name is John Doe."
"I am 21 years old."

[Evaluated Topic]
"Observations about the environment"

[Included Messages]
"The sky is blue."
"The sun is yellow."

[Excluded Messages]
"My name is John Doe."
"I am 21 years old."

4. Topic Evaluation Algorithm: Strict Nth Message Topic - First 2 Messages (SNMT2)

[Messages]
"The sky is blue."
"The sun is yellow."
"My name is John Doe."
"I am 21 years old."

[Evaluated Topic]
"Sky and Sun Colors"

[Included Messages]
"The sky is blue."
"The sun is yellow."

[Excluded Messages]
"My name is John Doe."
"I am 21 years old."

5. Topic Evaluation Algorithm: Non-Strict Anchored Topic Evaluation - First 2 Messages (NSATE2)

[Messages]
"The sky is blue."
"The sun is yellow."
"My name is John Doe."
"I am 21 years old."

[Evaluated Topic]
"Observations about the natural world"

6. Topic Evaluation Algorithm: Strict Anchored Topic Evaluation - First 2 Messages (SATE2)

[Messages]
"The sky is blue."
"The sun is yellow."
"My name is John Doe."
"I am 21 years old."

[Evaluated Topic]
Sky and Sun Colors

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

python_echo-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

python_echo-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file python_echo-0.1.0.tar.gz.

File metadata

  • Download URL: python_echo-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for python_echo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 47decdcf8d1678ff1d47cd8b14938bbf995150fc53b563398146b561039c9305
MD5 5858f39b96868a27796628d10ed6073c
BLAKE2b-256 a68aa9ff101870fadda727a40c62ef3dfec271f3d7bba33d3db7e9d45f0ef09c

See more details on using hashes here.

File details

Details for the file python_echo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_echo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for python_echo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edf03f40cb70cb9151bfd2d370c5525c9fa0fe6bf67dc3ec438b8c261f873dbf
MD5 97b557a57ce131750ffc9f60a97a36bf
BLAKE2b-256 0478de1ab98affb047f6d2b99cc27a23df36249e4022ae725e22688665ca0770

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