[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-callmesora--llmops-python-package":3,"tool-callmesora--llmops-python-package":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",157379,2,"2026-04-15T23:32:42",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":76,"owner_twitter":76,"owner_website":76,"owner_url":77,"languages":78,"stars":98,"forks":99,"last_commit_at":100,"license":101,"difficulty_score":102,"env_os":103,"env_gpu":103,"env_ram":103,"env_deps":104,"category_tags":118,"github_topics":76,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":119,"updated_at":120,"faqs":121,"releases":122},7852,"callmesora\u002Fllmops-python-package","llmops-python-package","Kickstart your LLMOps initiative with a flexible, robust, and productive Python package.","llmops-python-package 是一个专为大语言模型（LLM）运营打造的 Python 工具包，旨在帮助团队快速构建灵活、稳健且高效的 LLMOps 工作流。它解决了大模型从实验开发到生产部署过程中常见的代码规范不统一、流程自动化缺失以及监控困难等痛点，让开发者无需从零搭建基础设施。\n\n这款工具特别适合从事大模型应用的 AI 工程师、研究人员及开发团队使用。无论是需要管理模型注册、追踪实验数据，还是构建实时推理服务，llmops-python-package 都能提供标准化的最佳实践支持。其独特之处在于深度融合了现代软件工程理念与大模型特性：不仅集成了 Ruff、Pytest、Mypy 等工具确保代码质量与安全，还通过 Mlflow 实现全链路的模型管理与评估，并利用 Litserve 简化服务部署。此外，项目内置了 Commitizen、Pre-Commit 等自动化机制，配合 YAML 配置与 Pydantic 验证，大幅降低了维护成本。作为基于成熟 MLOps 模板的进化版本，它针对 LLM 场景进行了专门优化，是开启规范化大模型工程实践的得力助手。","# LLMOps Python Pacakge\n\n[![check.yml](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fcheck.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fcheck.yml)\n[![publish.yml](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fpublish.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fpublish.yml)\n\n[![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fcallmesora\u002Fllmops-python-package)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Fblob\u002Fmain\u002FLICENCE.txt)\n[![Release](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fv\u002Frelease\u002Fcallmesora\u002Fllmops-python-package)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Freleases)\n\n**This repository contains a Python code base with best practices designed to support your LLMOps initiatives.**\n\n![LLMOps Python Package](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_49b8ca99b75b.png)\n\nThe package leverages several [tools](#tools) and [tips](#tips) to make your LLMOps experience as flexible, robust, productive as possible.\n\n\nYou can use this package as part of your LLMOps toolkit or platform (e.g., Model Registry, Experiment Tracking, Realtime Inference, ...).\n\nThis package is a variation \u002F fork of these resources but specicially tailored for LLM use cases:\n\n**Related Resources**:\n- **[MLOps Coding Course (Learning)](https:\u002F\u002Fgithub.com\u002FMLOps-Courses\u002Fmlops-coding-course)**: Learn how to create, develop, and maintain a state-of-the-art MLOps code base.\n- **[Cookiecutter MLOps Package (Template)](https:\u002F\u002Fgithub.com\u002Ffmind\u002Fcookiecutter-mlops-package)**: Start building and deploying Python packages and Docker images for MLOps tasks.\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_021b50e310f9.png)\n\n# Table of Contents\n\n- [LLMOps Python Package](#mlops-python-package)\n- [Table of Contents](#table-of-contents)\n- [Install](#install)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n  - [Next Steps](#next-steps)\n- [Usage](#usage)\n  - [Configuration](#configuration)\n  - [Execution](#execution)\n  - [Automation](#automation)\n  - [Workflows](#workflows)\n- [Tools](#tools)\n  - [Automation](#automation-1)\n    - [Commits: Commitizen](#commits-commitizen)\n    - [Git Hooks: Pre-Commit](#git-hooks-pre-commit)\n    - [Tasks: PyInvoke](#tasks-pyinvoke)\n  - [CI\u002FCD](#cicd)\n    - [Runner: GitHub Actions](#runner-github-actions)\n  - [CLI](#cli)\n    - [Parser: Argparse](#parser-argparse)\n    - [Logging: Loguru](#logging-loguru)\n  - [Code](#code)\n    - [Coverage: Coverage](#coverage-coverage)\n    - [Editor: VS Code](#editor-vs-code)\n    - [Formatting: Ruff](#formatting-ruff)\n    - [Quality: Ruff](#quality-ruff)\n    - [Security: Bandit](#security-bandit)\n    - [Testing: Pytest](#testing-pytest)\n    - [Typing: Mypy](#typing-mypy)\n    - [Versioning: Git](#versioning-git)\n  - [Configs](#configs)\n    - [Format: YAML](#format-yaml)\n    - [Parser: OmegaConf](#parser-omegaconf)\n    - [Reader: Cloudpathlib](#reader-cloudpathlib)\n    - [Validator: Pydantic](#validator-pydantic)\n  - [Model](#model)\n    - [Format: Mlflow Model](#format-mlflow-model)\n    - [Registry: Mlflow Registry](#registry-mlflow-registry)\n    - [Tracking: Mlflow Tracking](#tracking-mlflow-tracking)\n  - [Package](#package)\n    - [Evolution: Changelog](#evolution-changelog)\n    - [Format: Wheel](#format-wheel)\n    - [Manager: Poetry](#manager-poetry)\n    - [Runtime: Docker](#runtime-docker)\n  - [Programming](#programming)\n    - [Language: Python](#language-python)\n    - [Version: Pyenv](#version-pyenv)\n  - [Observability](#observability)\n    - [Monitoring : Mlflow Evaluate](#monitoring--mlflow-evaluate)\n    - [Infrastructure: Mlflow System Metrics](#infrastructure-mlflow-system-metrics)\n  - [Model Serving](#endpoint)\n    - [Serving Endpoint: Litserve](#serving-endpoint)\n- [Tips](#tips)\n  - [Design Patterns](#design-patterns)\n    - [Directed-Acyclic Graph](#directed-acyclic-graph)\n    - [Program Service](#program-service)\n    - [Soft Coding](#soft-coding)\n    - [SOLID Principles](#solid-principles)\n    - [IO Separation](#io-separation)\n  - [Python Powers](#python-powers)\n    - [Context Manager](#context-manager)\n    - [Python Package](#python-package)\n  - [Software Engineering](#software-engineering)\n    - [Code Typing](#code-typing)\n    - [Config Typing](#config-typing)\n    - [Object Oriented](#object-oriented)\n    - [Semantic Versioning](#semantic-versioning)\n  - [Testing Tricks](#testing-tricks)\n    - [Parallel Testing](#parallel-testing)\n    - [Test Fixtures](#test-fixtures)\n  - [VS Code](#vs-code)\n    - [Code Workspace](#code-workspace)\n    - [GitHub Copilot](#github-copilot)\n- [Resources](#resources)\n  - [Python](#python)\n  - [AI\u002FML\u002FMLOps](#aimlmlops)\n\n# Architecture\n\n## RAG Evaluation\n\nRAG Evaluation is performed by generating a synthetic dataset of QA answer pairs. This dataset serves as a baseline to evaluate the performance of different RAG systems before deploying them. By using a consistent and controlled dataset, we can objectively compare the effectiveness of various RAG implementations.\n\n![RAG Lifecycle](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_031f73cf5503.png)\n\n## Model Registry\n\nWe use a pattern where all LLM chains are stored and logged in Mlflow. Each chain is evaluated against the RAG evaluation baseline. If a chain demonstrates better performance than the previous ones, it is registered and promoted to production. This ensures that only the best-performing models are deployed.\n\n![Experiment Tracking](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_f42055039b70.png)\n\n## Guardrails\nHaving Guardrails is important in production since it prevents the model from entering unexpected\u002F undesired behaviours.\n\nThis LLMOps template comes with a setup config files for guardrails for PII and Topic censuring that is built on top of [Guardrails AI](https:\u002F\u002Fgithub.com\u002Fguardrails-ai\u002Fguardrails?tab=readme-ov-file)\n\n![Guardrails](static\u002Fwith_and_without_guardrails.svg)\n\n\n## Endpoint Deployment\n\nHaving a model registry is crucial for managing and running deployments. In this architecture, we use [Litserve](https:\u002F\u002Flightning.ai\u002Fdocs\u002Flitserve\u002Fhome), which builds on top of FastAPI, to deploy our LLMs. This setup allows for flexible deployment options, including Kubernetes and AWS Lambda, ensuring that our models can be scaled and managed efficiently.\n\n![Litserve](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_8acf558a020a.png)\n\nYou can check how to serve the model as well as code template to deploy on AWS Fargate under `\u002Fserving_endpoint`folder\n\n\n## Model Monitoring\n\nModel monitoring is crucial for ensuring the performance and reliability of your LLMs in production. Continuous monitoring helps in detecting issues such as performance degradation, and unexpected behaviors, which can significantly impact the user experience and business outcomes.\n\n![Mlflow Traces](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_2ec69931d593.gif)\n\n\nWe use Mlflow Traces for monitoring our LLMs. This allows us to track various metrics and logs associated with the models over time. Additionally, we run evaluations on these traces using Mlflow Evaluate, with the LLM itself acting as a judge. This setup ensures that we maintain high standards for model performance and can quickly identify and address any issues that arise.\n\n\n## LLMOps Design Pattern\nIn this project we use a very similar design pattern to that recommended by databricks, where each model gets logged on mlflow before its deployed.\n![LLMOps Databricks](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_49db9738fdea.png)\n\nThe main variations here is that we the deployment pipeline is orchestrated in the form of two steps with register, validations and final deployment on the registry. Instead of data drift we are measuring differences in LLM metrics and finnaly we aren't using Mlflow AI Gateway (altough this or LiteLLM could be an adition in the future)\n\n\n# Install\n\nThis section details the requirements, actions, and next steps to kickstart your LLMOps project.\n\n## Prerequisites\n\n- [Python>=3.10](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F): to benefit from [the latest features and performance improvements](https:\u002F\u002Fdocs.python.org\u002F3\u002Fwhatsnew\u002F3.12.html)\n- [Poetry>=1.8.2](https:\u002F\u002Fpython-poetry.org\u002F): to initialize the project [virtual environment](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fvenv.html) and its dependencies\n\nUse the package manager [Poetry](https:\u002F\u002Fpython-poetry.org\u002F):\n\n## Credentials for LLM\n\nTo access Bedrock, OpenAI, or any other LLM provider, you need to set up your  credentials. These credentials will allow the package to authenticate and interact with the respective services.\nIn this code template we used Bedrock but feel free to change it to your needs.\n\nExample for AWS \n\n **Environment Variables**:\n    ```bash\n    export AWS_ACCESS_KEY_ID=your_access_key_id\n    export AWS_SECRET_ACCESS_KEY=your_secret_access_key\n    export AWS_REGION=your_default_region\n    ```\n\n\n  - You can easily replace `ChatBedrock` with `ChatOllama` or any other provider. \n\n\n## Installation\n\n1. [Clone this GitHub repository](https:\u002F\u002Fdocs.github.com\u002Fen\u002Frepositories\u002Fcreating-and-managing-repositories\u002Fcloning-a-repository) on your computer\n```bash\n# with ssh (recommended)\n$ git clone -\n# with https\n$ git clone -\n```\n2. [Run the project installation with poetry](https:\u002F\u002Fpython-poetry.org\u002Fdocs\u002F)\n```bash\n$ cd llmops-python-package\u002F\n$ poetry install\n```\n3. Adapt the code base to your desire\n\n## Next Steps\n\nThere are numerous ways to incorporate this package into your MLOps platform.\n\nFor example, you might choose Databricks or AWS for your compute platform and model registry.\n\nFeel free to modify the package code to suit your specific needs. Best of luck!\n\n\n# Usage\n\nThis section explains how configure the project code and execute it on your system.\n\n## Configuration\n\nYou can add or edit config files in the `confs\u002F` folder to change the program behavior.\n\n```yaml\n# confs\u002Fdeployment.yaml\njob:\n  KIND: DeploymentJob\n  staging_alias: \"champion\"\n  production_alias: \"production\"\n  registry_model_name: \"rag-chatbot-with-guardrails\"\n  llm_confs: \"\u002Fconfs\u002Frag_chain_config.yaml\"\n  llm_model_code_path: \"\u002Fsrc\u002Fllmops_project\u002Fmodels\u002Fchatbot_with_guardrails.py\"\n  vector_store_path: \"http:\u002F\u002Flocalhost:6333\"\n```\n\nThis config file instructs the program to start a `DeploymentJob` with respective parameters\nYou can find all the parameters of your program in the `src\u002F[package]\u002Fpipelines\u002F*.py` files.\n\nYou can also print the full schema supported by this package using `poetry run llmops --schema`.\n\n## Execution\n\nThe project code can be executed with poetry during your development, this is the order recommended:\n\n```bash\n$ poetry run llmops-project confs\u002Fgenerate_rag_dataset.yaml # Run once to generate rag dataset\n$ poetry run llmops-project confs\u002Ffeature_eng.yaml # Creates Vector DB and Injests documents\n$ poetry run llmops-project confs\u002Fdeployment.yaml # Deploys model on model registry\n$ poetry run llmops-project confs\u002Fmonitoring.yaml # Monitors Model Inferences \"every week\"\n```\n\nTo deploy the serving endpoint you can use the following automation:\n\n```bash\n$ inv serve # Launches Litserve server on port 8000\n```\n\nNote: you can also deploy this as a container \u002Fcloud with the instructions under `\u002Fserving_endpoint`\n\n## Pipelines\nThis project is organized under a manager pattern, each manager is responsible for all the workflow orchestration betwen tasks\u002F jobs. (In production you could use airflow etc.. for this type of thing)\n\n### Generate Rag Dataset\nThis pipeline generates a rag QA dataset under `\u002Fdata\u002Fdatasets\u002F``\n\n### Feature Engineering \nThis pipeline creates a Vector Database instance collection and ingests documents onto it in the form of vectors.\n![Vector Database](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_b35ace470c34.png)\n\n### Deployment \nThis pipeline:\n-  registers a model using Mlflow \n-  promote the model to `champion`alias\n-  validates model input \u002Foutput and singatures\n-  sets tag \"passed_tests\" on mlflow registry to True\u002FFalse depending if model passed tests\n-  runs an evaluation of QA factfullness on the QA dataset we created previously\n-  depending on the result of this evaluation, the model will be asigned a tag `beats_threshold` to True or False\n-  if the model `beats_threshold` and `passed_tests` we can promote it to `production`\n\nAt the end of this pipeline we should have a model version on the model registry in production.\n![Model Version](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_7fe954d03775.png)\n\n\n### Monitoring\nThis pipeline is meant to be run as weekly job to monitor the performance of the model against given metrics such as default metrics or even LLM as a judge.\n![Monitoring](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_1960747c58bc.png)\n\nThese metrics are also saved with a display in case you want to load it in a dashboard elsewhere.\n![Guage](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_469041dbb8cf.png)\n\n\n\n\nIn production, you can build, ship, and run the project as a Python package:\n\n```bash\npoetry build\npoetry publish # optional\npython -m pip install [package]\n[package] confs\u002Fdeployment.yaml\n```\n\nYou can also install and use this package as a library for another AI\u002FML project:\n\n```python\nfrom [package] import pipelines\n\njob = pipelines.DeploymentJob(...)\nwith job as runner:\n    runner.run()\n```\n\n**Additional tips**:\n- You can pass extra configs from the command line using the `--extras` flag\n  - Use it to pass runtime values (e.g., a result from previous job executions)\n- You can pass several config files in the command-line to merge them from left to right\n  - You can define common configurations shared between jobs (e.g., model params)\n- The right job task will be selected automatically thanks to [Pydantic Discriminated Unions](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002Fconcepts\u002Funions\u002F#discriminated-unions)\n  - This is a great way to run any job supported by the application (training, tuning, ....)\n\n\n## Automation\n\nThis project includes several automation tasks to easily repeat common actions.\n\nYou can invoke the actions from the [command-line](https:\u002F\u002Fwww.pyinvoke.org\u002F) or [VS Code extension](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=dchanco.vsc-invoke).\n\n```bash\n# create a code archive\n$ inv packages\n# list other actions\n$ inv --list\n```\n\n**Available tasks**:\n- **checks.all (checks)** - Run all check tasks.\n- **checks.code** - Check the codes with ruff.\n- **checks.coverage** - Check the coverage with coverage.\n- **checks.format** - Check the formats with ruff.\n- **checks.poetry** - Check poetry config files.\n- **checks.security** - Check the security with bandit.\n- **checks.test** - Check the tests with pytest.\n- **checks.type** - Check the types with mypy.\n- **cleans.all (cleans)** - Run all tools and folders tasks.\n- **cleans.cache** - Clean the cache folder.\n- **cleans.coverage** - Clean the coverage tool.\n- **cleans.dist** - Clean the dist folder.\n- **cleans.docs** - Clean the docs folder.\n- **cleans.environment** - Clean the project environment file.\n- **cleans.folders** - Run all folders tasks.\n- **cleans.mlruns** - Clean the mlruns folder.\n- **cleans.mypy** - Clean the mypy tool.\n- **cleans.outputs** - Clean the outputs folder.\n- **cleans.poetry** - Clean poetry lock file.\n- **cleans.pytest** - Clean the pytest tool.\n- **cleans.projects** - Run all projects tasks.\n- **cleans.python** - Clean python caches and bytecodes.\n- **cleans.requirements** - Clean the project requirements file.\n- **cleans.reset** - Run all tools, folders, and sources tasks.\n- **cleans.ruff** - Clean the ruff tool.\n- **cleans.sources** - Run all sources tasks.\n- **cleans.tools** - Run all tools tasks.\n- **cleans.venv** - Clean the venv folder.\n- **commits.all (commits)** - Run all commit tasks.\n- **commits.bump** - Bump the version of the package.\n- **commits.commit** - Commit all changes with a message.\n- **commits.info** - Print a guide for messages.\n- **containers.all (containers)** - Run all container tasks.\n- **containers.build** - Build the container image with the given tag.\n- **containers.compose** - Start up docker compose.\n- **containers.run** - Run the container image with the given tag.\n- **docs.all (docs)** - Run all docs tasks.\n- **docs.api** - Document the API with pdoc using the given format and output directory.\n- **docs.serve** - Serve the API docs with pdoc using the given format and computer port.\n- **formats.all** - (formats) Run all format tasks.\n- **formats.imports** - Format python imports with ruff.\n- **formats.sources** - Format python sources with ruff.\n- **installs.all (installs)** - Run all install tasks.\n- **installs.poetry** - Install poetry packages.\n- **installs.pre-commit** - Install pre-commit hooks on git.\n- **mlflow.all (mlflow)** - Run all mlflow tasks.\n- **mlflow.doctor** - Run mlflow doctor to diagnose issues.\n- **mlflow.serve** - Start mlflow server with the given host, port, and backend uri.\n- **packages.all (packages)** - Run all package tasks.\n- **packages.build** - Build a python package with the given format.\n- **projects.all (projects)** - Run all project tasks.\n- **projects.environment** - Export the project environment file.\n- **projects.requirements** - Export the project requirements file.\n- **projects.run** - Run an mlflow project from MLproject file.\n\n# Tools\n\nThis sections motivates the use of developer tools to improve your coding experience.\n- Most developer tools in this project are the same ones used in the mlops-python package. Check that resource for a detailed explanation on the motivation behind these toolings.\n\n\n\n# Tips\n\nThis sections gives some tips and tricks to enrich the develop experience.\n\n## [Design Patterns](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftware_design_pattern)\n\n### [Directed-Acyclic Graph](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDirected_acyclic_graph)\n\n**You should use Directed-Acyclic Graph (DAG) to connect the steps of your ML pipeline.**\n\nA DAG can express the dependencies between steps while keeping the individual step independent.\n\nThis package provides a simple DAG example in `tasks\u002Fdags.py`. This approach is based on [PyInvoke](https:\u002F\u002Fwww.pyinvoke.org\u002F).\n\nIn production, we recommend to use a scalable system such as [Airflow](https:\u002F\u002Fairflow.apache.org\u002F), [Dagster](https:\u002F\u002Fdagster.io\u002F), [Prefect](https:\u002F\u002Fwww.prefect.io\u002F), [Metaflow](https:\u002F\u002Fmetaflow.org\u002F), or [ZenML](https:\u002F\u002Fzenml.io\u002F).\n\n### [Program Service](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSystemd)\n\n**You should provide a global context for the execution of your program.**\n\nThere are several approaches such as [Singleton](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSingleton_pattern), [Global Variable](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGlobal_variable), or [Component](https:\u002F\u002Fgithub.com\u002Fstuartsierra\u002Fcomponent).\n\nThis package takes inspiration from [Clojure mount](https:\u002F\u002Fgithub.com\u002Ftolitius\u002Fmount). It provides an implementation in `src\u002F[package]\u002Fio\u002Fservices.py`.\n\n### [Soft Coding](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftcoding)\n\n**You should separate the program implementation from the program configuration.**\n\nExposing configurations to users allow them to influence the execution behavior without code changes.\n\nThis package seeks to expose as much parameter as possible to the users in configurations stored in the `confs\u002F` folder.\n\n### [SOLID Principles](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSOLID)\n\n**You should implement the SOLID principles to make your code as flexible as possible.**\n\n- *Single responsibility principle*:  Class has one job to do. Each change in requirements can be done by changing just one class.\n- *Open\u002Fclosed principle*: Class is happy (open) to be used by others. Class is not happy (closed) to be changed by others.\n- *Liskov substitution principle*: Class can be replaced by any of its children. Children classes inherit parent's behaviours.\n- *Interface segregation principle*: When classes promise each other something, they should separate these promises (interfaces) into many small promises, so it's easier to understand.\n- *Dependency inversion principle*: When classes talk to each other in a very specific way, they both depend on each other to never change. Instead classes should use promises (interfaces, parents), so classes can change as long as they keep the promise.\n\nIn practice, this mean you can implement software contracts with interface and swap the implementation.\n\nFor instance, you can implement several jobs in `src\u002F[package]\u002Fjobs\u002F*.py` and swap them in your configuration.\n\nTo learn more about the mechanism select for this package, you can check the documentation for [Pydantic Tagged Unions](https:\u002F\u002Fdocs.pydantic.dev\u002Fdev-v2\u002Fusage\u002Ftypes\u002Funions\u002F#discriminated-unions-aka-tagged-unions).\n\n### [IO Separation](https:\u002F\u002Fen.wikibooks.org\u002Fwiki\u002FHaskell\u002FUnderstanding_monads\u002FIO)\n\n**You should separate the code interacting with the external world from the rest.**\n\nThe external is messy and full of risks: missing files, permission issue, out of disk ...\n\nTo isolate these risks, you can put all the related code in an `io` package and use interfaces\n\n## [Python Powers](https:\u002F\u002Frealpython.com\u002F)\n\n### [Context Manager](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fcontextlib.html)\n\n**You should use Python context manager to control and enhance an execution.**\n\nPython provides contexts that can be used to extend a code block. For instance:\n\n```python\n# in src\u002F[package]\u002Fscripts.py\nwith job as runner:  # context\n    runner.run()  # run in context\n```\n\nThis pattern has the same benefit as [Monad](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FMonad_(functional_programming)), a powerful programming pattern.\n\nThe package uses `src\u002F[package]\u002Fjobs\u002F*.py` to handle exception and services.\n\n### [Python Package](https:\u002F\u002Fpackaging.python.org\u002Fen\u002Flatest\u002Ftutorials\u002Fpackaging-projects\u002F)\n\n**You should create Python package to create both library and application for others.**\n\nUsing Python package for your AI\u002FML project has the following benefits:\n- Build code archive (i.e., wheel) that be uploaded to Pypi.org\n- Install Python package as a library (e.g., like pandas)\n- Expose script entry points to run a CLI or a GUI\n\nTo build a Python package with Poetry, you simply have to type in a terminal:\n```bash\n# for all poetry project\npoetry build\n# for this project only\ninv packages\n```\n\n## [Software Engineering](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftware_engineering)\n\n### [Code Typing](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Ftyping.html)\n\n**You should type your Python code to make it more robust and explicit for your user.**\n\nPython provides the [typing module](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Ftyping.html) for adding type hints and [mypy](https:\u002F\u002Fmypy-lang.org\u002F) to checking them.\n\n\nThis code snippet clearly state the inputs and outputs of the method, both for the developer and the type checker.\n\nThe package aims to type every functions and classes to facilitate the developer experience and fix mistakes before execution.\n\n### [Config Typing](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002F)\n\n**You should type your configuration to avoid exceptions during the program execution.**\n\nPydantic allows to define classes that can validate your configs during the program startup.\n\n```python\n# in src\u002F[package]\u002Futils\u002Fsplitters.py\nclass TrainTestSplitter(Splitter):\n    shuffle: bool = False  # required (time sensitive)\n    test_size: int | float = 24 * 30 * 2  # 2 months\n    random_state: int = 42\n```\n\nThis code snippet allows to communicate the values expected and avoid error that could be avoided.\n\nThe package combines both OmegaConf and Pydantic to parse YAML files and validate them as soon as possible.\n\n\n### [Object Oriented](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FObject-oriented_programming)\n\n**You should use the Objected Oriented programming to benefit from [polymorphism](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPolymorphism_(computer_science)).**\n\nPolymorphism combined with SOLID Principles allows to easily swap your code components.\n\nThe package defines class interface whenever possible to provide intuitive and replaceable parts for your AI\u002FML project.\n\n### [Semantic Versioning](https:\u002F\u002Fsemver.org\u002F)\n\n**You should use semantic versioning to communicate the level of compatibility of your releases.**\n\nSemantic Versioning (SemVer) provides a simple schema to communicate code changes. For package X.Y.Z:\n- *Major* (X): major release with breaking changed (i.e., imply actions from the benefit)\n- *Minor* (Y): minor release with new features (i.e., provide new capabilities)\n- *Patch* (Z): patch release to fix bugs (i.e., correct wrong behavior)\n\nPoetry and this package leverage Semantic Versioning to let developers control the speed of adoption for new releases.\n\n## [Testing Tricks](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftware_testing)\n\n### [Parallel Testing](https:\u002F\u002Fpytest-xdist.readthedocs.io\u002Fen\u002Fstable\u002F)\n\n**You can run your tests in parallel to speed up the validation of your code base.**\n\nPytest can be extended with the [pytest-xdist plugin](https:\u002F\u002Fpytest-xdist.readthedocs.io\u002Fen\u002Fstable\u002F) for this purpose.\n\nThis package enables Pytest in its automation tasks by default.\n\n### [Test Fixtures](https:\u002F\u002Fdocs.pytest.org\u002Fen\u002Flatest\u002Fexplanation\u002Ffixtures.html)\n\n**You should define reusable objects and actions for your tests with [fixtures](https:\u002F\u002Fdocs.pytest.org\u002Fen\u002Flatest\u002Fexplanation\u002Ffixtures.html).**\n\nFixture can prepare objects for your test cases, such as dataframes, models, files.\n\nThis package defines fixtures in `tests\u002Fconftest.py` to improve your testing experience.\n\n## [VS Code](https:\u002F\u002Fcode.visualstudio.com\u002F)\n\n### [Code Workspace](https:\u002F\u002Fcode.visualstudio.com\u002Fdocs\u002Feditor\u002Fworkspaces)\n\n**You can use VS Code workspace to define configurations for your project.**\n\n[Code Workspace](https:\u002F\u002Fcode.visualstudio.com\u002Fdocs\u002Feditor\u002Fworkspaces) can enable features (e.g. formatting) and set the default interpreter.\n\n```json\n{\n\t\"settings\": {\n\t\t\"editor.formatOnSave\": true,\n\t\t\"python.defaultInterpreterPath\": \".venv\u002Fbin\u002Fpython\",\n    ...\n\t},\n}\n```\n\nThis package defines a workspace file that you can load from `[package].code-workspace`.\n\n### [GitHub Copilot](https:\u002F\u002Fgithub.com\u002Ffeatures\u002Fcopilot)\n\n**You can use GitHub Copilot to increase your coding productivity by 30%.**\n\n[GitHub Copilot](https:\u002F\u002Fgithub.com\u002Ffeatures\u002Fcopilot) has been a huge productivity thanks to its smart completion.\n\nYou should become familiar with the solution in less than a single coding session.\n\n### [VSCode VIM](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=vscodevim.vim)\n\n**You can use VIM keybindings to more efficiently navigate and modify your code.**\n\nLearning VIM is one of the best investment for a career in IT. It can make you 30% more productive.\n\nCompared to GitHub Copilot, VIM can take much more time to master. You can expect a ROI in less than a month.\n\n# Resources\n\nThis section provides resources for building packages for Python and AI\u002FML\u002FMLOps.\n\n## Python\n\n- https:\u002F\u002Fgithub.com\u002Fkrzjoa\u002Fawesome-python-data-science#readme\n- https:\u002F\u002Fgithub.com\u002Fml-tooling\u002Fbest-of-ml-python\n- https:\u002F\u002Fgithub.com\u002Fml-tooling\u002Fbest-of-python\n- https:\u002F\u002Fgithub.com\u002Fml-tooling\u002Fbest-of-python-dev\n- https:\u002F\u002Fgithub.com\u002Fvinta\u002Fawesome-python\n\n## AI\u002FML\u002FMLOps\n\n- https:\u002F\u002Fgithub.com\u002Fjosephmisiti\u002Fawesome-machine-learning\n- https:\u002F\u002Fgithub.com\u002Fvisenger\u002Fawesome-mlops\n\n\n\n\n\n","# LLMOps Python 包\n\n[![check.yml](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fcheck.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fcheck.yml)\n[![publish.yml](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fpublish.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Factions\u002Fworkflows\u002Fpublish.yml)\n\n[![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fcallmesora\u002Fllmops-python-package)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Fblob\u002Fmain\u002FLICENCE.txt)\n[![Release](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fv\u002Frelease\u002Fcallmesora\u002Fllmops-python-package)](https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package\u002Freleases)\n\n**本仓库包含一套基于最佳实践的 Python 代码库，旨在支持您的 LLMOps 项目。**\n\n![LLMOps Python 包](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_49b8ca99b75b.png)\n\n该包利用多种 [工具](#tools) 和 [技巧](#tips)，以尽可能提升您在 LLMOps 方面的灵活性、健壮性和生产力。\n\n\n您可以将此包用作 LLMOps 工具链或平台的一部分（例如模型注册表、实验跟踪、实时推理等）。\n\n本包是对以下资源的变体或分支，但专门针对 LLM 使用场景进行了优化：\n\n**相关资源**：\n- **[MLOps 编程课程（学习）](https:\u002F\u002Fgithub.com\u002FMLOps-Courses\u002Fmlops-coding-course)**：学习如何创建、开发和维护最先进的 MLOps 代码库。\n- **[Cookiecutter MLOps 包（模板）](https:\u002F\u002Fgithub.com\u002Ffmind\u002Fcookiecutter-mlops-package)**：开始构建并部署用于 MLOps 任务的 Python 包和 Docker 镜像。\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_021b50e310f9.png)\n\n# 目录\n\n- [LLMOps Python 包](#mlops-python-package)\n- [目录](#table-of-contents)\n- [安装](#install)\n  - [先决条件](#prerequisites)\n  - [安装](#installation)\n  - [后续步骤](#next-steps)\n- [使用](#usage)\n  - [配置](#configuration)\n  - [执行](#execution)\n  - [自动化](#automation)\n  - [工作流](#workflows)\n- [工具](#tools)\n  - [自动化](#automation-1)\n    - [提交：Commitizen](#commits-commitizen)\n    - [Git 钩子：Pre-Commit](#git-hooks-pre-commit)\n    - [任务：PyInvoke](#tasks-pyinvoke)\n  - [CI\u002FCD](#cicd)\n    - [运行器：GitHub Actions](#runner-github-actions)\n  - [CLI](#cli)\n    - [解析器：Argparse](#parser-argparse)\n    - [日志：Loguru](#logging-loguru)\n  - [代码](#code)\n    - [覆盖率：Coverage](#coverage-coverage)\n    - [编辑器：VS Code](#editor-vs-code)\n    - [格式化：Ruff](#formatting-ruff)\n    - [质量：Ruff](#quality-ruff)\n    - [安全：Bandit](#security-bandit)\n    - [测试：Pytest](#testing-pytest)\n    - [类型检查：Mypy](#typing-mypy)\n    - [版本控制：Git](#versioning-git)\n  - [配置](#configs)\n    - [格式：YAML](#format-yaml)\n    - [解析器：OmegaConf](#parser-omegaconf)\n    - [读取器：Cloudpathlib](#reader-cloudpathlib)\n    - [验证器：Pydantic](#validator-pydantic)\n  - [模型](#model)\n    - [格式：Mlflow Model](#format-mlflow-model)\n    - [注册表：Mlflow Registry](#registry-mlflow-registry)\n    - [跟踪：Mlflow Tracking](#tracking-mlflow-tracking)\n  - [包](#package)\n    - [演进：Changelog](#evolution-changelog)\n    - [格式：Wheel](#format-wheel)\n    - [管理工具：Poetry](#manager-poetry)\n    - [运行时：Docker](#runtime-docker)\n  - [编程](#programming)\n    - [语言：Python](#language-python)\n    - [版本：Pyenv](#version-pyenv)\n  - [可观测性](#observability)\n    - [监控：Mlflow Evaluate](#monitoring--mlflow-evaluate)\n    - [基础设施：Mlflow 系统指标](#infrastructure-mlflow-system-metrics)\n  - [模型服务](#endpoint)\n    - [服务端点：Litserve](#serving-endpoint)\n- [提示](#tips)\n  - [设计模式](#design-patterns)\n    - [有向无环图](#directed-acyclic-graph)\n    - [程序服务](#program-service)\n    - [软编码](#soft-coding)\n    - [SOLID 原则](#solid-principles)\n    - [IO 分离](#io-separation)\n  - [Python 力量](#python-powers)\n    - [上下文管理器](#context-manager)\n    - [Python 包](#python-package)\n  - [软件工程](#software-engineering)\n    - [代码类型检查](#code-typing)\n    - [配置类型检查](#config-typing)\n    - [面向对象](#object-oriented)\n    - [语义版本控制](#semantic-versioning)\n  - [测试技巧](#testing-tricks)\n    - [并行测试](#parallel-testing)\n    - [测试夹具](#test-fixtures)\n  - [VS Code](#vs-code)\n    - [代码工作区](#code-workspace)\n    - [GitHub Copilot](#github-copilot)\n- [资源](#resources)\n  - [Python](#python)\n  - [AI\u002FML\u002FMLOps](#aimlmlops)\n\n# 架构\n\n## RAG 评估\n\nRAG 评估是通过生成一个 QA 答案对的合成数据集来完成的。该数据集作为基准，用于在部署不同 RAG 系统之前评估其性能。通过使用一致且受控的数据集，我们可以客观地比较各种 RAG 实现的有效性。\n\n![RAG 生命周期](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_031f73cf5503.png)\n\n## 模型注册表\n\n我们采用一种模式，将所有 LLM 链存储并记录在 Mlflow 中。每条链都会与 RAG 评估基准进行对比。如果某条链的表现优于之前的链，则会被注册并晋升到生产环境。这样可以确保只有表现最好的模型才会被部署。\n\n![实验跟踪](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_f42055039b70.png)\n\n## 守护机制\n在生产环境中，守护机制非常重要，因为它可以防止模型出现意外或不良行为。\n\n此 LLMOps 模板附带了用于 PII 和主题审查的守护机制配置文件，这些配置是在 [Guardrails AI](https:\u002F\u002Fgithub.com\u002Fguardrails-ai\u002Fguardrails?tab=readme-ov-file) 的基础上构建的。\n\n![守护机制](static\u002Fwith_and_without_guardrails.svg)\n\n\n## 端点部署\n\n拥有模型注册表对于管理和运行部署至关重要。在此架构中，我们使用 [Litserve](https:\u002F\u002Flightning.ai\u002Fdocs\u002Flitserve\u002Fhome)，它基于 FastAPI 构建，用于部署我们的 LLM。这种设置提供了灵活的部署选项，包括 Kubernetes 和 AWS Lambda，从而确保我们的模型能够高效地扩展和管理。\n\n![Litserve](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_8acf558a020a.png)\n\n您可以在 `\u002Fserving_endpoint` 文件夹下查看如何提供模型服务以及在 AWS Fargate 上部署的代码模板。\n\n## 模型监控\n\n模型监控对于确保生产环境中大型语言模型（LLM）的性能和可靠性至关重要。持续的监控有助于检测诸如性能下降、异常行为等问题，这些问题可能会显著影响用户体验和业务成果。\n\n![Mlflow Traces](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_2ec69931d593.gif)\n\n\n我们使用 Mlflow Traces 来监控我们的 LLM。这使我们能够随着时间推移跟踪与模型相关的各种指标和日志。此外，我们还使用 Mlflow Evaluate 对这些跟踪记录进行评估，并以 LLM 本身作为评判者。这种设置确保了我们维持高标准的模型性能，并能快速识别和解决任何出现的问题。\n\n\n## LLMOps 设计模式\n在该项目中，我们采用了与 Databricks 推荐非常相似的设计模式，即在每个模型部署之前先将其记录到 Mlflow 中。\n![LLMOps Databricks](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_49db9738fdea.png)\n\n这里的主要变化在于，我们的部署流水线以两个步骤的形式编排：注册、验证，最后在注册表上完成部署。我们不是监测数据漂移，而是测量 LLM 指标的变化；另外，我们目前没有使用 Mlflow AI Gateway（尽管未来可以考虑加入它或 LiteLLM）。\n\n\n# 安装\n\n本节详细介绍了启动您的 LLMOps 项目所需的条件、操作步骤及后续工作。\n\n## 前提条件\n\n- [Python>=3.10](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F)：以便利用[最新功能和性能改进](https:\u002F\u002Fdocs.python.org\u002F3\u002Fwhatsnew\u002F3.12.html)\n- [Poetry>=1.8.2](https:\u002F\u002Fpython-poetry.org\u002F)：用于初始化项目的[虚拟环境](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fvenv.html)及其依赖项\n\n请使用包管理器 [Poetry](https:\u002F\u002Fpython-poetry.org\u002F)：\n\n## LLM 凭证\n\n要访问 Bedrock、OpenAI 或其他 LLM 提供商的服务，您需要设置相应的凭证。这些凭证将允许该软件包进行身份验证并与相应服务交互。在此代码模板中，我们使用了 Bedrock，但您可以根据需求自由更改。\n\n以 AWS 为例：\n\n**环境变量**：\n    ```bash\n    export AWS_ACCESS_KEY_ID=your_access_key_id\n    export AWS_SECRET_ACCESS_KEY=your_secret_access_key\n    export AWS_REGION=your_default_region\n    ```\n\n\n  - 您可以轻松地将 `ChatBedrock` 替换为 `ChatOllama` 或其他提供商。\n\n\n## 安装\n\n1. 将此 GitHub 仓库[克隆到您的计算机](https:\u002F\u002Fdocs.github.com\u002Fen\u002Frepositories\u002Fcreating-and-managing-repositories\u002Fcloning-a-repository)\n```bash\n# 使用 ssh（推荐）\n$ git clone -\n# 使用 https\n$ git clone -\n```\n2. [使用 poetry 运行项目安装](https:\u002F\u002Fpython-poetry.org\u002Fdocs\u002F)\n```bash\n$ cd llmops-python-package\u002F\n$ poetry install\n```\n3. 根据您的需求调整代码库\n\n## 后续步骤\n\n有许多方法可以将此软件包集成到您的 MLOps 平台中。\n\n例如，您可以选择 Databricks 或 AWS 作为计算平台和模型注册表。\n\n请随时修改软件包代码以满足您的特定需求。祝您好运！\n\n\n# 使用说明\n\n本节说明如何配置项目代码并在您的系统上执行。\n\n## 配置\n\n您可以在 `confs\u002F` 文件夹中添加或编辑配置文件，以改变程序的行为。\n\n```yaml\n# confs\u002Fdeployment.yaml\njob:\n  KIND: DeploymentJob\n  staging_alias: \"champion\"\n  production_alias: \"production\"\n  registry_model_name: \"rag-chatbot-with-guardrails\"\n  llm_confs: \"\u002Fconfs\u002Frag_chain_config.yaml\"\n  llm_model_code_path: \"\u002Fsrc\u002Fllmops_project\u002Fmodels\u002Fchatbot_with_guardrails.py\"\n  vector_store_path: \"http:\u002F\u002Flocalhost:6333\"\n```\n\n此配置文件指示程序以相应参数启动 `DeploymentJob`。您可以在 `src\u002F[package]\u002Fpipelines\u002F*.py` 文件中找到程序的所有参数。\n\n您还可以使用 `poetry run llmops --schema` 打印出该软件包支持的完整架构。\n\n## 执行\n\n在开发过程中，您可以使用 poetry 执行项目代码，推荐顺序如下：\n\n```bash\n$ poetry run llmops-project confs\u002Fgenerate_rag_dataset.yaml # 运行一次以生成 RAG 数据集\n$ poetry run llmops-project confs\u002Ffeature_eng.yaml # 创建向量数据库并注入文档\n$ poetry run llmops-project confs\u002Fdeployment.yaml # 将模型部署到模型注册表\n$ poetry run llmops-project confs\u002Fmonitoring.yaml # 每周监控模型推理\n```\n\n要部署服务端点，您可以使用以下自动化命令：\n\n```bash\n$ inv serve # 在端口 8000 上启动 Litserve 服务器\n```\n\n注意：您也可以按照 `\u002Fserving_endpoint` 下的说明，将其部署为容器或云端服务。\n\n## 流水线\n该项目采用管理器模式组织，每个管理器负责任务\u002F作业之间的整个工作流编排。（在生产环境中，您可以使用 Airflow 等工具来实现此类功能）\n\n### 生成 RAG 数据集\n此流水线会在 `\u002Fdata\u002Fdatasets\u002F` 目录下生成一个 RAG QA 数据集。\n\n### 特征工程\n此流水线创建一个向量数据库实例，并以向量形式将文档注入其中。\n![向量数据库](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_b35ace470c34.png)\n\n### 部署\n此流水线：\n- 使用 Mlflow 注册模型\n- 将模型提升至 `champion` 别名\n- 验证模型的输入\u002F输出及签名\n- 在 Mlflow 注册表上设置标签 `passed_tests`，根据模型是否通过测试将其值设为 True 或 False\n- 对我们先前创建的 QA 数据集进行 QA 事实性评估\n- 根据评估结果，为模型分配标签 `beats_threshold`，值为 True 或 False\n- 如果模型既 `beats_threshold` 又 `passed_tests`，则可将其提升至 `production`\n\n在该流水线结束时，我们应该在模型注册表中拥有一个处于生产状态的模型版本。\n![模型版本](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_7fe954d03775.png)\n\n### 监控\n此流水线旨在作为每周作业运行，以监控模型在给定指标上的表现，例如默认指标，甚至使用大型语言模型作为评判者。\n![监控](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_1960747c58bc.png)\n\n这些指标也会被保存并显示出来，以便您可以在其他地方的仪表板中加载它们。\n![仪表盘](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_readme_469041dbb8cf.png)\n\n\n\n\n在生产环境中，您可以将该项目构建、发布并作为一个 Python 包来运行：\n\n```bash\npoetry build\npoetry publish # 可选\npython -m pip install [package]\n[package] confs\u002Fdeployment.yaml\n```\n\n您也可以将此包作为库安装并用于另一个 AI\u002FML 项目：\n\n```python\nfrom [package] import pipelines\n\njob = pipelines.DeploymentJob(...)\nwith job as runner:\n    runner.run()\n```\n\n**附加提示**：\n- 您可以使用 `--extras` 标志从命令行传递额外的配置\n  - 可用于传递运行时值（例如，来自先前作业执行的结果）\n- 您可以在命令行中传递多个配置文件，按从左到右的顺序合并它们\n  - 您可以定义作业之间共享的通用配置（例如，模型参数）\n- 右侧的任务将自动选择，这得益于 [Pydantic 鉴别联合类型](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002Fconcepts\u002Funions\u002F#discriminated-unions)\n  - 这是运行应用程序支持的任何任务（训练、调优等）的绝佳方式\n\n\n## 自动化\n\n该项目包含多项自动化任务，可轻松重复常见操作。\n\n您可以从 [命令行](https:\u002F\u002Fwww.pyinvoke.org\u002F) 或 [VS Code 扩展](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=dchanco.vsc-invoke) 调用这些操作。\n\n```bash\n# 创建代码归档\n$ inv packages\n# 列出其他操作\n$ inv --list\n```\n\n**可用任务**：\n- **checks.all (检查)** - 运行所有检查任务。\n- **checks.code** - 使用 ruff 检查代码。\n- **checks.coverage** - 使用 coverage 检查覆盖率。\n- **checks.format** - 使用 ruff 检查格式。\n- **checks.poetry** - 检查 poetry 配置文件。\n- **checks.security** - 使用 bandit 检查安全性。\n- **checks.test** - 使用 pytest 检查测试。\n- **checks.type** - 使用 mypy 检查类型。\n- **cleans.all (清理)** - 运行所有工具和文件夹任务。\n- **cleans.cache** - 清理缓存文件夹。\n- **cleans.coverage** - 清理覆盖率工具。\n- **cleans.dist** - 清理 dist 文件夹。\n- **cleans.docs** - 清理文档文件夹。\n- **cleans.environment** - 清理项目环境文件。\n- **cleans.folders** - 运行所有文件夹任务。\n- **cleans.mlruns** - 清理 mlruns 文件夹。\n- **cleans.mypy** - 清理 mypy 工具。\n- **cleans.outputs** - 清理输出文件夹。\n- **cleans.poetry** - 清理 poetry 锁文件。\n- **cleans.pytest** - 清理 pytest 工具。\n- **cleans.projects** - 运行所有项目任务。\n- **cleans.python** - 清理 Python 缓存和字节码。\n- **cleans.requirements** - 清理项目需求文件。\n- **cleans.reset** - 运行所有工具、文件夹和源文件任务。\n- **cleans.ruff** - 清理 ruff 工具。\n- **cleans.sources** - 运行所有源文件任务。\n- **cleans.tools** - 运行所有工具任务。\n- **cleans.venv** - 清理 venv 文件夹。\n- **commits.all (提交)** - 运行所有提交任务。\n- **commits.bump** - 提升软件包版本。\n- **commits.commit** - 提交所有更改并附带消息。\n- **commits.info** - 打印消息指南。\n- **containers.all (容器)** - 运行所有容器任务。\n- **containers.build** - 使用指定标签构建容器镜像。\n- **containers.compose** - 启动 docker compose。\n- **containers.run** - 使用指定标签运行容器镜像。\n- **docs.all (文档)** - 运行所有文档任务。\n- **docs.api** - 使用 pdoc 按照指定格式和输出目录记录 API 文档。\n- **docs.serve** - 使用 pdoc 按照指定格式和计算机端口提供 API 文档服务。\n- **formats.all** - （格式）运行所有格式任务。\n- **formats.imports** - 使用 ruff 格式化 Python 导入语句。\n- **formats.sources** - 使用 ruff 格式化 Python 源代码。\n- **installs.all (安装)** - 运行所有安装任务。\n- **installs.poetry** - 安装 poetry 包。\n- **installs.pre-commit** - 在 git 上安装预提交钩子。\n- **mlflow.all (mlflow)** - 运行所有 mlflow 任务。\n- **mlflow.doctor** - 运行 mlflow doctor 诊断问题。\n- **mlflow.serve** - 使用指定主机、端口和后端 URI 启动 mlflow 服务器。\n- **packages.all (包)** - 运行所有打包任务。\n- **packages.build** - 使用指定格式构建 Python 包。\n- **projects.all (项目)** - 运行所有项目任务。\n- **projects.environment** - 导出项目环境文件。\n- **projects.requirements** - 导出项目需求文件。\n- **projects.run** - 从 MLproject 文件运行 mlflow 项目。\n\n# 工具\n\n本节旨在鼓励使用开发工具来提升您的编码体验。\n- 本项目中的大多数开发工具与 mlops-python 包中使用的工具相同。请参阅该资源，以获取有关这些工具背后动机的详细说明。\n\n\n\n# 提示\n\n本节提供了一些技巧和窍门，以丰富开发体验。\n\n## [设计模式](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftware_design_pattern)\n\n### [有向无环图](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDirected_acyclic_graph)\n\n**您应该使用有向无环图 (DAG) 来连接您的机器学习流水线步骤。**\n\nDAG 可以表达步骤之间的依赖关系，同时保持每个步骤的独立性。\n\n本包在 `tasks\u002Fdags.py` 中提供了一个简单的 DAG 示例。这种方法基于 [PyInvoke](https:\u002F\u002Fwww.pyinvoke.org\u002F)。\n\n在生产环境中，我们建议使用可扩展的系统，如 [Airflow](https:\u002F\u002Fairflow.apache.org\u002F)、[Dagster](https:\u002F\u002Fdagster.io\u002F)、[Prefect](https:\u002F\u002Fwww.prefect.io\u002F)、[Metaflow](https:\u002F\u002Fmetaflow.org\u002F) 或 [ZenML](https:\u002F\u002Fzenml.io\u002F)。\n\n### [程序服务](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSystemd)\n\n**您应该为程序的执行提供一个全局上下文。**\n\n有几种方法，例如 [单例模式](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSingleton_pattern)、[全局变量](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGlobal_variable) 或 [组件](https:\u002F\u002Fgithub.com\u002Fstuartsierra\u002Fcomponent)。\n\n本包受到 [Clojure mount](https:\u002F\u002Fgithub.com\u002Ftolitius\u002Fmount) 的启发，在 `src\u002F[package]\u002Fio\u002Fservices.py` 中提供了实现。\n\n### [软编码](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftcoding)\n\n**您应该将程序实现与程序配置分开。**\n\n向用户公开配置可以让他们无需修改代码即可影响程序的执行行为。\n\n本包力求将尽可能多的参数暴露给用户，并将其存储在 `confs\u002F` 文件夹中的配置中。\n\n### [SOLID 原则](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSOLID)\n\n**你应该实现 SOLID 原则，以使你的代码尽可能灵活。**\n\n- *单一职责原则*：类只负责一项工作。每当需求发生变化时，只需修改一个类即可。\n- *开闭原则*：类乐于（开放）被他人使用；但不乐于（封闭）被他人修改。\n- *里氏替换原则*：任何子类都可以替换其父类。子类继承了父类的行为。\n- *接口隔离原则*：当类之间相互承诺某些功能时，应将这些承诺（接口）拆分为多个小的、更易理解的接口。\n- *依赖反转原则*：当类之间以非常具体的方式交互时，它们会互相依赖，从而导致难以更改。相反，类应该依赖于抽象的承诺（接口或父类），这样即使类本身发生变化，只要遵守承诺，就不会影响整体。\n\n在实践中，这意味着你可以通过接口实现软件契约，并轻松切换其实现。\n\n例如，你可以在 `src\u002F[package]\u002Fjobs\u002F*.py` 中实现多个任务，并在配置中进行切换。\n\n要了解更多关于本包所选机制的信息，可以查阅 [Pydantic 标记联合体](https:\u002F\u002Fdocs.pydantic.dev\u002Fdev-v2\u002Fusage\u002Ftypes\u002Funions\u002F#discriminated-unions-aka-tagged-unions) 的文档。\n\n### [IO 分离](https:\u002F\u002Fen.wikibooks.org\u002Fwiki\u002FHaskell\u002FUnderstanding_monads\u002FIO)\n\n**你应该将与外部世界交互的代码与其他部分分离。**\n\n外部环境往往杂乱无章且充满风险：文件丢失、权限问题、磁盘空间不足等。\n\n为了隔离这些风险，你可以将所有相关代码放入一个 `io` 包中，并使用接口来管理。\n\n## [Python 功能](https:\u002F\u002Frealpython.com\u002F)\n\n### [上下文管理器](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fcontextlib.html)\n\n**你应该使用 Python 上下文管理器来控制和增强代码的执行过程。**\n\nPython 提供了上下文管理器，可用于扩展代码块的功能。例如：\n\n```python\n# 在 src\u002F[package]\u002Fscripts.py 中\nwith job as runner:  # 上下文\n    runner.run()  # 在上下文中执行\n```\n\n这种模式与强大的编程模式 [Monad](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FMonad_(functional_programming)) 具有相同的优势。\n\n该包使用 `src\u002F[package]\u002Fjobs\u002F*.py` 来处理异常和提供服务。\n\n### [Python 包](https:\u002F\u002Fpackaging.python.org\u002Fen\u002Flatest\u002Ftutorials\u002Fpackaging-projects\u002F)\n\n**你应该创建 Python 包，以便为他人提供库和应用程序。**\n\n在你的 AI\u002FML 项目中使用 Python 包具有以下优势：\n- 构建可上传到 PyPI.org 的代码归档（即 wheel 文件）\n- 将 Python 包作为库安装（例如 pandas）\n- 暴露脚本入口点，以运行 CLI 或 GUI\n\n要使用 Poetry 构建 Python 包，你只需在终端中输入以下命令：\n```bash\n# 对于所有 Poetry 项目\npoetry build\n# 仅针对本项目\ninv packages\n```\n\n## [软件工程](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftware_engineering)\n\n### [代码类型注解](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Ftyping.html)\n\n**你应该为你的 Python 代码添加类型注解，以使其更加健壮并明确地向用户展示其用途。**\n\nPython 提供了 [typing 模块](https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Ftyping.html)，用于添加类型提示，并使用 [mypy](https:\u002F\u002Fmypy-lang.org\u002F) 来检查这些类型提示。\n\n这段代码清晰地说明了方法的输入和输出，无论是对开发者还是类型检查器都十分有用。\n\n该包旨在为所有函数和类添加类型注解，以提升开发体验并在执行前发现错误。\n\n### [配置类型注解](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002F)\n\n**你应该为你的配置添加类型注解，以避免程序运行时出现异常。**\n\nPydantic 允许定义类，在程序启动时验证你的配置。\n\n```python\n# 在 src\u002F[package]\u002Futils\u002Fsplitters.py 中\nclass TrainTestSplitter(Splitter):\n    shuffle: bool = False  # 必需（时间敏感）\n    test_size: int | float = 24 * 30 * 2  # 2 个月\n    random_state: int = 42\n```\n\n这段代码能够明确传达预期的值，从而避免本可避免的错误。\n\n该包结合使用 OmegaConf 和 Pydantic，以尽早解析 YAML 文件并进行验证。\n\n### [面向对象编程](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FObject-oriented_programming)\n\n**你应该使用面向对象编程，以利用 [多态性](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPolymorphism_(computer_science)) 的优势。**\n\n结合 SOLID 原则，多态性使得你可以轻松地替换代码组件。\n\n该包尽可能定义类接口，以为你的 AI\u002FML 项目提供直观且可替换的模块。\n\n### [语义化版本控制](https:\u002F\u002Fsemver.org\u002F)\n\n**你应该使用语义化版本控制来传达你发布的版本之间的兼容性级别。**\n\n语义化版本控制（SemVer）提供了一种简单的模式来传达代码变更。对于 X.Y.Z 版本号：\n- *主版本*（X）：重大发布，包含破坏性变更（即需要采取行动以适应的变化）\n- *次版本*（Y）：次要版本，包含新功能（即提供新的能力）\n- *补丁版本*（Z）：补丁版本，用于修复 bug（即纠正错误行为）\n\nPoetry 和本包都利用语义化版本控制，让开发者能够控制新版本的采用速度。\n\n## [测试技巧](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSoftware_testing)\n\n### [并行测试](https:\u002F\u002Fpytest-xdist.readthedocs.io\u002Fen\u002Fstable\u002F)\n\n**你可以并行运行测试，以加快代码库的验证速度。**\n\n为此，可以使用 [pytest-xdist 插件](https:\u002F\u002Fpytest-xdist.readthedocs.io\u002Fen\u002Fstable\u002F) 扩展 pytest。\n\n本包默认在自动化任务中启用 pytest。\n\n### [测试夹具](https:\u002F\u002Fdocs.pytest.org\u002Fen\u002Flatest\u002Fexplanation\u002Ffixtures.html)\n\n**你应该使用 [夹具](https:\u002F\u002Fdocs.pytest.org\u002Fen\u002Flatest\u002Fexplanation\u002Ffixtures.html) 定义可重用的对象和操作，以支持你的测试。**\n\n夹具可以为你的测试用例准备对象，例如数据框、模型、文件等。\n\n本包在 `tests\u002Fconftest.py` 中定义了夹具，以提升你的测试体验。\n\n## [VS Code](https:\u002F\u002Fcode.visualstudio.com\u002F)\n\n### [代码工作区](https:\u002F\u002Fcode.visualstudio.com\u002Fdocs\u002Feditor\u002Fworkspaces)\n\n**你可以使用 VS Code 工作区为你的项目定义配置。**\n\n[代码工作区](https:\u002F\u002Fcode.visualstudio.com\u002Fdocs\u002Feditor\u002Fworkspaces) 可以启用特定功能（如格式化）并设置默认解释器。\n\n```json\n{\n\t\"settings\": {\n\t\t\"editor.formatOnSave\": true,\n\t\t\"python.defaultInterpreterPath\": \".venv\u002Fbin\u002Fpython\",\n    ...\n\t},\n}\n```\n\n本包定义了一个工作区文件，你可以从 `[package].code-workspace` 加载它。\n\n### [GitHub Copilot](https:\u002F\u002Fgithub.com\u002Ffeatures\u002Fcopilot)\n\n**你可以使用 GitHub Copilot 将你的编码效率提升 30%。**\n\n[GitHub Copilot](https:\u002F\u002Fgithub.com\u002Ffeatures\u002Fcopilot) 凭借其智能补全功能，极大地提升了开发效率。\n\n你只需一次编码会话，就能熟悉这套工具的使用方法。\n\n### [VSCode VIM](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=vscodevim.vim)\n\n**你可以通过 VIM 键位绑定更高效地导航和编辑代码。**\n\n学习 VIM 是投身 IT 行业的最佳投资之一，它能让你的工作效率提升 30%。\n\n与 GitHub Copilot 相比，VIM 需要更多时间来掌握。不过，通常不到一个月就能看到回报。\n\n# 资源\n\n本节提供用于构建 Python 及 AI\u002FML\u002FMLOps 相关软件包的资源。\n\n## Python\n\n- https:\u002F\u002Fgithub.com\u002Fkrzjoa\u002Fawesome-python-data-science#readme\n- https:\u002F\u002Fgithub.com\u002Fml-tooling\u002Fbest-of-ml-python\n- https:\u002F\u002Fgithub.com\u002Fml-tooling\u002Fbest-of-python\n- https:\u002F\u002Fgithub.com\u002Fml-tooling\u002Fbest-of-python-dev\n- https:\u002F\u002Fgithub.com\u002Fvinta\u002Fawesome-python\n\n## AI\u002FML\u002FMLOps\n\n- https:\u002F\u002Fgithub.com\u002Fjosephmisiti\u002Fawesome-machine-learning\n- https:\u002F\u002Fgithub.com\u002Fvisenger\u002Fawesome-mlops","# llmops-python-package 快速上手指南\n\n本指南帮助中国开发者快速搭建基于最佳实践的 LLMOps（大语言模型运维）项目。该工具包集成了模型注册、实验追踪、RAG 评估、护栏（Guardrails）及服务部署等功能。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**：Linux, macOS 或 Windows (WSL2 推荐)\n*   **Python 版本**：>= 3.10 (推荐使用 3.12 以获得最佳性能)\n*   **包管理器**：Poetry >= 1.8.2\n*   **LLM 凭证**：需配置云厂商（如 AWS Bedrock, OpenAI 等）的访问密钥。\n\n### 前置依赖安装\n\n如果您尚未安装 Poetry，可以通过以下方式安装（国内用户若遇网络问题，可尝试使用国内镜像或代理）：\n\n```bash\n# 官方安装脚本\ncurl -sSL https:\u002F\u002Finstall.python-poetry.org | python3 -\n\n# 验证安装\npoetry --version\n```\n\n### 配置 LLM 凭证\n\n本项目默认示例使用 AWS Bedrock。您需要在终端导出环境变量以进行认证：\n\n```bash\nexport AWS_ACCESS_KEY_ID=your_access_key_id\nexport AWS_SECRET_ACCESS_KEY=your_secret_access_key\nexport AWS_REGION=your_default_region\n```\n\n> **提示**：您可以轻松将代码中的 `ChatBedrock` 替换为 `ChatOllama` 或其他提供商以适应本地或国内模型服务。\n\n## 安装步骤\n\n### 1. 克隆项目\n\n使用 Git 克隆仓库到本地：\n\n```bash\n# 推荐方式使用 SSH\ngit clone git@github.com:callmesora\u002Fllmops-python-package.git\n\n# 或使用 HTTPS\ngit clone https:\u002F\u002Fgithub.com\u002Fcallmesora\u002Fllmops-python-package.git\n```\n\n### 2. 进入目录并安装依赖\n\n进入项目文件夹并使用 Poetry 安装所有依赖及创建虚拟环境：\n\n```bash\ncd llmops-python-package\u002F\npoetry install\n```\n\n### 3. 验证安装\n\n安装完成后，您可以查看支持的配置架构以验证环境是否正常：\n\n```bash\npoetry run llmops --schema\n```\n\n## 基本使用\n\n本项目采用流水线（Pipeline）模式管理 RAG 生命周期。以下是标准的执行顺序，涵盖从数据生成到模型部署的全过程。\n\n### 1. 生成 RAG 评估数据集\n\n首先生成用于基准测试的合成问答数据集：\n\n```bash\npoetry run llmops-project confs\u002Fgenerate_rag_dataset.yaml\n```\n\n### 2. 特征工程与向量库构建\n\n创建向量数据库实例并将文档注入为向量：\n\n```bash\npoetry run llmops-project confs\u002Ffeature_eng.yaml\n```\n\n### 3. 模型部署与注册\n\n运行部署流程，该步骤会自动完成以下操作：\n*   使用 Mlflow 注册模型\n*   验证模型输入\u002F输出签名\n*   基于生成的数据集评估模型质量（Factfulness）\n*   若模型通过测试且超过阈值，则提升为 `champion` 或 `production` 版本\n\n```bash\npoetry run llmops-project confs\u002Fdeployment.yaml\n```\n\n### 4. 启动推理服务\n\n使用 Litserve（基于 FastAPI）在本地启动模型服务端点（默认端口 8000）：\n\n```bash\ninv serve\n```\n\n> **注意**：生产环境中，您可参考 `\u002Fserving_endpoint` 目录下的配置，将服务部署至 Docker、Kubernetes 或 AWS Fargate。\n\n### 5. 模型监控（可选）\n\n定期运行监控任务，利用 Mlflow Traces 和 LLM 作为裁判来评估线上表现：\n\n```bash\npoetry run llmops-project confs\u002Fmonitoring.yaml\n```\n\n### 配置文件说明\n\n所有行为均可通过修改 `confs\u002F` 目录下的 YAML 文件进行定制。例如，编辑 `confs\u002Fdeployment.yaml` 可更改模型名称、向量库地址及晋升策略：\n\n```yaml\n# confs\u002Fdeployment.yaml 示例\njob:\n  KIND: DeploymentJob\n  staging_alias: \"champion\"\n  production_alias: \"production\"\n  registry_model_name: \"rag-chatbot-with-guardrails\"\n  vector_store_path: \"http:\u002F\u002Flocalhost:6333\"\n```","某金融科技公司的大模型团队正致力于将实验阶段的客服问答模型转化为可稳定上线的生产级服务，急需解决从代码规范到模型部署的全流程标准化难题。\n\n### 没有 llmops-python-package 时\n- **环境配置混乱**：团队成员各自为政，Python 版本、依赖库管理不一致，导致“在我机器上能跑”的频发问题，复现实验结果极其困难。\n- **代码质量参差不齐**：缺乏统一的格式化（Formatting）和安全扫描机制，代码审查耗时耗力，且容易遗漏潜在的安全漏洞。\n- **模型管理手工化**：模型版本、训练参数和评估指标依靠人工记录或分散的表格，无法与代码提交关联，难以追溯模型效果变化的根本原因。\n- **部署流程繁琐**：从本地开发到容器化部署需手动编写大量脚本，缺乏标准化的 CI\u002FCD 流水线，新模型上线周期长达数周。\n\n### 使用 llmops-python-package 后\n- **开箱即用的标准环境**：内置 Poetry 和 Pyenv 配置，一键统一开发环境与依赖管理，确保所有成员在相同基准下协作，实验复现率提升至 100%。\n- **自动化代码治理**：集成 Ruff、Bandit 和 Pre-Commit 钩子，自动执行代码格式化、类型检查和安全审计，让开发者专注于业务逻辑而非风格争论。\n- **全链路模型追踪**：深度整合 MLflow，自动记录模型版本、超参数及评估指标，实现模型资产的可注册、可追踪和可对比，问题定位从小时级缩短至分钟级。\n- **流水线一键交付**：基于 GitHub Actions 和 Docker 预置了完整的 CI\u002FCD 模板，配合 Litserve 实现服务化封装，将模型从提交代码到生产环境部署的时间压缩至天内。\n\nllmops-python-package 通过提供一套经过验证的最佳实践模板，帮助团队将原本碎片化的大模型工程环节整合为高效、稳健的自动化流水线。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcallmesora_llmops-python-package_49b8ca99.png","callmesora","Pedro Azevedo","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fcallmesora_e5f07d5c.png","Msc. Mechanical Engineer with a major in Computer Vision for Autonomous Driving using Deep Learning. \r\n\r\n",null,"https:\u002F\u002Fgithub.com\u002Fcallmesora",[79,83,87,91,95],{"name":80,"color":81,"percentage":82},"Python","#3572A5",92,{"name":84,"color":85,"percentage":86},"HCL","#844FBA",6.3,{"name":88,"color":89,"percentage":90},"Dockerfile","#384d54",1,{"name":92,"color":93,"percentage":94},"Makefile","#427819",0.4,{"name":96,"color":97,"percentage":94},"Shell","#89e051",894,124,"2026-03-28T19:45:21","MIT",4,"未说明",{"notes":105,"python":106,"dependencies":107},"该项目是一个 LLMOps Python 包模板，主要用于构建和管理 LLM 应用的生命周期（如 RAG 评估、模型注册、监控等）。运行前需配置 LLM 提供商凭证（如 AWS Bedrock、OpenAI 等），通过环境变量设置访问密钥。项目使用 Poetry 进行依赖管理和虚拟环境构建。部署服务时默认使用 Litserve（基于 FastAPI），支持容器化部署（Docker\u002FKubernetes\u002FAWS Lambda）。代码中示例使用了 ChatBedrock，但可替换为 ChatOllama 等其他提供商。",">=3.10",[108,109,110,111,112,113,114,115,116,117],"Poetry>=1.8.2","Mlflow","Litserve","Guardrails AI","Pydantic","OmegaConf","Cloudpathlib","Loguru","Ruff","Pytest",[35,14],"2026-03-27T02:49:30.150509","2026-04-16T08:19:16.751895",[],[123],{"id":124,"version":125,"summary_zh":126,"released_at":127},280208,"v0.2.1","## 初始发布\r\nLLMOps 包模板初始版本，包含模型注册表和解耦部署","2024-12-10T19:33:38"]