Skip to main content

Operate with Lumen Brain API in Python straight forwardly

Project description

Lumen Brain Python Client

A Python client library for interacting with the Lumen Brain API. GitHub: https://github.com/Lumen-Labs/lumen-brain

Features

On-demand memory/context driver to interact with the Lumen Brain API and improve the context and responses of LLMs without finetuning.

Installation

pip install lumen-brain

Usage

Async Client

from lumen_brain import AsyncLumenBrainDriver

# Initialize the client
client = AsyncLumenBrainDriver(api_key="your-api-key")

# Save a message
await client.save_message(
    memory_uuid="your-memory-uuid", # the unique identifier provided by your app, if not provided, a new memory will be created
    type="message",
    content="Your message content",
    role="user",

    # Optional Fields
    conversation_id="your-conversation-id", # If not provided, a new conversation will be created
    metadata={"key": "value"}
)

# Query memory
# The result will be a MemoryUpdateResponse object with a context field
# the context field can be appended to the message that will be sent to the agent to improve the agent's response
# allowing the agent to have a more accurate and relevant context around the user's message
result = await client.query_memory(
    text="Your query",
    memory_uuid="your-memory-uuid", # the unique identifier provided by your app, if not provided, a new memory will be created
    conversation_id="your-conversation-id"
)

# Inject knowledge
# additional knowledge can be injected into the memory, for example if you are synking the user's emails, files etc.
# works also if you want the agent to answer better arount a specific topic like documents etc.

await client.inject_knowledge(
    memory_uuid="your-memory-uuid", # the unique identifier provided by your app, if not provided, a new memory will be created
    type="message",
    content="Your message content",
    resource_type="file",

    # Optional Fields
    metadata={"key": "value"}
)

Sync Client

from lumen_brain import LumenBrainDriver

# Initialize the client
client = LumenBrainDriver(api_key="your-api-key")

# Save a message
client.save_message(
    memory_uuid="your-memory-uuid",
    type="message",
    content="Your message content",
    role="user"
)

# Query memory
result = client.query_memory(
    text="Your query",
    memory_uuid="your-memory-uuid",
    conversation_id="your-conversation-id"
)

Fetch info

result = client.fetch_info(
    memory_uuid="your-memory-uuid", # the unique identifier provided by your app, if not provided, a new memory will be created
    entities=["john"], # the entities that are related to the information to be retrieved
    info="wedding date", # the information to be retrieved
    depth=2 # the higher relation depth that will be looked for
)
result.nodes # the nodes that are related to the information to be retrieved
result.most_relevant_relation # the most relevant relation between the entities and the information to be retrieved
result.most_relevant_confidence # the confidence of the most relevant relation (0-1)

License

This project is licensed under the 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

lumen_brain-0.3.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

lumen_brain-0.3.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file lumen_brain-0.3.1.tar.gz.

File metadata

  • Download URL: lumen_brain-0.3.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.4 Darwin/24.2.0

File hashes

Hashes for lumen_brain-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8ea0f6889161e5cbfe21886a1c851e9fd8b303829c9e1ff67a733ee09fbfa625
MD5 8ce951c0d6a6d2d74b0f40e3244b54f8
BLAKE2b-256 ddcf43ff746d0effe7b0ed69e9310680c5d316b41397c97fbb1eabd38be5a00e

See more details on using hashes here.

File details

Details for the file lumen_brain-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: lumen_brain-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.4 Darwin/24.2.0

File hashes

Hashes for lumen_brain-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69dc65780b5f44abdd8c28e9cd321aedd0e371573ce9086af25184d07bc868ca
MD5 0753e49803013ffd76daf2ebb29ce503
BLAKE2b-256 748a801f8e89ea1321c9bbce3d2c077b38ed6dfd614f86a1b7daf671dc6c6fb8

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