Skip to main content

Flash-built LLM workflows

Project description

llm-manager 大模型应用开发

简介

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

依赖性

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

安装

# 通过 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.1.0-cp312-cp312-win_amd64.whl (290.7 kB view details)

Uploaded CPython 3.12Windows x86-64

llm_manager-0.1.0-cp312-cp312-manylinux_2_17_x86_64.whl (365.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

llm_manager-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (288.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

llm_manager-0.1.0-cp312-cp312-macosx_10_15_x86_64.whl (305.8 kB view details)

Uploaded CPython 3.12macOS 10.15+ x86-64

llm_manager-0.1.0-cp311-cp311-win_amd64.whl (295.0 kB view details)

Uploaded CPython 3.11Windows x86-64

llm_manager-0.1.0-cp311-cp311-manylinux_2_17_x86_64.whl (382.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

llm_manager-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (290.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

llm_manager-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl (308.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 af6fbba1adeb7486d616363cf55fa0655bfce0e3c213c1889ae2386a315a69c1
MD5 fa6ef20b5d023c2cc6afe08e2bfba3d2
BLAKE2b-256 704b303ae70a3aaf6f1e5b99d39e8c0f81cd50542ca25880ce6689784db12fdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a9b368d02350ed9e7f921b2801280278c47fe26f57daab2ca9bc49639a896cc9
MD5 0691547578af9ac3a232c647c950d34a
BLAKE2b-256 b3c36b4b6ece2c399572495b443f7bb7120c6b8566bc66c5cbc40308ffcf93b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b26039623cdb4dbc5af72906125a083e70c323c5e6f0f4ae9cedc7f62f11116
MD5 c735dd12d9ba8ce0ec0f82199c640296
BLAKE2b-256 2c8ffde06b5f2aa46ae723b79c13f8c150f39e9db6c09b0b2b328aed56f7a417

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 45e395e6cce9efc69be24a3c0bb825b7529248c72eb69683133515db04534822
MD5 f7ba56219c733d32523cb2956c5bf8bb
BLAKE2b-256 2df4adc1a750e338387a7c2c22b56f9e18420c04f97e7900dbc3b90ba6b4865c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fd42e39ecceb7516452d6debde36aa8aa8419830692fafb128b65da57cb06f88
MD5 8c0027abccaf46b1fcc1e2302202793c
BLAKE2b-256 e3f9c3b76a819f8e8375bfbcdf0edad041b7c16f4ffd77f2cf98b38c86fe1e97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 df3dd90612a46f2dcb33c07fd41c3d61961b49024e61036530855efad213f03e
MD5 f32e98dd418bd711efc3c0b1f41474ed
BLAKE2b-256 0b037e88e35c25a129ab110cdb9b5be066192866adcf4ba28b6cf395e654dc1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 172ea13a1b0c5e82773a5899769760632cc647b908577b44be368d3d11957c6b
MD5 1c688cc21e6391843d748c55a2880559
BLAKE2b-256 174c07f0decd9c196ec97524ffb72ca0fe7d58ae4495df0e28a5679bc64b7697

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_manager-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f7210a603856d8f62b8d8a24aea2564b8a79dbeaebe23a6584de47e823a18a56
MD5 86cc6229249a72210d85b9a61c58b915
BLAKE2b-256 35c2a21cefd13222b99b522e99d7d23cc5683a0a5fceee6d6970492a3c864a2c

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