No project description provided
Project description
LLambda
LLambda is a library that makes it easy to integrate Large Language Models (LLM) and Python. It enables calling multiple pre-defined functions using natural language and executing them with appropriate arguments.
Installation
You can easily install LLambda using pip:
pip install llambda
Usage
Here is a basic usage example. The following code defines two functions and calls them using natural language.
Registering Functions with Decorators
from llambda import register
@register
def make_coffee(n_cups: int) -> str:
"""
Make coffee of the amount you want.
Can't make tea.
"""
return "☕" * n_cups
@register
def send_email(recipient_name: str, subject: str, content: str, your_name: str) -> str:
"""
Send an email to someone.
"""
return f"Sent email to {recipient_name} with subject '{subject}'\nand content '{content}' from {your_name}"
Now we have two functions. Let's call them using natural language:
from llambda import create_llambda, set_openai_api_key
set_openai_api_key("Your OpenAI API Key")
llambda = create_llambda()
print(llambda("I want to drink 3 cups of coffee"))
# ☕☕☕
print(llambda("Write an email in which GPT shares the method for training neural networks with Adam."))
# Sent email to Adam with subject 'Training Neural Networks'
# and content'Hey there! I wanted to share my method for training neural networks. Let's discuss soon!' from GPT
LLambda automatically recognizes the functions and their arguments, and calls the appropriate function with the arguments inferred from the instruction.
print(llambda("I want to drink 3 cups of tea"))
# NotImplementedError: Can't make tea.
LLambda raises NotImplementedError when it cannot find a function that matches the instruction.
Directly Passing Functions
In addition to using the @register decorator, you can also directly pass the functions to create_llambda.
llambda = create_llambda([make_coffee, send_email])
print(llambda("I want to drink 3 cups of coffee"))
# ☕☕☕
Custom Context
Using ContextVars Class
Functions
can access context variables by defining a subclass of ContextVars. The class variables of this subclass will be automatically recognized as context variables:
class Context(ContextVars):
your_name: str = "GPT"
your_friends: list[str] = ["Adam", "Bert"]
llambda = create_llambda(context=Context)
print(llambda("Share with your friend about your method for training neural networks"))
# Sent email to Adam with subject 'Training Neural Networks'
# and content'Hey there! I wanted to share my method for training neural networks. Let's discuss soon!' from GPT
Directly Passing ContextVar Instances
You can also pass the context directly as a list of ContextVar instances:
context_vars = [
ContextVar("your_name", "str", "GPT"),
ContextVar("your_friends", "list[str]", ["Adam", "Bert"])
]
llambda = create_llambda(context=context_vars)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llambda-0.1.0a1.tar.gz.
File metadata
- Download URL: llambda-0.1.0a1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.9 Linux/4.19.104-microsoft-standard
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4421007a866095ad77d4f67662fe73fee3000dd3567845351b5defd9a4baf24
|
|
| MD5 |
89fbb6335f8a30142cdf586f471799aa
|
|
| BLAKE2b-256 |
541c9f2ae6357fdede608293931ebe5a6dd22d55e9734479d38a3ddd63a5d255
|
File details
Details for the file llambda-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: llambda-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.9 Linux/4.19.104-microsoft-standard
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aae764309bcca447b6b2bc015d92c292f663f5c64be98076981da481929a7c0
|
|
| MD5 |
1719ede3eff600b6ead1882e0c005cfa
|
|
| BLAKE2b-256 |
aeb691ecfb35dbde5f2caeeecebb5848bf5af177c70a155d03ac163853d63c4f
|