Framework for intuitive LLM application development with tensors.
Project description
# <img src="langtorch_w_background.png" width="60" height="60" alt="LangTorch Logo" style="vertical-align: middle;"> LangTorch
[![Release Notes](https://img.shields.io/github/release/AdamSobieszek/langtorch)](https://github.com/AdamSobieszek/langtorch/releases)
[![Downloads](https://static.pepy.tech/badge/AdamSobieszek/langtorch)](https://pepy.tech/project/langtorch)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/AdamSobieszek.svg?style=social&label=Follow%20%40AdamSobieszek)](https://twitter.com/AdamSobieszek)
[![GitHub star chart](https://img.shields.io/github/stars/AdamSobieszek/langtorch?style=social)](https://star-history.com/#AdamSobieszek/langtorch)
[//]: # ([![](https://dcbadge.vercel.app/api/server/6adMQxSpJS?compact=true&style=flat)](https://discord.gg/6adMQxSpJS))
LangTorch is a Python package designed to simplify the development of LLM applications by leveraging familiar PyTorch concepts.
## Installation
```bash
pip install langtorch
```
## Overview
LangTorch provides a structured approach to LLM applications, offering:
- **TextTensors**: A unified way to handle prompt templates, completion dictionaries, and chat histories.
- **TextModules**: Building blocks, derived from torch.nn.Module, specifically tailored for text operations and LLM calls both locally and via an API.
- other things that are also better than langchain
## Examples
### TextTensors
Creating and manipulating textual data as tensors:
```python
template = TextTensor([["Explain {theory} in terms of {framework}"],
["Argue how {framework} can prove {theory}"]])
result = template * TextTensor({"theory": "active inference", "framework": "thermodynamics" })
print(result)
# Outputs: [[Explain active inference in terms of thermodynamics]
# [Argue how thermodynamics can prove active inference]]
```
### TextModules
Building sequences of operations on text data:
```python
chain = torch.nn.Sequential(
TextModule("Calculate this equation: {}"),
langtorch.methods.CoT,
GPT4
TextModule("Is this reasoning correct? {}", activation = GPT4)
)
output = chain(TextTensor(["170*32 =", "4*20 =", "123*45/10 =", "2**10*5 ="]))
```
### Cosine Similarities
Compute similarities between entries:
```python
from langtorch.tt import CosineSimilarity
cos = CosineSimilarity()
similarities = cos(TextTensor([["Yes"], ["No"]]), TextTensor(["1", "0", "Noo", "Yees"]))
```
## Contribute
Your feedback and contributions are valued. Feel free to check out our [contribution guidelines](#).
## License
LangTorch is MIT licensed. See the [LICENSE](#) file for details.
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
LangTorch-0.1.5.tar.gz
(85.8 kB
view details)
Built Distribution
LangTorch-0.1.5-py3-none-any.whl
(146.0 kB
view details)
File details
Details for the file LangTorch-0.1.5.tar.gz
.
File metadata
- Download URL: LangTorch-0.1.5.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f2b1a370447d688ff69d3361a647679197dbafa1590daed78551d2609542efc |
|
MD5 | a8eaa118d4acf883f5d915bd61b089c2 |
|
BLAKE2b-256 | a707e1d7c861a3b90cb919d5ee576454fe942bef53db8be64d01973ad0238a54 |
File details
Details for the file LangTorch-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: LangTorch-0.1.5-py3-none-any.whl
- Upload date:
- Size: 146.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d40c9f8c7d9977848f51819a94f279eba53d5c87a4a2fd60b0d10a7e98675fa |
|
MD5 | 5632af2c0023ac79a573846bc519492e |
|
BLAKE2b-256 | 6d6ca7223d3cb766d9acd0f2f928608e0dde324059be2e7ee52855fdaf65d676 |