Flash-built LLM workflows
Project description
llm-manager 大模型应用开发
简介
llm-manager是一个用于快速开发大模型应用的Python包。支持MCP服务集成和工具转换。内置工具:CodeInterpreter。
依赖性
基础依赖(安装llm-manager时将自动安装):
- portalocker
- cryptography
- pydantic
- requests
- docker
- fastmcp
安装
# 通过 pip 安装:
pip install llm-manager
配置操作
-
模型配置写入
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})
-
应用配置写入
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 BaseAgent
from llm_manager.tools import Tools
from tools import GetCurrentDate
class LLMChat(BaseAgent):
_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 BaseAgent
class VLMOCR(BaseAgent):
@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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_manager-0.4.5-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: llm_manager-0.4.5-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 411.4 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
693d706b410c91659765daa8b353d8b232931b6a1815beb24425f91c2c7a9e41
|
|
| MD5 |
ed0e8b0d2a264305314cc807367dd86b
|
|
| BLAKE2b-256 |
956b992da70f87109ed66d714a8a286e3208b6d2a1284d5739d34d65cfc473ff
|
File details
Details for the file llm_manager-0.4.5-cp312-cp312-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: llm_manager-0.4.5-cp312-cp312-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d1957bb23d3f5e98d97813ed539768919538235a920afd41754cd5e75eaf7d4
|
|
| MD5 |
0750dd5efcbd45309d62f48bf06cb95a
|
|
| BLAKE2b-256 |
1edeef2e67d9bdd2d793091505afa55a58a570a70bdca234161f95665efd4341
|
File details
Details for the file llm_manager-0.4.5-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: llm_manager-0.4.5-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 436.6 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e63ffb05b8b07aec54c30a08ea9405884390b0f75e6ac9fa5f5470d9872efd8
|
|
| MD5 |
dfaea49d4e712b337ec7ef50a0b8b0d0
|
|
| BLAKE2b-256 |
78bbb2e5c958b5ffe56a9463faf862e5289371d86bab08df3fc596cbbbf87f02
|
File details
Details for the file llm_manager-0.4.5-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: llm_manager-0.4.5-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 420.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
325871cbda85db833b843bef02631f5b83a8971ba2b3b5e947853f704769f870
|
|
| MD5 |
d82eb0a05afccaae2a67556b3dc7fad9
|
|
| BLAKE2b-256 |
87915dd5561843081438add1fd4a6fb5321c1d621fd8543c8948657ece6b2676
|
File details
Details for the file llm_manager-0.4.5-cp311-cp311-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: llm_manager-0.4.5-cp311-cp311-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb1f07a6bd964c0cf4d271ade90e9841daf31dcadec784d8d0b6b4f0f106358e
|
|
| MD5 |
abaf82bb14cdb57db976d33409a50cf5
|
|
| BLAKE2b-256 |
9c29ce1926926c9a2d317482d2a76bcf83fe3a3ecf3102e13ef6085a27d2da6b
|
File details
Details for the file llm_manager-0.4.5-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: llm_manager-0.4.5-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 439.1 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ced34fd5ac22441b4e5324d65989cf04b65c203c25a798f9fa093d0d6e3e8c3e
|
|
| MD5 |
189aa0728b34d51722c57b8f313c9255
|
|
| BLAKE2b-256 |
a1d05826bdee14d2f225774d48c9d608bc7769e62e181acba9a8de878b9e887d
|