Skip to main content

LLM Gateway Service

Project description

Feature

  • LLM 配置读取远程存储
  • Prompt 配置读取远程存储
  • LLM 对话记录 存储到远程
  • 远程存储: 支持 Baserow

默认使用模式

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.5.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_store-0.1.5-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file llm_store-0.1.5.tar.gz.

File metadata

  • Download URL: llm_store-0.1.5.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

Hashes for llm_store-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f276bdb50b253516eb32002a651dd539393bb59305c94eeecc00b76014c0b146
MD5 b93e982447c1e099c0df14e157caaae6
BLAKE2b-256 cea80ac1b139d2feaa71c96475844d60391dee37435da705a2c99abeefb35830

See more details on using hashes here.

File details

Details for the file llm_store-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: llm_store-0.1.5-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

Hashes for llm_store-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3deabd69b03e357c6b18ac79598e9861b58e28bdd9d11eadaf026eb5674c0c9b
MD5 bfbe332ffe90306292522cf3e45da047
BLAKE2b-256 0a5b3378ca9f65a6be4dcc5d1d9b41eb89e5faa6a065353c8ee6b6b05e5e639a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page