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

Uploaded CPython 3.12Windows x86-64

llm_manager-0.4.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (398.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.4.2-cp311-cp311-win_amd64.whl (385.9 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.4.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (400.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0208230fc07618c5c5eccd64c8c701c63ad6812c24ba4af9efd6d7cbd3c2df1b
MD5 6df7a1de3d4c284f8370a79fb6aeb1d7
BLAKE2b-256 6d89e6d869d9d7b12c7d5522845483701bacacd5373001e16cece4285bc8fe5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.2-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8893e59fa87c55f34d2d63676700062828ff60a348f9511d90bf16f1e3ba018a
MD5 3c51293d256cb3f5c592e957a9f62cbc
BLAKE2b-256 04277e8338384ba3e0b0c84c5f51f623ad5a4b991789017add5f6a5b833a6325

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c7e3abd16833ae01cadcbb0dd407e2eb5ad5d443a4ec5a586d0a790b82492d7d
MD5 1a3155399da8effc08d4f1490dd33a8d
BLAKE2b-256 f37fa4d4284a0c94aa1aaf16651cee2fec8a2424aee92b2e7edda47ed39111e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1e8deaf1261578b091edcf66a2eaf18df69d83c004724c087daa0b175f6ca562
MD5 a36ddecfdfab757b5ecbd45c74909f13
BLAKE2b-256 58caec07e9a109283f057c822fb3b3b9f0e8a2b6b37932ce2dac132c9ab8dc16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.2-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 50dd531d3154af068a38d336ad73e2b237de51319ccced13c16f3f52f450cfa7
MD5 38f81bcd5fd7894449b57234109e12be
BLAKE2b-256 35b9e82646f4bb206df0c356be1fafce98eea519d0f826301c6b9e943f41b71a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.4.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1b2a9ac38772be49a8b7eab9e1037f85e216c644ea2f1e01e9605d6f2604774
MD5 5d4d9a2f1446eb8e875476da557a0074
BLAKE2b-256 328a28ffde359e89191662add4b0775b59660ae611761705ee78db2e05aae7b4

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