A simple llm library.
Project description
llmtext
llmtext
is a simple yet powerful library designed to interact with large language models (LLMs) as straightforward functions. It provides easy-to-use interfaces for both input-output text transformations and input-to-Pydantic class conversions, leveraging the power of open-source LLMs and OpenAI's schema.
Features
- Input Text, Output Text: Seamlessly generate text outputs from text inputs using large language models.
- Input Text, Output Pydantic Class: Convert text inputs directly into structured Pydantic classes for better data validation and manipulation.
- OpenAI Schema Support: Utilize OpenAI's schema for consistent and robust text processing.
- OpenSource LLMs through TogetherAI: Access a variety of open-source LLMs via TogetherAI for flexible and cost-effective solutions.
- Async by default: Asynchronous by default
- Robusts: configured with retry and self healing loop for structured extraction
Installation
You can install llmtext
via pip:
pip install llmtext
Usage
Text to Text Transformation
To generate text outputs from text inputs:
from llmtext.llms.openai import OpenaiLLM
llm = OpenaiLLM()
res = await llm.arun(text="What is the capital of France?")
Text to Pydantic Class Transformation
To convert text inputs into a Pydantic class:
from llmtext.llms.openai import OpenaiLLM
llm = OpenaiLLM()
class ExtractedData(BaseModel):
name: Annotated[str, Field(description="Name of the city")]
description: Annotated[str, Field(description="Description of the city")]
res = await llm.astructured_extraction(text="The city of France is Paris. It's a beautiful city.", output_class=ExtractedData)
assert isinstance(res, ExtractedData)
Access open source models through togetherAI
from llmtext.llms.togetherai import TogetherAILLM
llm = TogetherAILLM()
class ExtractedData(BaseModel):
name: Annotated[str, Field(description="Name of the city")]
description: Annotated[str, Field(description="Description of the city")]
res = await llm.astructured_extraction(text="The city of France is Paris. It's a beautiful city.", output_class=ExtractedData)
assert isinstance(res, ExtractedData)
Configuration
To configure llmtext
for using OpenAI's schema or TogetherAI's open-source LLMs, you can set the necessary API keys in your environment variables or configuration file.
Example Configuration
TOGETHERAI_API_KEY=
TOGETHER_API_BASE_URL=https://api.together.xyz/v1
OPENAI_API_KEY=
Contributing
We welcome contributions to llmtext
. Please fork the repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
Special thanks to OpenAI for providing robust schema support and TogetherAI for enabling access to open-source LLMs.
For more information, please refer to the documentation.
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
File details
Details for the file llmtext-0.1.4.tar.gz
.
File metadata
- Download URL: llmtext-0.1.4.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c176023f03a0575a4f7c60f3f6d134b69462115898905969650fae48ba11d2a |
|
MD5 | 1586a0a110a050a2bad6664beb581ae0 |
|
BLAKE2b-256 | 6fb47fe4908b452f2913940f776ca877834bb1af101cfbaf921bba6daeb04dc5 |
File details
Details for the file llmtext-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: llmtext-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dffcdc07c1d4d5f21fb0d1636eb06f4ca1f0034a687dcc32eadd5b8e509402c0 |
|
MD5 | 601835bf87f58862c1f6be9efe73df78 |
|
BLAKE2b-256 | 02aca42f38c8f7be32ffb192a9417d20a471ae30adb213e98173f251fb352718 |