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

Uploaded CPython 3.12Windows x86-64

llm_manager-0.4.1-cp312-cp312-manylinux_2_17_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.4.1-cp311-cp311-win_amd64.whl (386.1 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.4.1-cp311-cp311-manylinux_2_17_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.4.1-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.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for llm_manager-0.4.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e4abde4aa28fb33ad5aa71e39a426280a2030c31ba869dd9ae07b44e65441139
MD5 f018c856c58eddda109e2056db4f871f
BLAKE2b-256 266091ccfea19f470671a5ede1c2942c4f1dbedb3c2a7a587e16f93af416809a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.1-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 170fa7d479fdee4d480174d962ef0286b5b33f98eb9d146f1ad2e80ba194140e
MD5 25a4ae9bfce6d17803cc3265ca4445df
BLAKE2b-256 f4db5ddab85e1d0e096061ac7cae09e20d96e7e73267cfce964a918c7737e2e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fecd825db39e041623975f53cf605380c6f691838b56cb4f0c8d020c8502f3e7
MD5 312e7860a89fe92fe0c60b15955a03aa
BLAKE2b-256 301ef87348fd505727bd2d41244656d1a21a2eea14ffff7c28bd83fe9f3df827

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 65d4a972f40f6dce1dff60c41ab63b806b1b7900227612d6a39d2f789d8f8d81
MD5 e1c2874dbbaee12293a40996d7944a69
BLAKE2b-256 7aa956b32782b5efcb237b18f6689714e7024dbe56ace8fd4190490bd8ec0489

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.1-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 24757e84139996f2f44727e5b57c54ee94d0ab35e1c0807bc8f773a8ae08376d
MD5 db8f5ea710d9e114776a76ce8bab76a4
BLAKE2b-256 d105d29caaf61e7e76761b542dad26a28989b1e3de5f54e875cc00c33830b509

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b88a92e3dbe29fec9e64c10fca71b1bb52992bad5658e7cda8e5e1d4d8d79dee
MD5 ab82e452464e87ffd5db8adf4308d7c3
BLAKE2b-256 06bac1511d23c3116ca7bad00f934008c751188a6a6c7047b719784b9ec659a5

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