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

Uploaded CPython 3.12Windows x86-64

llm_manager-0.4.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (434.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.4.3-cp311-cp311-win_amd64.whl (420.0 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.4.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (437.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 128c4a97c5c995a7048738c88074ef055ac918dbbe9b9a7fe96aee5391ebfdf9
MD5 733c3ce287556adeba8f46cbcfe5780b
BLAKE2b-256 d887120b2b847fc53df7c925ec2af63e16bd7f509c60fe7568409c5e8cabe28d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.3-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 156eeca9a26a3969ef2fc601bab6a411b9293a3da282b851aa31118a934ddbc7
MD5 4bc748d2f7f36aec1f24cd3bd3d18ebb
BLAKE2b-256 411bb00b7d7b56b0dac469fcd31785a10d7ce9799903cfa95675c0c7b32788c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9cf67799d59fe0891f19f7899ae3bcb957a14127a831c9bdfdb6370010e11ab
MD5 a64553d72b89c9c15ac9da5928a0641d
BLAKE2b-256 a52b4e7676c9fd643b64c01f196a4e3fae456edb8783dc63360b5d74e4400dc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7f2f98098eb33f00a442da81d2055492bba878be99d213a47ce6b107cbf2e00d
MD5 da65ef348eae092b4d7a8ab72e6f0abf
BLAKE2b-256 f8c5ed676baeef30642b7f9d585de0131944f84299a995e164461a10057bffb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.3-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 39718371c9f4d05d45fb5e965aac0233c873fd00a3f15fbf6d94da691ead7684
MD5 42cdad3b7d2b1cd71d82574cf8e46d41
BLAKE2b-256 f17a24bd9f705421bd3aacd1c627a2915180df2f6f6c26f1f032c1ae079a45e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aeec507c5e71c6e31964e8d6f4bbb2e288712cb22e3a5f8040e12cb76c8d0623
MD5 1d054f84ededf7b767180609df6fe2b0
BLAKE2b-256 cf3e02122bd9800f44819d7c99ff595b1ff7f5b6189204e969d0d573753e9598

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