The auxiliary tool is used to invoke the online LLM service API, supporting local caching, prompt rendering, and configuration management.
Project description
LLMQuiver
English | 简体中文
The auxiliary tool is used to invoke the online LLM service API, supporting local caching, prompt rendering, and configuration management.
Supported
- Support Openai/Azure LLM service providers (or openai-compatible service providers).
- Support vllm service.
- Local caching (based on sqlite).
- Prompt rendering (based on toml file).
- Configuration management (based on toml file).
To Be Done
- Multi service provider support.
Installation
pip install llm-quiver
Basic Usage
1. Direct Call Mode
Assuming you have a configuration file path/to/gpt.toml, you need to fill in your own API_KEY, content as follows:
API_TYPE = "azure_openai"
API_BASE = "https://endpoint.openai.azure.com/"
API_VERSION = "2023-05-15"
API_KEY = "********************************"
MODEL_NAME = "gpt-4o-20240513"
temperature = 0.0
max_tokens = 4096
enable_cache = true
cache_dir = "oai_cache"
Running code:
from llm_quiver import LLMQuiver
# Initialize
llm = LLMQuiver(
config_path="path/to/gpt.toml",
)
# Text generation mode
prompt_values = ["Who are you?"]
responses = llm.generate(prompt_values)
# Default role is system
# ["I am an AI assistant developed by OpenAI, designed to help answer questions, provide information, and complete various tasks. How can I help you?"]
# Chat mode
messages = [[{"role": "user", "content": "Who are you?"}]]
responses = llm.chat(messages)
# ["I am an AI assistant developed by OpenAI, designed to help answer questions, provide information, and engage in conversations. Feel free to ask me anything!"]
2. Toml Template Call Mode
First, create a TOML template file, for example hello_world.toml:
[hello_world_template]
prompt = "Hello {name}, who are you?"
Then you can use it like this:
from llm_quiver import TomlLLMQuiver
# Specify template during initialization
llm = TomlLLMQuiver(
config_path="path/to/gpt.toml",
toml_prompt_name="hello_world_template",
toml_template_file="path/to/hello_world.toml"
)
# Pass template parameters
prompt_values = [dict(name="GPT")]
responses = llm.generate(prompt_values)
Configuration Guide
There are two ways to configure API keys and other parameters:
- Through environment variables:
Configuration can be loaded by passing parameter config_path="path/to/config.toml" or setting environment variable "export LLMQUIVER_CONFIG=path/to/config.toml". Parameters like API_TYPE, API_BASE, API_VERSION, API_KEY, MODEL_NAME can also be set in environment variables.
- Directly passing configuration file path:
llm = TomlLLMQuiver(
config_path="path/to/config.toml",
toml_prompt_name="template_name",
toml_template_file="path/to/template.toml"
)
Configuration file example:
API_TYPE = "azure_openai"
API_BASE = "https://endpoint.openai.azure.com/"
API_VERSION = "2023-05-15"
API_KEY = "********************************"
MODEL_NAME = "gpt-4o-20240513"
temperature = 0.0
max_tokens = 4096
enable_cache = true
cache_dir = "oai_cache"
Return Value Description
- Both generate() and chat() methods return a list of strings
- Each element corresponds to a response for one input prompt
Notes
- API key must be correctly configured before use
- Template files must comply with TOML format specifications
- Input parameters must correspond to placeholders in the template
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 llm_quiver-0.3.7.tar.gz.
File metadata
- Download URL: llm_quiver-0.3.7.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f294d68244bf9b7805d3e48a54de1e31684e900895e4227f83511be8a6831e3
|
|
| MD5 |
115a2d9fcab2892c125b387cbe26c2d3
|
|
| BLAKE2b-256 |
b5667ac984cf700a15652fcfb1174f80ca27db4872489a932dce535b17243917
|
Provenance
The following attestation bundles were made for llm_quiver-0.3.7.tar.gz:
Publisher:
publish-to-test-pypi.yml on xrandx/LLMQuiver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_quiver-0.3.7.tar.gz -
Subject digest:
6f294d68244bf9b7805d3e48a54de1e31684e900895e4227f83511be8a6831e3 - Sigstore transparency entry: 178452068
- Sigstore integration time:
-
Permalink:
xrandx/LLMQuiver@cdd3a6c26604e2e650f3d5bafacdfaba234522e1 -
Branch / Tag:
refs/tags/0.3.7 - Owner: https://github.com/xrandx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@cdd3a6c26604e2e650f3d5bafacdfaba234522e1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file llm_quiver-0.3.7-py3-none-any.whl.
File metadata
- Download URL: llm_quiver-0.3.7-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
611d34559cee0c0f1a0e026813c738040fab912eac7b6f477ffdb98caca30563
|
|
| MD5 |
cb77d93b8c4029e74d247a4d9b7c5549
|
|
| BLAKE2b-256 |
9b97e466a0bd3c14b6cc207866f68b39b8e7f77fef2d95e72ea8f84711b8b7fe
|
Provenance
The following attestation bundles were made for llm_quiver-0.3.7-py3-none-any.whl:
Publisher:
publish-to-test-pypi.yml on xrandx/LLMQuiver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_quiver-0.3.7-py3-none-any.whl -
Subject digest:
611d34559cee0c0f1a0e026813c738040fab912eac7b6f477ffdb98caca30563 - Sigstore transparency entry: 178452069
- Sigstore integration time:
-
Permalink:
xrandx/LLMQuiver@cdd3a6c26604e2e650f3d5bafacdfaba234522e1 -
Branch / Tag:
refs/tags/0.3.7 - Owner: https://github.com/xrandx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@cdd3a6c26604e2e650f3d5bafacdfaba234522e1 -
Trigger Event:
push
-
Statement type: