LLM Gateway Service
Project description
Feature
- LLM 配置读取远程存储
- Prompt 配置读取远程存储
- LLM 对话记录 存储到远程
- 远程存储: 支持 Baserow
- 支持使用 Jinja2 模板渲染 Prompt
默认使用模式
from llm_store.gateway import LLMGateway
from llm_store.store.baserowstore import BaseRowStore
import os
## 初始化配置
store = BaseRowStore(
api_host=os.environ.get("BASEROW_API_HOST", "localhost"),
api_key=os.environ.get("BASEROW_API_KEY", ""),
db_code="3",
model_table_code="614",
prompt_table_code="308",
chat_log_table_code="309")
llm_gateway = LLMGateway(store)
## 渲染 Prompt 内容
prompt_code = "test_template"
prompt_record, messages = llm_gateway.render_prompt(prompt_code, {"topic": "科幻"})
## LLM 对话
chatCompletion, time_cost = llm_gateway.completions(prompt_record, messages)
print(chatCompletion,time_cost)
## 保存会话记录
trace_id = "1234567890"
log = llm_gateway.save_log(trace_id,prompt_record)
print(log)
轻量使用模式
说明: Prompt 不使用远程存储, 仅 LLM 配置, 对话记录存储到远程
from llm_store.gateway import LLMGateway
from llm_store.store.baserowstore import BaseRowStore
import os
store = BaseRowStore(
api_host=os.environ.get("BASEROW_API_HOST", "localhost"),
api_key=os.environ.get("BASEROW_API_KEY", ""),
db_code="3",
model_table_code="614",
prompt_table_code="308",
chat_log_table_code="309")
llm_gateway = LLMGateway(store)
# 不使用远程 Prompt 模式
messages = [{"role": "system", "content": "今天星期几"}]
# -- 获取 模型信息
model_code = "litellm-us"
model_record = llm_gateway.get_model(model_code)
# -- 执行对话
chatCompletion = llm_gateway.completions(model_record, messages, trace_id="1234567890")
print(chatCompletion)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
llm_store-0.1.6.tar.gz
(7.5 kB
view details)
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_store-0.1.6.tar.gz.
File metadata
- Download URL: llm_store-0.1.6.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b9b353bda1649dc47dbfa30a5195fcbcc066ea0da352bc29212df98d6e4c6e
|
|
| MD5 |
f7e3243123cbdca83f9bfcb651307273
|
|
| BLAKE2b-256 |
4ffdce4b2b6f881629b20dd524a50c170a9c9975f156094d1680bd4b95694b6c
|
File details
Details for the file llm_store-0.1.6-py3-none-any.whl.
File metadata
- Download URL: llm_store-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c259dec095712da60d91059874a94cf001b998a7130db400ea09b86dfe9cc433
|
|
| MD5 |
3e27cff8337cc331886ffa75d3c61bf8
|
|
| BLAKE2b-256 |
d4528ec193982cf3482987b2329ca9b7eb3d2d933ae9b96d702c42393b96006c
|