Skip to main content

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.text.index import Text

text = Text(text="What is the capital of France ?")
res = await llm.arun_openai(text="What is the capital of France?")

Text to Pydantic Class Transformation

To convert text inputs into a Pydantic class:

from llmtext.text.index import Text

text = Text(text="The city of France is Paris. It's a beautiful city.")

class ExtractedData(BaseModel):
    name: Annotated[str, Field(description="Name of the city")]
    description: Annotated[str, Field(description="Description of the city")]

res = await text.astructured_extraction_openai(output_class=ExtractedData)
assert isinstance(res, ExtractedData)

Access open source models through togetherAI

from llmtext.text.index import Text

llm = Text(text="The city of France is Paris. It's a beautiful city.")

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_togetherai(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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llmtext-3.0.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

llmtext-3.0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file llmtext-3.0.2.tar.gz.

File metadata

  • Download URL: llmtext-3.0.2.tar.gz
  • Upload date:
  • Size: 6.3 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

Hashes for llmtext-3.0.2.tar.gz
Algorithm Hash digest
SHA256 6da21ea01a39adefcd9885bddc067f267f3c9bcabaf1caf95ad4f56896911634
MD5 449ede91fa711ce4568fe9a1b854cf35
BLAKE2b-256 17e1e7a3604dfe92d796984d5811dc71526fbbd83e208157905704c89dbf8cb1

See more details on using hashes here.

File details

Details for the file llmtext-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: llmtext-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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

Hashes for llmtext-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 63e3e910e9a8d6ab05651410510c658c056f1ead6499cbf4e953993949dc1b4b
MD5 eb2f63b466505a521d88b29c5b1c06b3
BLAKE2b-256 d380b4f969b15bdbb8fbd002775ae92ea4ee45bec2d21b6b8c5dd6fee6d13d2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page