A lightweight Python library for creating tasks and workflows with Large Language Models (LLMs) using prompt templates.
Project description
LLM Tasker
LLM Tasker is a small Python library designed to simplify working with language models and prompts. It provides a structure for defining tasks, configuring LLM clients, and managing responses in a type-safe manner.
Features
- Supports various LLM clients (e.g., OpenAI) with easy configuration.
- Define structured prompt-based tasks as Python classes.
- Type-safe implementation using Pydantic models.
- Asynchronous support for efficient interaction with LLM services.
- Reusable task configuration and logic.
Installation
pip install llm_tasker
Example Usage
from openai import AsyncOpenAI
from pydantic import BaseModel
from llm_tasker.task import LLMTask, TaskConfig
LLM_API_KEY = "your-openai-api-key"
LLM_MODEL_ID = "gpt-4o
client = AsyncOpenAI(api_key=LLM_API_KEY)
class AnalysisResult(BaseModel):
subject: str
verb: str
object: str
class NestedOutputTask(LLMTask):
"""
Analyze the following sentence and return a structured nested output with the main subject, verb, and object.
Sentence: `{sentence}`
Output format:
```json
{{
"subject": "subject of the sentence",
"verb": "main verb",
"object": "object of the sentence"
}}
```
"""
sentence: str
result: AnalysisResult | None = None
config = TaskConfig(client=client, model=LLM_MODEL_ID)
if __name__ == "__main__":
import asyncio
async def main():
task = NestedOutputTask(
sentence="The cat chased the mouse."
)
await task()
print(task.result)
asyncio.run(main())
License
This project is licensed under the MIT License.
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 llm_tasker-0.1.2.tar.gz.
File metadata
- Download URL: llm_tasker-0.1.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13e468e89712ef16261ab267aa9d1f0b08b8fd776c288016cadaa355badb99e7
|
|
| MD5 |
795be352b731bd59245249359b8c88b6
|
|
| BLAKE2b-256 |
a38bbdef70111a0509e5d9a7064a0f3a9a052d9cab7dd6ed13d46d1b9cb0d755
|
File details
Details for the file llm_tasker-0.1.2-py3-none-any.whl.
File metadata
- Download URL: llm_tasker-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c5ced0112ff9879864eeb4fb304f3fb6fef6d2884e20c39a1c12b8c2653bddf
|
|
| MD5 |
0e6e9aea09264c68b0b0ade9f671a828
|
|
| BLAKE2b-256 |
73f82b5a986ddb8bf702d59817f358317578a25e5f6c9c75deec5f1e9421a2fc
|