Skip to main content

LLMText

logo

Overview

This codebase provides a set of tools and workflows for interacting with language models (LLMs) in an asynchronous manner. It includes functionalities for generating text, streaming text, and structured extraction from messages and text inputs. The codebase is designed to be modular and extensible, allowing for easy integration of new tools and workflows.

Features

  • Asynchronous Text Generation: Generate text asynchronously from user messages.
  • Streaming Text Generation: Stream text responses asynchronously.
  • Structured Extraction: Extract structured data from text inputs using predefined classes.
  • Workflows: Define and execute complex workflows involving multiple tools and messages.

Installation

To install the necessary dependencies, you can use the following command:

pip install llmtext

Ensure you have the required environment variables set up by creating a .env file in the root directory with the necessary configurations.

Usage

Running Tests

To run the tests, use the following command:

pytest

Example Usage

Here is an example of how to use the asynchronous text generation functionality:

from llmtext.messages_fns import agenerate
from llmtext.data_types import Message

async def main():
    text = await agenerate(
        messages=[Message(role="user", content="what's the weather today ?")]
    )
    print(text)

import asyncio
asyncio.run(main())

Agentic Workflow

Here is an example of how to use the agentic workflow functionality:

from llmtext.data_types import Message
from llmtext.workflows_fns import astream_agentic_workflow
from llmtext.data_types import RunnableTool
from typing import Annotated
from pydantic import Field

class SearchInternetTool(RunnableTool):
    """Tool to search internet"""

    query: Annotated[str, Field(description="search query")]

    async def arun(self) -> str:
        return f"there's no result for: {self.query}"

async def main():
    stream = astream_agentic_workflow(
        messages=[
            Message(role="user", content="what's the weather today ?"),
            Message(
                role="assistant",
                content="there's no result for: what's the weather today ?",
            ),
        ],
        tools=[SearchInternetTool],
    )
    async for chunk in stream:
        print(chunk)

import asyncio
asyncio.run(main())

Available Tests

  • test_messages.py: Tests for message-related functionalities.
  • test_workflows.py: Tests for workflow-related functionalities.
  • test_text.py: Tests for text-related functionalities.
  • test_tool.py: Tests for tool-related functionalities.

Code Structure

  • tests/: Contains all the test files.
    • test_workflow/: Tests for workflow functionalities.
    • tools/: Tests for tool functionalities.
  • llmtext/: Contains the main codebase.
    • utils_fns/: Utility functions for converting messages and tools.
    • data_types/: Data types used throughout the codebase.
    • messages_fns/: Message-related functions.
    • texts_fns/: Text-related functions.
    • workflows_fns/: Workflow-related functions.

Contributing

Contributions are welcome! Please follow the standard Git workflow:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes.
  4. Push your branch to your fork.
  5. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For any questions or issues, please open an issue on GitHub.

Release files for llmtext 5.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llmtext 5.0.1
File Size Uploaded
llmtext-5.0.1.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llmtext 5.0.1
File Interpreter ABI Platform
llmtext-5.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / llmtext-5.0.1.tar.gz

Download URL llmtext-5.0.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
19db2d13c767a295e1b4ff1d1c9caeae00777da5a1fc4bcbd666fe5441d9bdb4
BLAKE2b-256 checksum
How to use checksums
b075134db0e105c9f57fde880b1ed9aa425e015d0916e11bf6e8804f51c61ced
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-38-generic

Release files / llmtext-5.0.1-py3-none-any.whl

Download URL llmtext-5.0.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87929b27ace4247bcaf78588af7b93f00dbc87d1579ef678c79b855b0c12af9c
BLAKE2b-256 checksum
How to use checksums
de76f0aaf4e91261c4aed049ebcf936213882665459fefb8bfc898423625f41c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-38-generic

Release history Release notifications | RSS feed

5.0.7

2 release files

5.0.6

2 release files

5.0.5

2 release files

5.0.4

2 release files

5.0.2

2 release files

This release

5.0.1 This release

2 release files

5.0.0

2 release files

4.1.5

2 release files

4.0.5

2 release files

4.0.4

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page