⚡ UglyChain:更好用的 LLM 应用构建工具 ⚡
Project description
UglyChain
⚡ UglyChain: A Better LLM Application Development Framework ⚡
中文版本说明 »
Report Bug
·
Request Feature
🤔 What is UglyChain?
UglyChain is a Python framework designed to simplify LLM application development. It provides a more intuitive and developer-friendly interface compared to traditional LLM frameworks.
Key Problems Addressed:
- Non-intuitive API Design: Many existing frameworks have complex and non-intuitive interfaces
- Over-encapsulation: Excessive abstraction makes customization difficult
- Chat-centric Design: Most frameworks are designed around chat interfaces, which are not ideal for structured application development
Why Choose UglyChain?
- 🚀 Developer-friendly API: Intuitive decorator-based interface
- 🧩 Modular Design: Easy to extend and customize
- ⚡ High Performance: Built-in support for parallel processing
- 📦 Production-ready: Well-documented and thoroughly tested
✨ Features
-
Decorator-based API: Simplify LLM interactions with intuitive decorators
@llm(model="openai:gpt-4o") def generate_text(prompt: str) -> str: return prompt
-
Structured Output: Easily parse LLM responses into structured data
class User(BaseModel): name: str age: int @llm(model="openai:gpt-4o", response_format=User) def parse_user(text: str) -> User: return text
-
Parallel Processing: Process multiple inputs concurrently
@llm(model="openai:gpt-4", map_keys=["input"]) def batch_process(inputs: list[str]) -> list[str]: return inputs
-
ReAct Support: Built-in support for reasoning and acting
@react(model="openai:gpt-4", tools=[web_search]) def research(topic: str) -> str: return f"Research about {topic}"
-
Extensible Architecture: Easily add custom models and tools
🚀 Getting Started
Prerequisites
- Python 3.10+
- pip 20.0+
Installation
# Install from PyPI
pip install uglychain
# Install from source
git clone https://github.com/uglyboy-tl/UglyChain.git
cd UglyChain
pip install -e .
Project Structure
uglychain/
├── src/uglychain # Source code
│ ├── client.py # Client supported by aisuite
│ ├── config.py # Configuration management
│ ├── console.py # Console interface
│ ├── llm.py # Core LLM functionality
│ ├── react.py # ReAct implementation
│ ├── structured.py # Structured output
│ └── tools.py # Built-in tools
├── tests/ # Unit tests
├── examples/ # Usage examples
├── pyproject.toml # Build configuration
└── README.md # Project documentation
Usage
llm
A basic decorator that makes it easy to decorate LLM calls for more convenient invocation.
Quick start:
from uglychain import llm
@llm(model="openai:gpt-4o-mini", temperature=0.1)
def hello(world : str):
"""You are a helpful assistant that writes in lower case.""" # System Message
return f"Say hello to {world[::-1]} with a poem." # User Message
hello("sama")
Structured output example:
class UserDetail(BaseModel):
name: str
age: int
@llm("openai:gpt-4o-mini", response_format=UserDetail)
def test(name: str):
return f"{name} is a boy"
test("Bob")
MapChain
Allows batch processing of models through map_keys, returning multiple results. If config.use_parallel_processing is set to True, it will use multiprocessing for parallel execution.
Quick start:
@llm("openai:gpt-4o-mini", map_keys=["input"])
def map(input: list[str]):
return input
input = [
"How old are you?",
"What is the meaning of life?",
"What is the hottest day of the year?",
]
for item in map(input):
print(item)
Similar to LLM, MapChain can also be used for more advanced scenarios:
class AUTHOR(BaseModel):
name: str = Field(..., description="Name")
introduction: str = Field(..., description="Introduction")
@llm("openai:gpt-4o-mini", map_keys=["book"], response_format=AUTHOR)
def map(book: list[str], position: str):
return f"Who is the {position} of {book}?"
input = [
"Dream of the Red Chamber",
"Journey to the West",
"Romance of the Three Kingdoms",
"Water Margin",
]
map(book=input, position="author") # Returns a list of AUTHOR objects
ReActChain
ReActChain is a method for tool invocation using ReAct capability, which performs better than traditional Function Call approaches.
from uglychain import react
from examples.utils import execute_command
@react("openai:gpt-4o-mini", tools = [execute_command])
def update():
return "Update my computer system"
update() # Automatically runs shell commands to update the system
🧪 Testing
Run the test suite:
pytest tests/
We maintain 100% test coverage for all core functionality.
🤝 Contributing
We welcome contributions! Please follow these steps:
- Read our Contribution Guidelines
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
Development Setup
-
Install development dependencies:
pdm install -G dev
-
Set up pre-commit hooks:
pre-commit install -
Run tests before committing:
pytest
Please ensure your code:
- Follows PEP 8 style guidelines
- Includes type hints
- Has corresponding unit tests
- Includes documentation
License
Distributed under the MIT License. See LICENSE.txt for more information.
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 uglychain-1.6.6.tar.gz.
File metadata
- Download URL: uglychain-1.6.6.tar.gz
- Upload date:
- Size: 60.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
775f768164ff33965583e1a650e868111cdca163715cd8186c07280b33adc9fa
|
|
| MD5 |
3209b7d5036d3fe7f7637b4275f08377
|
|
| BLAKE2b-256 |
d710fece2a6a5518b6d534db2abd2828ab6527b29df9edf3125a2187787c4874
|
File details
Details for the file uglychain-1.6.6-py3-none-any.whl.
File metadata
- Download URL: uglychain-1.6.6-py3-none-any.whl
- Upload date:
- Size: 79.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14f381ae80760079805f565f32bdd5acebe86759d7f47ebb700f713efe432ab6
|
|
| MD5 |
13aa289a766e4ba262e2ce6664b74baa
|
|
| BLAKE2b-256 |
6bb7961c9c152058bf310aacdd08a6e09ca48087a0ad6143b99a2895349dffd8
|