Skip to main content

LLMRF

PyPI version License: MIT Python 3.6+

LLMRF (LLM Response Formatter) 是一个轻量级的 Python 库,用于将 LLM 输出格式化为标准的 OpenAI API 响应格式。

✨ 特性

  • 🚀 简单易用的 API
  • 📦 支持标准和流式响应格式
  • 🔧 完全可自定义的参数
  • 🎯 兼容 OpenAI API 格式

🛠️ 安装

pip install llmrf

📖 使用示例

基础用法

from llmrf import RF
import json

rf = RF()
# 普通响应
response = rf.f_r("Hello, World!")
print(json.dumps(response, indent=2))  # 格式化输出

# 流式响应
stream = rf.f_r("Hello, World!", stream=True)
print(stream)

输出示例

普通响应输出:

{
  "id": "chatcmpl-123e4567-e89b-12d3-a456-426614174000",
  "object": "chat.completion",
  "created": 1707139200,
  "model": "gpt-3.5-turbo",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello, World!"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 12,
    "total_tokens": 24
  }
}

流式响应输出:

data: {"id": null, "object": "chat.completion.chunk", "created": null, "model": "gpt-3.5-turbo", "choices": [{"index": 0, "delta": {"content": "Hello, World!", "role": null}, "finish_reason": null}], "usage": null}

自定义参数

response = rf.f_r(
    content="Hello, World!",
    model="custom-model",
    id="custom-id"
)

格式化输出提示

为了获得更好的可读性,建议使用 json.dumps() 格式化输出:

import json

response = rf.f_r("Hello, World!")
# 使用 indent 参数美化输出
print(json.dumps(response, indent=2, ensure_ascii=False))

📚 API 文档

RF.f_r()

主要格式化方法,支持以下参数:

参数 类型 必需 默认值 描述
content str 是 - 要格式化的文本内容
stream bool 否 False 是否使用流式响应
model str 否 "gpt-3.5-turbo" 模型名称
id str 否 自动生成 响应 ID
created int 否 当前时间戳 创建时间

🎯 使用场景

  • 自定义 LLM 服务接口标准化
  • API 响应格式转换
  • 流式输出格式化
  • LLM 响应模拟测试

🤝 贡献

欢迎提交 Pull Requests!对于重大更改,请先开 issue 讨论您想要改变的内容。

开源协议

MIT License

问题反馈

如果您发现任何问题或有改进建议,欢迎在 GitHub 上提交 issue。

Metadata

Release files for llmrf 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llmrf 0.1.4
File Size Uploaded Provenance
llmrf-0.1.4.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llmrf 0.1.4
File Interpreter ABI Platform
llmrf-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / llmrf-0.1.4.tar.gz

Download URL llmrf-0.1.4.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0a3fead73a5f19a3a5403729404ddf53b9e224bb56de6916229fbced380924b1
BLAKE2b-256 checksum
How to use checksums
40fb05307747bb14cac7319c938228c32d630d31c1df0a0cfb95c0e81191f624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release files / llmrf-0.1.4-py3-none-any.whl

Download URL llmrf-0.1.4-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3384159dc9812e2d4171825484b3d4180154eb606e183231985e748aa6482b01
BLAKE2b-256 checksum
How to use checksums
2cb0132d52059c0a42f2560b7c6ec6eb3c7488ce3346391a2e23bee5a2613146
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Security for llmrf 0.1.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page