LLMLib
LLMLib is a simple Python library for making requests to Language Learning Models (LLMs) such as OpenAI's GPT and Anthropic's Claude.
Installation
You can install LLMLib using pip:
pip install llmlib-amq
Usage
Here's a quick example of how to use LLMLib:
from PIL import Image
from pathlib import Path
from llmlib import LLMClient, Provider, AnthropicModel, OpenAIModel, Role, \
LLMResponse, TextMessage, ImageMessage, print_stream, encode_image_webp
import os
client = LLMClient(
provider=Provider.ANTHROPIC,
model=AnthropicModel.CLAUDE_3_5_SONNET_20241022,
# provider=Provider.OPENAI,
# model=OpenAIModel.GPT_4O,
openai_key=os.environ["OPENAI_API_KEY"],
anthropic_key=os.environ["ANTHROPIC_API_KEY"],
)
#############################################
### Non-streaming example ###
#############################################
output: LLMResponse = client.chat(
messages=[
TextMessage(content="You are very concise, answering a question in one sentence.", role=Role.SYSTEM),
TextMessage(content="What is the capital of South Africa?", role=Role.USER)
]
)
print(f"[{client.model_id}]")
print(output.content)
#############################################
### Non-streaming image example ###
#############################################
example_image = Path(__file__).parent.parent / "tests/bird.webp"
img_base64 = encode_image_webp(Image.open(example_image))
output: LLMResponse = client.chat(
messages=[
TextMessage(content="You are very concise image analyst", role=Role.SYSTEM),
TextMessage(content="Please describe this image", role=Role.USER),
ImageMessage(content=img_base64, role=Role.USER)
]
)
print(f"[{client.model_id}]")
print(output.content)
print(output.usage)
#############################################
### Streaming example ###
#############################################
for chunk in client.chat_stream(
messages=[TextMessage(content="How can I solve tic-tac-toe in Python?", role=Role.USER)]
):
print(chunk, end="", flush=True)
#############################################
### Streaming and collecting output ###
#############################################
stream = client.chat_stream(
messages=[
TextMessage(
content="What is the bash command to rollback a git commit? "
"Please be extremely succinct, output only the bash "
"command. Do not include any commentary. The output "
"will be executed directly",
role=Role.USER,
)
]
)
result = print_stream(stream)
print()
print(result)
License
This project is licensed under the MIT License.
Metadata
Release files for llmlib-amq 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llmlib_amq-0.0.9.tar.gz | 210.3 kB | Without provenance | Details for llmlib_amq-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llmlib_amq-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for llmlib_amq-0.0.9-py3-none-any.whl |
Total release size: 217.2 kB
Release files / llmlib_amq-0.0.9.tar.gz
| Download URL | llmlib_amq-0.0.9.tar.gz |
|---|---|
| Size | 210.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ffba74b329dc089e0c7784c8ec0b7d80d6fbbe80f54a86b94995de4526d576b
|
|
BLAKE2b-256 checksum How to use checksums |
d7c1575e9dca97b4c08986aaa6f99c5d09db7d34be1d41d8a7b7318a5587e9ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / llmlib_amq-0.0.9-py3-none-any.whl
| Download URL | llmlib_amq-0.0.9-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7e7119d21e0368f9b67c94e118a4b712409eb2798b189ed3e3b5f2d0ca296c0
|
|
BLAKE2b-256 checksum How to use checksums |
6b7c321ef57342fa3986eea1bf90359012d1d3c48ff56f862bb1dcef2034478d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Security for llmlib-amq 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.