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

Uploaded CPython 3.12Windows x86-64

llm_manager-0.3.0-cp312-cp312-manylinux_2_17_x86_64.whl (397.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (324.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.3.0-cp312-cp312-macosx_10_15_x86_64.whl (326.7 kB view details)

Uploaded CPython 3.12macOS 10.15+ x86-64

llm_manager-0.3.0-cp311-cp311-win_amd64.whl (316.8 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.3.0-cp311-cp311-manylinux_2_17_x86_64.whl (408.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (324.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

llm_manager-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl (330.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5444d90336b359d0dbe901e7d5813166611ee76ca3c7d57cf10eaf827a0c65e4
MD5 7503aae1fa4c83a62e1ef106b490a438
BLAKE2b-256 61dd82f3db5c3307349d248b33237474e99624b5799dc3c5061e05b5cf0f1c72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a3e1e73719c8ab42264ab83584983f3377c462d2a5f8bcf04a54737d3e9935dc
MD5 133288c7d33207e0f5268efa58b97c18
BLAKE2b-256 f7dc66ef18a0e88496a51e8ec744d0c3364992218272ea6ba3959328e5f5290b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ddd4d20d2f3fe1986f716902194dd70b8f5697ef2b7117c9df0512bfd381a9f7
MD5 ae36090125193d74d20c2e025a8b8641
BLAKE2b-256 2ef8394646711480a555051fb94028f24eeedd164ae0d94a940e006d1da54cf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2aa6444b0de4e68302dba18b47e9d604301c8950d93388d20f532957495d3248
MD5 99634432caeb46ff4bb04cc7f0f7cf17
BLAKE2b-256 43815b180dfe41d644921390fe94f7bb7cd9120d75cdaae05d0ea48a44ea410b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b8f25f447c3a1eabcf93265c0d141349f7e8a9a183ca92a9e13ea9149577b1cc
MD5 9a5858d0c161d96ea61acc347ef32d0c
BLAKE2b-256 ab400a89836d13c603b0bdc3a06eaf5af530edeb1a62472c495ae86e899e4f44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f6a476e90d9fe6716db0fba95300e5a5b8d1ee3d617c2bb599c48c0f8b8a74c4
MD5 501feb450e941e78bba0783c9739f6d8
BLAKE2b-256 d24808ec387d2930cf09e7021791094f9c65365645425abbc5ef782d351d524d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f87a166ebafde9b2db26cfa321a7cf2ddfa936cf7449a091ad7671f5eb008bfb
MD5 ab5942d3ee1347af955bb364a8057c74
BLAKE2b-256 55af5853875d39dfb928737e0e511289f8568adb2f74befc0f86eac3fe1bf0d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 af9d71ea1f7fd76a9be6865faafc5097742d94b21229e8ba6b0d010305bd158c
MD5 b2bf963f3061796174129bbaecafc665
BLAKE2b-256 56c3b93b720f0392b10f6b521119d6dee7b1a1481077f103e77ec050bdff3320

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