Skip to main content

LLM extensions framework

Project description

GalaxyBrain

PyPI Version License Tests

Turn LLMs into mighty shape rotators!

GalaxyBrain is a workflow framework designed for large language models (LLMs). It allows developers to define prompt completion steps, prompt rules, result validators, and more. The framework also enhances LLM workflows by providing memory capabilities, enabling easy handling of state between steps.

Please note that GalaxyBrain is an experimental Python library in early development. Its APIs and documentation are subject to change. For usage examples, check out the examples repository which contains the most current examples of the library's usage.

Goals

  1. Reduce surprises when it comes to working with LLMs.
  2. Focus on production LLM 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 OpenAiCompletionDriver

load_dotenv()

driver = OpenAiCompletionDriver(os.environ.get('OPENAI_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 OpenAiCompletionDriver
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.meta.be_truthful(),
    rules.meta.your_name_is("GalaxyGPT"),
    Rule("only use information from fantasy novels")
]
driver = OpenAiCompletionDriver(temperature=0.5, user="demo")
workflow = Workflow(rules=chat_rules, completion_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"]
# }

Use ComputeStep to delegate computational tasks to Python:

ComputeStep(input=Prompt(f"generate two random 3x3 matrices and multiply them"))

This will generate the following code that GalaxyBrain runs locally and returns it to the LLM in the next prompt:

print(np.matmul(np.random.rand(3,3), np.random.rand(3,3)))

You can also ask more open-ended computational questions:

ComputeStep(input=Prompt(f"Sally is 5 feet tall, Jack is 14 inches taller than Sally. How tall is Jack?"))

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.5.tar.gz (15.6 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for galaxybrain-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a21e046bb600a56e70de3a0417cb17ab9a4c9aaa01cded8a391af6e5cef16845
MD5 d4fd7c51333007f4b9bd78c5bdf669e7
BLAKE2b-256 80cae0b551ea73d9f23123d3eca8d60d93bc836eb14d060d38e3a40642843e7b

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