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.4-cp312-cp312-win_amd64.whl (410.7 kB view details)

Uploaded CPython 3.12Windows x86-64

llm_manager-0.4.4-cp312-cp312-manylinux_2_17_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.4.4-cp312-cp312-macosx_11_0_arm64.whl (435.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.4.4-cp311-cp311-win_amd64.whl (420.2 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.4.4-cp311-cp311-manylinux_2_17_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.4.4-cp311-cp311-macosx_11_0_arm64.whl (437.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 08e71b33874ddda5580cea7cfc4675f487fd42c2575b90abc4e3893253f69340
MD5 7b478598b964a770c387966684b69d70
BLAKE2b-256 7985cfd752a2c6c3e0d385613c32e2623dcf7bd9fac34e2aa3de54ae326d35d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.4-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 47eebed312c8bcfa3d658038ce492a4ba372f0a27830258d35b3a433df7f8801
MD5 b6fd479c4e6ae9aeb6247e9ef2ea3d0f
BLAKE2b-256 1c63fe8017c0c640e06ea85a615712d014d679b88577d6d909c3d4bf53693ad9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc278eb50771a5c52cd46213ce9cbf9071e427fa5a4087c76b103e1ec41a6304
MD5 4465918ad0c76d947be8834a14d5db32
BLAKE2b-256 0941ed125ebd612b2c6eae0284b4a46300876bc1ea0d5be6cf39bf59afd81984

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 293b8896c33dd717225d9419f5cfc14466fe8aaf852d1abefbc15010b68b60aa
MD5 d9caf5e185fb939dd63fb57325934662
BLAKE2b-256 e11b7619e6a5a07a349250379fc15c25413d0ee5434aca176aeb867d47022601

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.4-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d455ddf3b8274b82c16ef92ff6dc22f927c8e82ff46fca9326a285899d3ec692
MD5 530bf02dfbe9fc924a04b8cedf3f90c8
BLAKE2b-256 256cae6c394e1ba613e08fd08d6bc16c8e3d2df9bb4315dfc1f9ad2ef37275a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a00be0cf3022d66ed10728b3c3e5f3466e839a636d3dd93bd7c8def24f23b51d
MD5 219829e0ecf70efb0ad7765c605a4156
BLAKE2b-256 94b3f13e64e406ad6a3c080b3e19e3ab15cc3afd879dd60c493c1059ad6a1a2f

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