Skip to main content

Flash-built LLM workflows

Project description

llm-manager 大模型应用开发

简介

llm-manager是一个用于快速开发大模型应用的Python包。内置工具:CodeInterpreter。

依赖性

基础依赖(安装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):
    _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 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.3.2-cp312-cp312-win_amd64.whl (314.1 kB view details)

Uploaded CPython 3.12Windows x86-64

llm_manager-0.3.2-cp312-cp312-manylinux_2_17_x86_64.whl (403.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.3.2-cp312-cp312-macosx_11_0_arm64.whl (328.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.3.2-cp311-cp311-win_amd64.whl (320.2 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.3.2-cp311-cp311-manylinux_2_17_x86_64.whl (413.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.3.2-cp311-cp311-macosx_11_0_arm64.whl (327.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d271c0f3de418e8b52a21ff964ec137d6260110d64d011af3d87d2f0ca594452
MD5 b39bbd35d4deeca339b6dfbe466fc034
BLAKE2b-256 f84c6d24e47837eb9a39d2592b0a9720c3d187fbe44cfe6ec6cb67fc36b27b21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.2-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c9493c7730d7ccfef3b4a5f04bc6ffcbfb18137ead36deed92cd90cc55934e21
MD5 90285f8802e667a9546cbd09be000045
BLAKE2b-256 819abeba916a51293bf20262b9851be7b9e4ce7c749d08d314cdb56c365f2faf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5fe69f7a1a3f5c8b8b845ed71f0b25044eba1c816b1bd747db138fd6eeef0a9d
MD5 2a777998a4f2be703c75b6716425ed94
BLAKE2b-256 588943631a095f92fa4334639743f5d2c7ceba3b057b851e1396aaae2ff3458f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d95de8f665d658965a71eaa308d739deeb13a0510f7bd30931912982d6b7ad18
MD5 55783d2359c4ae0a6c3992f22cfebdbf
BLAKE2b-256 7d816b140b2bd50eb512e5e9debdd3afd4ff8b54c7dbb4ef65167160efc564da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.2-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 eac0875442f97e42650d01814f23d3fda15312ab964dc5e61f89bb4ff5a888c3
MD5 048d08b451ecada4a43cd3fd65c10fa5
BLAKE2b-256 4f3218029abf81d879e49569f6b6cd0623c43be93e94daa0ade434c1c1d7d187

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45702ea96995dc6d6cf9c934ce7af5fad817550d713aa0b4edde79d2b1ee0600
MD5 255d7d5983d8338766957aa7fd55c427
BLAKE2b-256 12d078614331f5c9930af711c828f6472447c037306a2d84cc2970685556755d

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