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

Uploaded CPython 3.12Windows x86-64

llm_manager-0.3.3-cp312-cp312-manylinux_2_17_x86_64.whl (419.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.3.3-cp312-cp312-macosx_11_0_arm64.whl (328.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.3.3-cp311-cp311-win_amd64.whl (320.0 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.3.3-cp311-cp311-manylinux_2_17_x86_64.whl (414.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.3.3-cp311-cp311-macosx_11_0_arm64.whl (328.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4d3268441132f0035d08db7fbc3ea8b129372829dc7975aeea037eddda8759ba
MD5 6ac781fd3e1cae22ccb91bae9dc961c4
BLAKE2b-256 33a82f64161e5d472bdba1df4f63e72d38fd9a3d4e24c9375202263e794f46e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.3-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1fe2da511dd4e7a2af162c99461d6986d0cd87dcc4bba0f92603a700b9913453
MD5 7d06aaf3a1762a7e61e44c67a0cc8bfa
BLAKE2b-256 668531577d9312e20f0620b65074149bb914edd18c0572464e98d2cf0253b6be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67aef4d02c9f05972a67cef449c8e3fb50abef9a58c6ba0a88d74f584f3f7b38
MD5 fb1f0cbaa0e76397b61b9fc06799d710
BLAKE2b-256 9dd6aa85a63f2933cd845eb3f2ce4226ff4db35e9254f5ad89f8469ee3e4bab3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e5161a1ae622f5c1473854eaa78741e9e65e6a19d29a0fd83a25b282416f9467
MD5 11e8bdf0a60439b86fb3b1d63c247692
BLAKE2b-256 a9fc310e3c20d9f396b51ddd67afae0efab63cb83c2bb1bb033146c50037c08b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.3-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1da389c7d82d1959cda5aaed188c57609ac774821b0bc86345d8b670684dc9cd
MD5 1abb50a538849a16517f7771bd8bdb0b
BLAKE2b-256 76b8072db0e3464a85cdaf9d71de6d9cef90b61754ac77783ff1f4409717f899

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa6dd5661227ca4875af49ad56c8fb10013f4173e798a2ac4a64d7ec01cca153
MD5 76199ce0dbcde93b7d56e3aa686fc02e
BLAKE2b-256 c1e21758291f3e6168356e033e3cbbb0e293ab84ea205b0a057a3979d06b93f9

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