Skip to main content

A simple llm library.

Project description

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.

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-5.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

llmtext-5.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llmtext-5.0.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-38-generic

File hashes

Hashes for llmtext-5.0.0.tar.gz
Algorithm Hash digest
SHA256 9b9841457ae3bb41ae068aa2a0891bafb93e8a4a1815b8fc9ee6c728c5469f10
MD5 4a184ec2141d5b1f542db8d92f95db90
BLAKE2b-256 7a80d4f78fc701cbd219548f6a0097ddb4d4f9aef3824c4ea2c70d087906d9c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llmtext-5.0.0-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-38-generic

File hashes

Hashes for llmtext-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 000ce59b3fd70863afeec519f9627acf81a5081b3b440d857e892ad1251e9643
MD5 54e2ddce437efa9ea807f6b0002b115d
BLAKE2b-256 c973e8b73c093bc95ff54f404c2b4d132256ea183b3c281600eecb04c2249080

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