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.
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 invocationainvoke(prompt: str) -> str: Asynchronous invocationstream_invoke(prompt: str) -> Iterator[str]: Synchronous streaming invocationastream_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_KEYfor OpenAIANTHROPIC_API_KEYfor ClaudeGOOGLE_API_KEYfor 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
- function calling
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tinylang-3.0.2.tar.gz.
File metadata
- Download URL: tinylang-3.0.2.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8521602d9d433c82a28fdcb8a137c802c6bd89ff1f45a3eb97a16f43ea7a4a8
|
|
| MD5 |
96a555eaa3129dd3a7c400607b1c1f42
|
|
| BLAKE2b-256 |
45d441f6c57fafabdd8a6ac770585748aea181b5ac17b3e3583aa122f3ac8c00
|
File details
Details for the file tinylang-3.0.2-py3-none-any.whl.
File metadata
- Download URL: tinylang-3.0.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6ad09d6fd9a5ca8fbe2a26b8bea5aa9cac632a39a6094a0a6ac8b150c90f617
|
|
| MD5 |
d881ee0afe779e3086084fc1f474b815
|
|
| BLAKE2b-256 |
fd3645b71efb739d3507f821e01aa9b2a46026d0d0492c9d548525130eae22bb
|