Skip to main content

Flash-built LLM workflows

Project description

llm-manager 大模型应用开发

简介

llm-manager是一个用于快速开发大模型应用的Python包。

依赖性

基础依赖(安装llm-manager时将自动安装):
  • portalocker
  • cryptography
  • pydantic
  • requests

安装

# 通过 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 TLModel
from llm_manager.tools import Tools

from tools import GetCurrentDate


class LLMChat(TLModel):
    _pretty: bool = True  # 美化输出(可选)

    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, end="")
for chunk in chat.run(content="周末旅游地点推荐"):
    print(chunk, end="")

OCR应用开发

ocr/model.py文件内容

from llm_manager.model import VLModel


class VLMOCR(VLModel):

    @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.2.0-cp312-cp312-win_amd64.whl (291.0 kB view details)

Uploaded CPython 3.12Windows x86-64

llm_manager-0.2.0-cp312-cp312-manylinux_2_17_x86_64.whl (368.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (304.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.2.0-cp312-cp312-macosx_10_15_x86_64.whl (306.0 kB view details)

Uploaded CPython 3.12macOS 10.15+ x86-64

llm_manager-0.2.0-cp311-cp311-win_amd64.whl (295.6 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.2.0-cp311-cp311-manylinux_2_17_x86_64.whl (381.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (304.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

llm_manager-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl (308.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a8376eb91e1dfe525ef7507aa5975b6dfca4d2200e51605cafbb313b6177c940
MD5 7c7b11c76b7272309609976fd54e6d1c
BLAKE2b-256 cee6ee1ba9d9547d25766ee960da67bdd0c6d34c7fc64e21f2d446ee68634445

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 ef051fd394a609a153f64178a37e5a2b1d9d3604dd83daba303a7e97d91bae4d
MD5 c302da189a0504e57d27e4989c07fb55
BLAKE2b-256 f00ce8fb01458a26c370822e457032a828b30408ee579aa4ef8d7b04e85ce3af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61644b4a5383d304fd43a9a8e08c575a05c6f5e0ccd576530b077804988ebfcc
MD5 0ba5b6e6043fb4b22e4e2a1d79a38174
BLAKE2b-256 8d70ae8271515fb3801d42ab3e7a1845ce963c437411546b0c0a3c4ce35c5f38

See more details on using hashes here.

File details

Details for the file llm_manager-0.2.0-cp312-cp312-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 efea2f1f498fb9077408b111d4337f4e22db2faab949c269128fdb41cf337dda
MD5 93ca15550fcb602bdf8779cbf15fe801
BLAKE2b-256 6225654646c97bdb3e4580b48354cba4fe3c4ea2323dc62b35688791f0109f4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1052e17da6e6d5d311cbb033c7c1a632cb0640f27b048e630e4cfe151075d9c6
MD5 2109712b0be705550bd9f59c33e0f07f
BLAKE2b-256 bab1b11652837bdb524e90ebd9180b0740a0dd3f668fbe94a1ccdc5fa1ccf05e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 47cf86a01a9a39ae1bb4da4d292d616757be8e8157a60e232b841e64d8cd0584
MD5 ff98ff44e9ef5f9ad61617c5ef44308a
BLAKE2b-256 93112ef136233ab13a86ba7aa1e2569e95beacf64f9f931c1a5cbc2ba961df56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dddb591fde09df4c0f1011ef3a18bb9eb1f4fb7cd2ebd569861550332532c728
MD5 984cb5b29f2f109faa8a36ec8b5c8592
BLAKE2b-256 51d8ed0f926a7cfded2814235cc7f8486276ed1216b8c41073e21914b9cc5e3d

See more details on using hashes here.

File details

Details for the file llm_manager-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for llm_manager-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 33b2ac14a3bc42799062e80a9edb7a0ae3ab3bcaebad6f3e0f6eb8e854ef0703
MD5 b63e953af28c0fee8c542185badcc4cf
BLAKE2b-256 dabb21a0d74ef9c2d155707731ace0dc48c84745bae02fe1775e60212681bf07

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