Add your description here
Project description
LangPrompt
LangPrompt is a Python library for creating chat prompts with template support.
Some code come from https://github.com/cfahlgren1/observers,https://github.com/Mirascope/mirascope
Installation
pip install langprompt
Usage
from pydantic import BaseModel
from langprompt import TextOutputParser, Prompt
from langprompt.llms.openai import OpenAI
from langprompt.cache import SQLiteCache
from langprompt.store import DuckDBStore
class Input(BaseModel):
text: str
language: str = "Chinese"
prompt = Prompt[Input]("""
<|system|>
You are a professional translator. Please accurately translate the text while maintaining its original meaning and style.
<|end|>
<|user|>
Translate the following text into {{language}}: {{text}}
<|end|>
""")
if __name__ == "__main__":
parser = TextOutputParser()
provider = OpenAI(model="gpt-4o-mini", cache=SQLiteCache(), store=DuckDBStore(), query_per_second=0.2)
inputs = [
Input(text="Hello, how are you?", language="Chinese"),
Input(text="Hello, how are you?", language="English"),
Input(text="Hello, how are you?", language="Chinese"),
]
messages = [prompt.parse(input) for input in inputs]
responses = provider.batch(messages, batch_size=2, enable_retry=True)
# 处理结果
for i, response in enumerate(responses):
print(f"\n--- Result {i+1} ---")
print(f"Original: {inputs[i].text}")
result = parser.parse(response)
print(f"Translated: {result}")
执行结果:
--- Result 1 ---
Original: Hello, how are you?
Translated: 你好,你好吗?
Cache Key: None
--- Result 2 ---
Original: Hello, how are you?
Translated: Hello, how are you?
Cache Key: None
--- Result 3 ---
Original: Hello, how are you?
Translated: 你好,你好吗?
Cache Key: 5693a0a16dff61866ca18feef969719cc78979a5f44cd412fef1add7bdcaaa42
Todo
- OpenAI Tools 完全支持
- OpenAI JSON Mode 支持
- support data viewer
- add to langeval/ragas/distilabel distilabel support qianfan、llm cache
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 langprompt-0.1.1.tar.gz.
File metadata
- Download URL: langprompt-0.1.1.tar.gz
- Upload date:
- Size: 123.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
048ec92c3feaca2a7dc7f04f8fc7172deb433470e4ff7aa91532510bc95fdfce
|
|
| MD5 |
638c28a3cc68f58d24283548d97565db
|
|
| BLAKE2b-256 |
f3be637a00f8d7ae84f2a7a2fd3b80973385cae483f27d920bd4f1832a50c914
|
Provenance
The following attestation bundles were made for langprompt-0.1.1.tar.gz:
Publisher:
publish.yml on ninehills/langprompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langprompt-0.1.1.tar.gz -
Subject digest:
048ec92c3feaca2a7dc7f04f8fc7172deb433470e4ff7aa91532510bc95fdfce - Sigstore transparency entry: 162829213
- Sigstore integration time:
-
Permalink:
ninehills/langprompt@b366bec36b71a93e93ff800aa69f29dac7bfdb6e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ninehills
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b366bec36b71a93e93ff800aa69f29dac7bfdb6e -
Trigger Event:
push
-
Statement type:
File details
Details for the file langprompt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langprompt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dddeb906cfece436eeff200c12d5a63adc76d290b2cf13bc0db226e2009ed921
|
|
| MD5 |
a8021ad6ecd7cf0795284a9f63b359f2
|
|
| BLAKE2b-256 |
243f7b68c69a389fecd607b2948399d283fe56e0364be3e7e3a500f4482942aa
|
Provenance
The following attestation bundles were made for langprompt-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on ninehills/langprompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langprompt-0.1.1-py3-none-any.whl -
Subject digest:
dddeb906cfece436eeff200c12d5a63adc76d290b2cf13bc0db226e2009ed921 - Sigstore transparency entry: 162829215
- Sigstore integration time:
-
Permalink:
ninehills/langprompt@b366bec36b71a93e93ff800aa69f29dac7bfdb6e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ninehills
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b366bec36b71a93e93ff800aa69f29dac7bfdb6e -
Trigger Event:
push
-
Statement type: