Skip to main content

LLM extensions framework

Project description

GalaxyBrain

PyPI Version License

Turning LLMs into mighty shape rotators!

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. You can then either keep it on your path as OPENAI_API_KEY or pass it to the completion object manually:

api_key = ...
OpenAiCompletion(api_key)

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

from galaxybrain.completions import OpenAiCompletion
from galaxybrain.memory import Memory
from galaxybrain.prompts import Prompt
import galaxybrain.rules.json as json_rules
from galaxybrain.completions import Validator


completion = OpenAiCompletion(api_key, temperature=0.9, user="demo")
memory = Memory()
rules = [
    json_rules.return_valid_json(),
    json_rules.put_answer_in_field("Names"),
    Rule("only use information from fantasy novels")
]

completion.complete(
    Prompt("Give me ideas for two names from the same universe", memory=memory, rules=rules)
)

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

result = completion.complete(
    Prompt("Give me 3 more from another universe", memory=memory)
)

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

You can also validate results against your rules:

validator = Validator(result, 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.2.tar.gz (10.7 kB view hashes)

Uploaded Source

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