A set of tools for easily interacting with LLMs.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
WHAT
A set of tools for easily interacting with LLMs.
WHY
Building AI-driven software leans upon a number of utilities, such as prompt building and LLM calling via HTTP requests. Additionally, writing agents and workflows can prove particularly challenging using conventional code structures.
HOW
This simple library offers a set of predefined functions for:
- Easy prompting - you need only provide a path
- Calling LLMs - instructor takes care of that for us
- Modifying response models - we use Pydantic (duh)
Additionally, we provide grafo out of the box for convenient workflow building.
About Grafo
Grafo (see Recommended Docs below) is a library for building executable DAGs where each node contains a coroutine. Since the DAG abstraction fits particularly well into AI-driven building, we have provided the BaseWorkflow class with the following methods:
taskfor LLM callingredirectto help you manage redirections in yourgrafoworkflows
Examples
Simple text:
from ait import AIT
ait = AIT("gpt-5")
path = "./prompt.md"
response = ait.chat(path)
print(response.completion)
print(response.content)
Structured response:
from ait import AIT
from pydantic import BaseModel
class Purchase(BaseModel):
product: str
quantity: int
ait = AIT("gpt-5")
path = "./prompt.md" # PROMPT: {{ message }}
message = "I want to buy 5 apples"
response = ait.asend(response_model=Fruit, path=path, message=message)
Structured response with model type injection:
from ait import AIT
from pydantic import BaseModel
class Purchase(BaseModel):
product: str
quantity: int
ait = AIT("gpt-5")
path = "./prompt.md" # PROMPT: {{ message }}
message = "I want to buy 5 apples"
available_fruits = ["apple", "banana", "orange"]
FruitModel = ait.inject_types(Purchase, [
("product", Literal[tuple(available_fruits)])
])
response = ait.asend(response_model=Purchase, path=path, message=message)
Simple workflow:
from ait import AIT, BaseWorkflow, Node
from pydantic import BaseModel
class Purchase(BaseModel):
product: str
quantity: int
class Eval(BaseModel):
is_valid: bool
reasoning: str
humanized_failure_reason: str | None
ait = AIT("gpt-5")
prompts_path = "./"
message = "I want to buy 5 apples"
available_fruits = ["apple", "banana", "orange"]
FruitModel = ait.inject_types(Purchase, [
("product", Literal[tuple(available_fruits)])
])
class PurchaseWorkflow(BaseWorkflow):
def __init__(...):
...
async def run(self, message) -> Purchase:
purchase_node = Node[FruitModel](
uuid="fruit purchase node"
coroutine=self.task
kwargs=dict(
path=f"{prompts_path}/purchase.md"
response_model=FruitModel
message=message
)
)
validation_node = Node[Eval](
uuid="purchase eval node"
coroutine=self.task
kwargs=dict(
path=f"{prompts_path}/eval.md"
response_model=Eval
message=message
purchase=lambda: purchase_node.output
)
)
eval_node.on_after_run = (
self.redirect,
dict(
source_node=purchase_node
validation_node=validation_node
)
)
await purchase_node.connect(validation_node)
executor = TreeExecutor(uuid="Purchase Workflow", roots=[purchase_node])
await executor.run()
if not purchase_node.output or not validation_node.output.is_valid:
raise ValueError("Purchase failed.")
return purchase_node.output
Recommended Docs
instructorhttps://python.useinstructor.com/jinja2https://jinja.palletsprojects.com/en/stable/pydantichttps://docs.pydantic.dev/latest/grafohttps://github.com/paulomtts/grafo
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
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 grafo_ai_tools-0.1.1.tar.gz.
File metadata
- Download URL: grafo_ai_tools-0.1.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
836491b6677235101cdf247603819972d9bd7068fc65d676cb6beb16734fcb8a
|
|
| MD5 |
03d0713b328be8301d6a1205105cf3c2
|
|
| BLAKE2b-256 |
ac853469391ddb94be3001a3a3f9aad12d06ec5632c7aaf6943197482f7886af
|
File details
Details for the file grafo_ai_tools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: grafo_ai_tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35ed3d51ec06c3a698034367dca5be6e3bc2bb648314cd74f716bc051547a768
|
|
| MD5 |
ef3422808408fab487dc55b9d3477649
|
|
| BLAKE2b-256 |
6fd1424840243eb8b731ae9f1c85a40bdba0162c33567061aa7ade49161d538a
|