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

Uploaded CPython 3.12Windows x86-64

llm_manager-0.3.1-cp312-cp312-manylinux_2_17_x86_64.whl (399.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.3.1-cp312-cp312-macosx_11_0_arm64.whl (325.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.3.1-cp312-cp312-macosx_10_15_x86_64.whl (328.1 kB view details)

Uploaded CPython 3.12macOS 10.15+ x86-64

llm_manager-0.3.1-cp311-cp311-win_amd64.whl (318.4 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.3.1-cp311-cp311-manylinux_2_17_x86_64.whl (409.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.3.1-cp311-cp311-macosx_11_0_arm64.whl (326.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

llm_manager-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl (332.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7a9a1f2993cffc64675637881195424c4e8e32f6596a92ffb91b31db1f4f3454
MD5 5041e4578749e1d749329ccce3498c6f
BLAKE2b-256 da344b1e47278e0ae7311b37501ffd18adf3beadf1fe2ec9cee83ba494d6eb5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5793d60e84d242ecffcf64c3d5048b6e24319efa1f9245464aa143096d47bd6e
MD5 4337bb376c7a074c5b348e9c4f23e286
BLAKE2b-256 d99fb0bd63182cd39dae8aa75fd9f30834fc4acf563c7ceb420a3eb9b0c4e066

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 93133ecaf352d93749b298fd2cac876b90a34ff3922452eecb30806a6661390c
MD5 18574d5ff02905b4021af7402951c8f5
BLAKE2b-256 ce79f30cba70fa80472e77b3b75de04c7e39294451ddd923b6df6767f0be0c69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b1c579de2914e010a7edb2b68a0416325f91ee49600b9606ada8f0b89a35db10
MD5 2c149f6f28b0c17704773eb490ab84e8
BLAKE2b-256 236fced7f04ef0979c960ec648c895d09d917267020491ce6016fef3c4cc5d0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9a7580c8110ad9959c067c72850f42b902339f7e59762d2632ec68891da33af1
MD5 f12ff2bb7b7665e02113e796541ad5aa
BLAKE2b-256 37c02dbb52d7b18d98d2360072a3e5ce23ec2b665c4f44dfd6c4a07d234bb3c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0df7057ea523182a826070dea7bdcc4bcc541ed6f518ca823428db4c50536f7d
MD5 1296ca10ebabe0eb1bc5f9e0c3754959
BLAKE2b-256 97d6b9a8075a8b2b94f74a303739d954b5b03b19ced8aa675b28897022c85d66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 496d013b949c76d5bd43f4d79c2cca5edfa09f47001fc138ad7eeccf86078c0b
MD5 b497e3734d6d1d96735f532af21c7bbd
BLAKE2b-256 6484d58771255a5751c90b8239718b19f74ce3c4ab4d1945b3b288c77bbe0a2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bedc383bdf4a16811951ecd46b91919ee4e222da9c7acdf5d56bb571c9752953
MD5 a42036589209f25091f09ec8ef75f545
BLAKE2b-256 fa7ed1ec2e2cc45bf9c3aa46481cb9aa2647530503218a07f3be99416b544e7d

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