Skip to main content

llm-manager 大模型应用开发

简介

llm-manager是一个用于快速开发大模型应用的Python包。支持MCP服务集成和工具转换。内置工具:CodeInterpreter。

依赖性

基础依赖(安装llm-manager时将自动安装):
  • portalocker
  • cryptography
  • pydantic
  • requests
  • docker
  • fastmcp

安装

# 通过 pip 安装:
pip install llm-manager

配置操作

  1. 模型配置写入

from llm_manager.config import EnvConfig

# 配置名为 'qwen' 的大模型
EnvConfig.write("qwen", endpoint_url="https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", api_key={API_KEY})

# 配置名为 'deepseek' 的大模型
EnvConfig.write("deepseek", endpoint_url="https://api.deepseek.com/chat/completions", api_key={API_KEY})
  1. 应用配置写入

from llm_manager.config import EnvConfig

# 应用名为 'chat' 的大模型配置
EnvConfig.write("chat", llm="deepseek", model="deepseek-chat", temperature=0.9, top_p=0.95, stream=True)

# 应用名为 'qwen-vl' 的大模型配置
EnvConfig.write("qwen-vl", llm="qwen", model="qwen-vl-max-latest", stream=True)

# 读取全部配置文件信息
all_config = EnvConfig.read()

工具开发

tools.py文件内容

import datetime
from typing import Any

from llm_manager.tools import ToolModel


# 自动生成schema
class GetCurrentDate(ToolModel):
    """获取当前日期"""

    def __call__(self) -> dict[str, Any]:
        now = datetime.datetime.now()
        return {"isoformat": now.isoformat(), "isoweekday": now.isoweekday()}


# 自定义schema
class GetCurrentDate(ToolModel):

    @classmethod
    def to_schema(cls) -> dict[str, Any]:
        return {
            "type": "function",
            "function": {
                "name": "GetCurrentDate",
                "description": "获取当前日期"
            }
        }

    def __call__(self) -> dict[str, Any]:
        now = datetime.datetime.now()
        return {"isoformat": now.isoformat(), "isoweekday": now.isoweekday()}

chat应用开发

chat/model.py文件内容

from llm_manager.model import BaseAgent
from llm_manager.tools import Tools

from tools import GetCurrentDate


class LLMChat(BaseAgent):
    _raw: bool = True  # 保持完整输出数据结构(默认False,只输出模型回复)
    _tools: Tools = Tools(GetCurrentDate)

    content: str

    @property
    def _section(self) -> str:
        return "chat"

chat/prompt.py文件内容

SYSTEM = """You are a helpful assistant."""

USER = """{content}"""

chat应用示例

from chat.model import LLMChat

chat = LLMChat(content="还有几天周末放假?")
for chunk in chat.run():
    print(chunk)
for chunk in chat.run(content="周末旅游地点推荐"):
    print(chunk)

OCR应用开发

ocr/model.py文件内容

from llm_manager.model import BaseAgent


class VLMOCR(BaseAgent):

    @property
    def _section(self) -> str:
        return "qwen-vl"

ocr/prompt.py文件内容

SYSTEM = """You are an AI specialized in recognizing and extracting text from images. Your mission is to analyze the image document and generate the result in QwenVL Document Parser HTML format using specified tags while maintaining user privacy and data integrity."""

USER = """QwenVL HTML"""

OCR应用示例

import base64
import pathlib

from ocr.model import VLMOCR


def encode_image(filepath: str) -> str:
    with open(filepath, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")


vlm_ocr = VLMOCR(_images=[encode_image("document.png")])

for chunk in vlm_ocr.run():
    print(chunk, end="")

Metadata

Release files for llm-manager 0.4.5

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

Built distributions (wheels)

Table of built distributions (wheels) for llm-manager 0.4.5
File
llm_manager-0.4.5-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
llm_manager-0.4.5-cp312-cp312-manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
llm_manager-0.4.5-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
llm_manager-0.4.5-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
llm_manager-0.4.5-cp311-cp311-manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
llm_manager-0.4.5-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 5.9 MB

Release files / llm_manager-0.4.5-cp312-cp312-win_amd64.whl

Download URL llm_manager-0.4.5-cp312-cp312-win_amd64.whl
Size 411.4 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
693d706b410c91659765daa8b353d8b232931b6a1815beb24425f91c2c7a9e41
BLAKE2b-256 checksum
How to use checksums
956b992da70f87109ed66d714a8a286e3208b6d2a1284d5739d34d65cfc473ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / llm_manager-0.4.5-cp312-cp312-manylinux_2_17_x86_64.whl

Download URL llm_manager-0.4.5-cp312-cp312-manylinux_2_17_x86_64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8d1957bb23d3f5e98d97813ed539768919538235a920afd41754cd5e75eaf7d4
BLAKE2b-256 checksum
How to use checksums
1edeef2e67d9bdd2d793091505afa55a58a570a70bdca234161f95665efd4341
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / llm_manager-0.4.5-cp312-cp312-macosx_11_0_arm64.whl

Download URL llm_manager-0.4.5-cp312-cp312-macosx_11_0_arm64.whl
Size 436.6 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3e63ffb05b8b07aec54c30a08ea9405884390b0f75e6ac9fa5f5470d9872efd8
BLAKE2b-256 checksum
How to use checksums
78bbb2e5c958b5ffe56a9463faf862e5289371d86bab08df3fc596cbbbf87f02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / llm_manager-0.4.5-cp311-cp311-win_amd64.whl

Download URL llm_manager-0.4.5-cp311-cp311-win_amd64.whl
Size 420.9 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
325871cbda85db833b843bef02631f5b83a8971ba2b3b5e947853f704769f870
BLAKE2b-256 checksum
How to use checksums
87915dd5561843081438add1fd4a6fb5321c1d621fd8543c8948657ece6b2676
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / llm_manager-0.4.5-cp311-cp311-manylinux_2_17_x86_64.whl

Download URL llm_manager-0.4.5-cp311-cp311-manylinux_2_17_x86_64.whl
Size 2.0 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
eb1f07a6bd964c0cf4d271ade90e9841daf31dcadec784d8d0b6b4f0f106358e
BLAKE2b-256 checksum
How to use checksums
9c29ce1926926c9a2d317482d2a76bcf83fe3a3ecf3102e13ef6085a27d2da6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / llm_manager-0.4.5-cp311-cp311-macosx_11_0_arm64.whl

Download URL llm_manager-0.4.5-cp311-cp311-macosx_11_0_arm64.whl
Size 439.1 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ced34fd5ac22441b4e5324d65989cf04b65c203c25a798f9fa093d0d6e3e8c3e
BLAKE2b-256 checksum
How to use checksums
a1d05826bdee14d2f225774d48c9d608bc7769e62e181acba9a8de878b9e887d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Security for llm-manager 0.4.5

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