Skip to main content

LLM extensions framework

Project description

GalaxyBrain

PyPI Version License

Turning LLMs into mighty shape rotators!

GalaxyBrain is a workflow framework for large language models (LLMs). With GalaxyBrain, developers can define prompt completion steps, prompt rules, result validators, and more. Additionally, the framework adds memory capabilities to LLM workflows making it easy to handle state between steps.

Goals

  1. Reduce surprises when it comes to working with LLMs.
  2. Focus on production use cases and CI/CD compatibility.
  3. Avoid bloat and keep base primitives simple.

Getting Started

First, install the library:

pip install galaxybrain

Currently, GalaxyBrain only supports OpenAI APIs, so you'll need to get an API key and keep it on your path as OPENAI_API_KEY or pass it to the driver object manually. For example:

import os
from dotenv import load_dotenv
from galaxybrain.drivers import OpenAiDriver

load_dotenv()

api_key = os.environ.get('OPENAI_KEY')
driver = OpenAiDriver(api_key)

Here is an example of some of GalaxyBrain's functionality:

from galaxybrain.rules import Rule, Validator
from galaxybrain.workflows import CompletionStep, Workflow
from galaxybrain.drivers import OpenAiDriver
from galaxybrain.prompts import Prompt
import galaxybrain.rules as rules


chat_rules = [
    rules.json.return_valid_json(),
    rules.json.put_answer_in_field("Names"),
    rules.conversation.be_truthful(),
    rules.conversation.your_name_is("GalaxyGPT"),
    Rule("only use information from fantasy novels")
]

driver = OpenAiDriver(temperature=0.5, user="demo")
workflow = Workflow(rules=chat_rules, driver=driver)

workflow.add_step(
    CompletionStep(input=Prompt("Give me ideas for two names from the same universe"))
)

workflow.start()

# Output:
# {
#     "Names": ["Frodo Baggins", "Gandalf the Grey"]
# }

workflow.add_step(
    CompletionStep(input=Prompt("Give me 3 more from another universe"))
)

workflow.resume()

# Output:
# {
#     "Names": ["Dumbledore", "Luna Lovegood", "Harry Potter"]
# }

You can also validate results against your rules:

validator = Validator(workflow.last_step().output, chat_rules)

if validator.validate():
    print("Rule validations passed")
else:
    print("Rule validations failed")
    print(validator.failed_rules())

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

galaxybrain-0.0.3.tar.gz (13.0 kB view details)

Uploaded Source

File details

Details for the file galaxybrain-0.0.3.tar.gz.

File metadata

  • Download URL: galaxybrain-0.0.3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for galaxybrain-0.0.3.tar.gz
Algorithm Hash digest
SHA256 17c6e367d08c63b9ef0f43ca22b179a0a05c884ee3e329dcea5b80faa397c94e
MD5 544b6ac6f5a40c6da814d0451ffc46ff
BLAKE2b-256 454535a08ac00aa2ace100e14d1fabd1bb862b0fa31431a21fe1cb32e7fa0f33

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page