Skip to main content

Flash-built LLM workflows

Project description

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="")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

llm_manager-0.4.0-cp312-cp312-win_amd64.whl (376.7 kB view details)

Uploaded CPython 3.12Windows x86-64

llm_manager-0.4.0-cp312-cp312-manylinux_2_17_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (398.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.4.0-cp311-cp311-win_amd64.whl (386.0 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.4.0-cp311-cp311-manylinux_2_17_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (400.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file llm_manager-0.4.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 363c2df2d79b55c73baf131a08c9b3a14226b0cb89fd55bf36fda96bb308848f
MD5 dc1ceaad9714228bea6f34bed2f6c4ba
BLAKE2b-256 6b5c5551cd6ae436776e4449c2bef2f92024e2db8611fff5677c6b7fc8b18103

See more details on using hashes here.

File details

Details for the file llm_manager-0.4.0-cp312-cp312-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.0-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8627ca629eac068fda10902b8c35472f857a2c98d4eed2bbd7331b079073e85e
MD5 e477004b9150b084835d9b3dfacf8a6d
BLAKE2b-256 434278ceae1217020e4a6ad3a6355005a68bfac414a05f6d2ebf890ccb219edb

See more details on using hashes here.

File details

Details for the file llm_manager-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba785249e737be5b9da513d30c92e3cd7e714c0bba26cb62466335a72d32154b
MD5 911a5154e18a1f928fb4f1f88db2b411
BLAKE2b-256 e0b2efcf765e60181b56147fa289448a866455a1eba0178d38f367a509f79b46

See more details on using hashes here.

File details

Details for the file llm_manager-0.4.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 266d6a78e8ef0be65b7d0ab2eacda10476711864e7307c00c212bdce82c87af6
MD5 2b5198b3288d944505b45506ed49ea4c
BLAKE2b-256 2d325f8b5d2250e40613754c675d0927bbe5f50a3ad7dbf6737894e1edbdc25b

See more details on using hashes here.

File details

Details for the file llm_manager-0.4.0-cp311-cp311-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c388f178ee6d409eb45b43808ca0bda0ba8296aab081aadc73031b0ea6992860
MD5 843d238cbcc1b4a3fed4ca82358a25e5
BLAKE2b-256 395833386f8829ade7763022cefc68acb9cb91feb9ae8a8703c98ce5e4c0d641

See more details on using hashes here.

File details

Details for the file llm_manager-0.4.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee84b4e81a7fc20e5a99f8f0b7a21d570f18a7258ac4a9cf359c5928d25ebf88
MD5 73f4489fa5d4b2062e86bf403a64af7b
BLAKE2b-256 a4b31a32cfc3480f77bd91e19bcd57de374562d9a96723603b6c58ae5433ddbc

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