Skip to main content

A tiny language interpreter

Project description

🦜🔗🔍 Tinylang

Tinylang is a Python library that provides a unified interface for interacting with various Large Language Models (LLMs) including OpenAI's GPT, Anthropic's Claude, and Google's Gemini.

Documentation

Features

  • Unified API for multiple LLM providers
  • Support for OpenAI, Anthropic Claude, and Google Gemini
  • Synchronous and asynchronous invocation methods
  • Streaming support for real-time responses
  • Chat history management
  • Easy integration with existing projects

Installation

To install Tinylang, use pip:

pip install tinylang

Usage

Here's a quick example of how to use Tinylang:

from tinylang.llms import ChatOpenAI, ChatClaude, ChatGemini

# Initialize chat interfaces
openai_chat = ChatOpenAI("gpt-4o", chat_history=2)
claude_chat = ChatClaude("claude-3-opus-20240229", chat_history=2)
gemini_chat = ChatGemini("gemini-1.5-pro", chat_history=2)

# Use the chat interfaces
response = openai_chat.invoke("Hello, how are you?")
print(response)

# Streaming example
for chunk in claude_chat.stream_invoke("Tell me a joke"):
    print(chunk, end='')

# Async example
async def async_chat():
    response = await gemini_chat.ainvoke("What's the weather like today?")
    print(response)

# Run the async function
import asyncio
asyncio.run(async_chat())

API Reference

ChatOpenAI, ChatClaude, ChatGemini

These classes provide interfaces to their respective LLM providers. They share the following methods:

  • invoke(prompt: str) -> str: Synchronous invocation
  • ainvoke(prompt: str) -> str: Asynchronous invocation
  • stream_invoke(prompt: str) -> Iterator[str]: Synchronous streaming invocation
  • astream_invoke(prompt: str) -> AsyncIterable[str]: Asynchronous streaming invocation

ChatHistory

Manages the conversation history for the chat interfaces.

Configuration

Set the following environment variables for API authentication:

  • OPENAI_API_KEY for OpenAI
  • ANTHROPIC_API_KEY for Claude
  • GOOGLE_API_KEY for Gemini

Alternatively, you can pass the API keys directly when initializing the chat interfaces.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

More Information

For more detailed information about using Tinylang, please refer to our documentation.

To be Added

  • async tool use response
  • recursive tool use calling
  • function calling for gemini
  • return usage after using a function
  • async tools
  • refactor

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

tinylang-4.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinylang-4.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file tinylang-4.1.0.tar.gz.

File metadata

  • Download URL: tinylang-4.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for tinylang-4.1.0.tar.gz
Algorithm Hash digest
SHA256 fc381ec5b29cee86a829b61c3bd84276194634843ec02d8b02e0f4d040a9658f
MD5 e77bdf48aaca3947b5224d51cb027581
BLAKE2b-256 500c27f64f3059447c3bf9e806c7d3d435f3f1cb5a42e7e6f4f94b69ad644dc7

See more details on using hashes here.

File details

Details for the file tinylang-4.1.0-py3-none-any.whl.

File metadata

  • Download URL: tinylang-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for tinylang-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f05ecbf11d11e29441e01b2404271df8e41b108293fa39bf813a39602ab2003
MD5 1e9de2beac49982196f2f9815e657c53
BLAKE2b-256 1311439a0f6fbbb4e803b161ad81c057be8f01bef2cb7a9ee6c38198fbd664c7

See more details on using hashes here.

Supported by

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