[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-dottxt-ai--outlines":3,"tool-dottxt-ai--outlines":64},[4,17,25,39,48,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},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 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,14,15],"开发框架","Agent","语言模型","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":10,"last_commit_at":23,"category_tags":24,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,15],{"id":26,"name":27,"github_repo":28,"description_zh":29,"stars":30,"difficulty_score":10,"last_commit_at":31,"category_tags":32,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[33,34,35,36,14,37,15,13,38],"图像","数据工具","视频","插件","其他","音频",{"id":40,"name":41,"github_repo":42,"description_zh":43,"stars":44,"difficulty_score":45,"last_commit_at":46,"category_tags":47,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,3,"2026-04-04T04:44:48",[14,33,13,15,37],{"id":49,"name":50,"github_repo":51,"description_zh":52,"stars":53,"difficulty_score":45,"last_commit_at":54,"category_tags":55,"status":16},519,"PaddleOCR","PaddlePaddle\u002FPaddleOCR","PaddleOCR 是一款基于百度飞桨框架开发的高性能开源光学字符识别工具包。它的核心能力是将图片、PDF 等文档中的文字提取出来，转换成计算机可读取的结构化数据，让机器真正“看懂”图文内容。\n\n面对海量纸质或电子文档，PaddleOCR 解决了人工录入效率低、数字化成本高的问题。尤其在人工智能领域，它扮演着连接图像与大型语言模型（LLM）的桥梁角色，能将视觉信息直接转化为文本输入，助力智能问答、文档分析等应用场景落地。\n\nPaddleOCR 适合开发者、算法研究人员以及有文档自动化需求的普通用户。其技术优势十分明显：不仅支持全球 100 多种语言的识别，还能在 Windows、Linux、macOS 等多个系统上运行，并灵活适配 CPU、GPU、NPU 等各类硬件。作为一个轻量级且社区活跃的开源项目，PaddleOCR 既能满足快速集成的需求，也能支撑前沿的视觉语言研究，是处理文字识别任务的理想选择。",74913,"2026-04-05T10:44:17",[15,33,13,37],{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":45,"last_commit_at":62,"category_tags":63,"status":16},2181,"OpenHands","OpenHands\u002FOpenHands","OpenHands 是一个专注于 AI 驱动开发的开源平台，旨在让智能体（Agent）像人类开发者一样理解、编写和调试代码。它解决了传统编程中重复性劳动多、环境配置复杂以及人机协作效率低等痛点，通过自动化流程显著提升开发速度。\n\n无论是希望提升编码效率的软件工程师、探索智能体技术的研究人员，还是需要快速原型验证的技术团队，都能从中受益。OpenHands 提供了灵活多样的使用方式：既可以通过命令行（CLI）或本地图形界面在个人电脑上轻松上手，体验类似 Devin 的流畅交互；也能利用其强大的 Python SDK 自定义智能体逻辑，甚至在云端大规模部署上千个智能体并行工作。\n\n其核心技术亮点在于模块化的软件智能体 SDK，这不仅构成了平台的引擎，还支持高度可组合的开发模式。此外，OpenHands 在 SWE-bench 基准测试中取得了 77.6% 的优异成绩，证明了其解决真实世界软件工程问题的能力。平台还具备完善的企业级功能，支持与 Slack、Jira 等工具集成，并提供细粒度的权限管理，适合从个人开发者到大型企业的各类用户场景。",70612,"2026-04-05T11:12:22",[15,14,13,36],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":80,"owner_twitter":81,"owner_website":82,"owner_url":83,"languages":84,"stars":93,"forks":94,"last_commit_at":95,"license":96,"difficulty_score":45,"env_os":97,"env_gpu":98,"env_ram":98,"env_deps":99,"category_tags":107,"github_topics":108,"view_count":45,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":117,"updated_at":118,"faqs":119,"releases":148},1185,"dottxt-ai\u002Foutlines","outlines","Structured Outputs","Outlines 是一个帮助开发者让大语言模型生成结构化数据的工具。它解决了传统方法中生成结果不可控、需要后期处理的问题，通过在生成过程中直接确保输出符合预设格式，避免了解析错误和格式混乱。适合开发者和研究人员使用，尤其在需要精准数据提取或分类的场景中非常实用。其核心亮点是支持多种模型，并能通过简单类型声明实现结构化输出，提升开发效率。","\u003Cdiv align=\"center\" style=\"margin-bottom: 1em;\">\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_72d2e33fb7a9.png\" alt=\"Outlines Logo\" width=300>\u003C\u002Fimg>\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_99d9e491ee45.png\" alt=\"Outlines Logo\" width=300>\u003C\u002Fimg>\n\n\n 🗒️ *Structured outputs for LLMs* 🗒️\n\nMade with ❤👷️ by the team at [.txt](https:\u002F\u002Fdottxt.co)\n\u003Cbr>Trusted by NVIDIA, Cohere, HuggingFace, vLLM, etc.\n\n\u003C!-- Project Badges -->\n[![PyPI Version][pypi-version-badge]][pypi]\n[![Downloads][downloads-badge]][pypistats]\n[![Stars][stars-badge]][stars]\n\n\u003C!-- Community Badges -->\n[![Discord][discord-badge]][discord]\n[![Blog][dottxt-blog-badge]][dottxt-blog]\n[![Twitter][twitter-badge]][twitter]\n\n\u003C\u002Fdiv>\n\n## 🚀 Building the future of structured generation\n\nWe're working with select partners to develop new interfaces to structured generation.\n\nNeed XML, FHIR, custom schemas or grammars? Let's talk.\n\nAudit your schema: share one schema, we show you what breaks under generation, the constraints that fix it, and compliance rates before and after. Sign up [here](https:\u002F\u002Fh1xbpbfsf0w.typeform.com\u002Fto\u002FrtFUraA2?typeform).\n\n## Table of Contents\n\n- [Why Outlines?](#why-outlines)\n- [Quickstart](#quickstart)\n- [Real-World Examples](#real-world-examples)\n  - [🙋‍♂️ Customer Support Triage](#customer-support-triage)\n  - [📦 E-commerce Product Categorization](#e-commerce-product-categorization)\n  - [📊 Parse Event Details with Incomplete Data](#parse-event-details-with-incomplete-data)\n  - [🗂️ Categorize Documents into Predefined Types](#categorize-documents-into-predefined-types)\n  - [📅 Schedule a Meeting with Function Calling](#schedule-a-meeting-with-function-calling)\n  - [📝 Dynamically Generate Prompts with Re-usable Templates](#dynamically-generate-prompts-with-re-usable-templates)\n- [They Use Outlines](#they-use-outlines)\n- [Model Integrations](#model-integrations)\n- [Core Features](#core-features)\n- [Other Features](#other-features)\n- [About .txt](#about-txt)\n- [Community](#community)\n\n\u003Cdiv align=\"center\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_a3b3988ac2b8.png\" width=300>\u003C\u002Fimg>\u003C\u002Fdiv>\n\n## Why Outlines?\n\nLLMs are powerful but their outputs are unpredictable. Most solutions attempt to fix bad outputs after generation using parsing, regex, or fragile code that breaks easily.\n\nOutlines guarantees structured outputs during generation — directly from any LLM.\n\n- **Works with any model** - Same code runs across OpenAI, Ollama, vLLM, and more\n- **Simple integration** - Just pass your desired output type: `model(prompt, output_type)`\n- **Guaranteed valid structure** - No more parsing headaches or broken JSON\n- **Provider independence** - Switch models without changing code\n\n\n### The Outlines Philosophy\n\n\u003Cdiv align=\"center\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_5590864468e4.png\" width=300>\u003C\u002Fimg>\u003C\u002Fdiv>\n\nOutlines follows a simple pattern that mirrors Python's own type system. Simply specify the desired output type, and Outlines will ensure your data matches that structure exactly:\n\n- For a yes\u002Fno response, use `Literal[\"Yes\", \"No\"]`\n- For numerical values, use `int`\n- For complex objects, define a structure with a [Pydantic model](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002F)\n\n## Quickstart\n\nGetting started with outlines is simple:\n\n### 1. Install outlines\n\n``` shell\npip install outlines\n```\n\n### 2. Connect to your preferred model\n\n``` python\nimport outlines\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n```\n\n### 3. Start with simple structured outputs\n\n``` python\nfrom typing import Literal\nfrom pydantic import BaseModel\n\n\n# Simple classification\nsentiment = model(\n    \"Analyze: 'This product completely changed my life!'\",\n    Literal[\"Positive\", \"Negative\", \"Neutral\"]\n)\nprint(sentiment)  # \"Positive\"\n\n# Extract specific types\ntemperature = model(\"What's the boiling point of water in Celsius?\", int)\nprint(temperature)  # 100\n```\n\n### 4. Create complex structures\n\n``` python\nfrom pydantic import BaseModel\nfrom enum import Enum\n\nclass Rating(Enum):\n    poor = 1\n    fair = 2\n    good = 3\n    excellent = 4\n\nclass ProductReview(BaseModel):\n    rating: Rating\n    pros: list[str]\n    cons: list[str]\n    summary: str\n\nreview = model(\n    \"Review: The XPS 13 has great battery life and a stunning display, but it runs hot and the webcam is poor quality.\",\n    ProductReview,\n    max_new_tokens=200,\n)\n\nreview = ProductReview.model_validate_json(review)\nprint(f\"Rating: {review.rating.name}\")  # \"Rating: good\"\nprint(f\"Pros: {review.pros}\")           # \"Pros: ['great battery life', 'stunning display']\"\nprint(f\"Summary: {review.summary}\")     # \"Summary: Good laptop with great display but thermal issues\"\n```\n\n## Real-world examples\n\nHere are production-ready examples showing how Outlines solves common problems:\n\n\u003Cdetails id=\"customer-support-triage\">\u003Csummary>\u003Cb>🙋‍♂️ Customer Support Triage\u003C\u002Fb>\n\u003Cbr>This example shows how to convert a free-form customer email into a structured service ticket. By parsing attributes like priority, category, and escalation flags, the code enables automated routing and handling of support issues.\n\u003C\u002Fsummary>\n\n``` python\nimport outlines\nfrom enum import Enum\nfrom pydantic import BaseModel\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\nfrom typing import List\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\ndef alert_manager(ticket):\n    print(\"Alert!\", ticket)\n\n\nclass TicketPriority(str, Enum):\n    low = \"low\"\n    medium = \"medium\"\n    high = \"high\"\n    urgent = \"urgent\"\n\nclass ServiceTicket(BaseModel):\n    priority: TicketPriority\n    category: str\n    requires_manager: bool\n    summary: str\n    action_items: List[str]\n\n\ncustomer_email = \"\"\"\nSubject: URGENT - Cannot access my account after payment\n\nI paid for the premium plan 3 hours ago and still can't access any features.\nI've tried logging out and back in multiple times. This is unacceptable as I\nhave a client presentation in an hour and need the analytics dashboard.\nPlease fix this immediately or refund my payment.\n\"\"\"\n\nprompt = f\"\"\"\n\u003C|im_start|>user\nAnalyze this customer email:\n\n{customer_email}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\"\n\nticket = model(\n    prompt,\n    ServiceTicket,\n    max_new_tokens=500\n)\n\n# Use structured data to route the ticket\nticket = ServiceTicket.model_validate_json(ticket)\nif ticket.priority == \"urgent\" or ticket.requires_manager:\n    alert_manager(ticket)\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails id=\"e-commerce-product-categorization\">\u003Csummary>\u003Cb>📦 E-commerce product categorization\u003C\u002Fb>\n\u003Cbr>This use case demonstrates how outlines can transform product descriptions into structured categorization data (e.g., main category, sub-category, and attributes) to streamline tasks such as inventory management. Each product description is processed automatically, reducing manual categorization overhead.\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom pydantic import BaseModel\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\nfrom typing import List, Optional\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\ndef update_inventory(product, category, sub_category):\n    print(f\"Updated {product.split(',')[0]} in category {category}\u002F{sub_category}\")\n\n\nclass ProductCategory(BaseModel):\n    main_category: str\n    sub_category: str\n    attributes: List[str]\n    brand_match: Optional[str]\n\n# Process product descriptions in batches\nproduct_descriptions = [\n    \"Apple iPhone 15 Pro Max 256GB Titanium, 6.7-inch Super Retina XDR display with ProMotion\",\n    \"Organic Cotton T-Shirt, Men's Medium, Navy Blue, 100% Sustainable Materials\",\n    \"KitchenAid Stand Mixer, 5 Quart, Red, 10-Speed Settings with Dough Hook Attachment\"\n]\n\ntemplate = outlines.Template.from_string(\"\"\"\n\u003C|im_start|>user\nCategorize this product:\n\n{{ description }}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\")\n\n# Get structured categorization for all products\ncategories = model(\n    [template(description=desc) for desc in product_descriptions],\n    ProductCategory,\n    max_new_tokens=200\n)\n\n# Use categorization for inventory management\ncategories = [\n    ProductCategory.model_validate_json(category) for category in categories\n]\nfor product, category in zip(product_descriptions, categories):\n    update_inventory(product, category.main_category, category.sub_category)\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails id=\"parse-event-details-with-incomplete-data\">\u003Csummary>\u003Cb>📊 Parse event details with incomplete data\u003C\u002Fb>\n\u003Cbr>This example uses outlines to parse event descriptions into structured information (like event name, date, location, type, and topics), even handling cases where the data is incomplete. It leverages union types to return either structured event data or a fallback “I don’t know” answer, ensuring robust extraction in varying scenarios.\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom typing import Union, List, Literal\nfrom pydantic import BaseModel\nfrom enum import Enum\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\nclass EventType(str, Enum):\n    conference = \"conference\"\n    webinar = \"webinar\"\n    workshop = \"workshop\"\n    meetup = \"meetup\"\n    other = \"other\"\n\n\nclass EventInfo(BaseModel):\n    \"\"\"Structured information about a tech event\"\"\"\n    name: str\n    date: str\n    location: str\n    event_type: EventType\n    topics: List[str]\n    registration_required: bool\n\n# Create a union type that can either be a structured EventInfo or \"I don't know\"\nEventResponse = Union[EventInfo, Literal[\"I don't know\"]]\n\n# Sample event descriptions\nevent_descriptions = [\n    # Complete information\n    \"\"\"\n    Join us for DevCon 2023, the premier developer conference happening on November 15-17, 2023\n    at the San Francisco Convention Center. Topics include AI\u002FML, cloud infrastructure, and web3.\n    Registration is required.\n    \"\"\",\n\n    # Insufficient information\n    \"\"\"\n    Tech event next week. More details coming soon!\n    \"\"\"\n]\n\n# Process events\nresults = []\nfor description in event_descriptions:\n    prompt = f\"\"\"\n\u003C|im_start>system\nYou are a helpful assistant\n\u003C|im_end|>\n\u003C|im_start>user\nExtract structured information about this tech event:\n\n{description}\n\nIf there is enough information, return a JSON object with the following fields:\n\n- name: The name of the event\n- date: The date where the event is taking place\n- location: Where the event is taking place\n- event_type: either 'conference', 'webinar', 'workshop', 'meetup' or 'other'\n- topics: a list of topics of the conference\n- registration_required: a boolean that indicates whether registration is required\n\nIf the information available does not allow you to fill this JSON, and only then, answer 'I don't know'.\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\"\n    # Union type allows the model to return structured data or \"I don't know\"\n    result = model(prompt, EventResponse, max_new_tokens=200)\n    results.append(result)\n\n# Display results\nfor i, result in enumerate(results):\n    print(f\"Event {i+1}:\")\n    if isinstance(result, str):\n        print(f\"  {result}\")\n    else:\n        # It's an EventInfo object\n        print(f\"  Name: {result.name}\")\n        print(f\"  Type: {result.event_type}\")\n        print(f\"  Date: {result.date}\")\n        print(f\"  Topics: {', '.join(result.topics)}\")\n    print()\n\n# Use structured data in downstream processing\nstructured_count = sum(1 for r in results if isinstance(r, EventInfo))\nprint(f\"Successfully extracted data for {structured_count} of {len(results)} events\")\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails id=\"categorize-documents-into-predefined-types\">\u003Csummary>\u003Cb>🗂️ Categorize documents into predefined types\u003C\u002Fb>\n\u003Cbr>In this case, outlines classifies documents into predefined categories (e.g., “Financial Report,” “Legal Contract”) using a literal type specification. The resulting classifications are displayed in both a table format and through a category distribution summary, illustrating how structured outputs can simplify content management.\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom typing import Literal, List\nimport pandas as pd\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\n# Define classification categories using Literal\nDocumentCategory = Literal[\n    \"Financial Report\",\n    \"Legal Contract\",\n    \"Technical Documentation\",\n    \"Marketing Material\",\n    \"Personal Correspondence\"\n]\n\n# Sample documents to classify\ndocuments = [\n    \"Q3 Financial Summary: Revenue increased by 15% year-over-year to $12.4M. EBITDA margin improved to 23% compared to 19% in Q3 last year. Operating expenses...\",\n\n    \"This agreement is made between Party A and Party B, hereinafter referred to as 'the Parties', on this day of...\",\n\n    \"The API accepts POST requests with JSON payloads. Required parameters include 'user_id' and 'transaction_type'. The endpoint returns a 200 status code on success.\"\n]\n\ntemplate = outlines.Template.from_string(\"\"\"\n\u003C|im_start|>user\nClassify the following document into exactly one category among the following categories:\n- Financial Report\n- Legal Contract\n- Technical Documentation\n- Marketing Material\n- Personal Correspondence\n\nDocument:\n{{ document }}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\")\n\n# Classify documents\ndef classify_documents(texts: List[str]) -> List[DocumentCategory]:\n    results = []\n\n    for text in texts:\n        prompt = template(document=text)\n        # The model must return one of the predefined categories\n        category = model(prompt, DocumentCategory, max_new_tokens=200)\n        results.append(category)\n\n    return results\n\n# Perform classification\nclassifications = classify_documents(documents)\n\n# Create a simple results table\nresults_df = pd.DataFrame({\n    \"Document\": [doc[:50] + \"...\" for doc in documents],\n    \"Classification\": classifications\n})\n\nprint(results_df)\n\n# Count documents by category\ncategory_counts = pd.Series(classifications).value_counts()\nprint(\"\\nCategory Distribution:\")\nprint(category_counts)\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary id=\"schedule-a-meeting-with-function-calling\">\u003Cb>📅 Schedule a meeting from requests with Function Calling\u003C\u002Fb>\n\u003Cbr>This example demonstrates how outlines can interpret a natural language meeting request and translate it into a structured format matching a predefined function’s parameters. Once the meeting details are extracted (e.g., title, date, duration, attendees), they are used to automatically schedule the meeting.\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nimport json\nfrom typing import List, Optional\nfrom datetime import date\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002Fphi-4\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\n# Define a function with typed parameters\ndef schedule_meeting(\n    title: str,\n    date: date,\n    duration_minutes: int,\n    attendees: List[str],\n    location: Optional[str] = None,\n    agenda_items: Optional[List[str]] = None\n):\n    \"\"\"Schedule a meeting with the specified details\"\"\"\n    # In a real app, this would create the meeting\n    meeting = {\n        \"title\": title,\n        \"date\": date,\n        \"duration_minutes\": duration_minutes,\n        \"attendees\": attendees,\n        \"location\": location,\n        \"agenda_items\": agenda_items\n    }\n    return f\"Meeting '{title}' scheduled for {date} with {len(attendees)} attendees\"\n\n# Natural language request\nuser_request = \"\"\"\nI need to set up a product roadmap review with the engineering team for next\nTuesday at 2pm. It should last 90 minutes. Please invite john@example.com,\nsarah@example.com, and the product team at product@example.com.\n\"\"\"\n\n# Outlines automatically infers the required structure from the function signature\nprompt = f\"\"\"\n\u003C|im_start|>user\nExtract the meeting details from this request:\n\n{user_request}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\"\nmeeting_params = model(prompt, schedule_meeting, max_new_tokens=200)\n\n# The result is a dictionary matching the function parameters\nmeeting_params = json.loads(meeting_params)\nprint(meeting_params)\n\n# Call the function with the extracted parameters\nresult = schedule_meeting(**meeting_params)\nprint(result)\n# \"Meeting 'Product Roadmap Review' scheduled for 2023-10-17 with 3 attendees\"\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary id=\"dynamically-generate-prompts-with-re-usable-templates\">\u003Cb>📝 Dynamically generate prompts with re-usable templates\u003C\u002Fb>\n\u003Cbr>Using Jinja-based templates, this example shows how to generate dynamic prompts for tasks like sentiment analysis. It illustrates how to easily re-use and customize prompts—including few-shot learning strategies—for different content types while ensuring the outputs remain structured.\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom typing import List, Literal\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002Fphi-4\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\n# 1. Create a reusable template with Jinja syntax\nsentiment_template = outlines.Template.from_string(\"\"\"\n\u003C|im_start>user\nAnalyze the sentiment of the following {{ content_type }}:\n\n{{ text }}\n\nProvide your analysis as either \"Positive\", \"Negative\", or \"Neutral\".\n\u003C|im_end>\n\u003C|im_start>assistant\n\"\"\")\n\n# 2. Generate prompts with different parameters\nreview = \"This restaurant exceeded all my expectations. Fantastic service!\"\nprompt = sentiment_template(content_type=\"review\", text=review)\n\n# 3. Use the templated prompt with structured generation\nresult = model(prompt, Literal[\"Positive\", \"Negative\", \"Neutral\"])\nprint(result)  # \"Positive\"\n\n# Templates can also be loaded from files\nexample_template = outlines.Template.from_file(\"templates\u002Ffew_shot.txt\")\n\n# Use with examples for few-shot learning\nexamples = [\n    (\"The food was cold\", \"Negative\"),\n    (\"The staff was friendly\", \"Positive\")\n]\nfew_shot_prompt = example_template(examples=examples, query=\"Service was slow\")\nprint(few_shot_prompt)\n```\n\u003C\u002Fdetails>\n\n## They use outlines\n\n\u003Cdiv align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_5611259f6ff7.png\" alt=\"Users Logo\">\u003C\u002Fimg>\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_bd1ef7b4ab09.png\" alt=\"Users Logo\">\u003C\u002Fimg>\n\u003C\u002Fdiv>\n\n## Model Integrations\n\n| Model type | Description | Documentation |\n|---------|-------------|:-------------:|\n| **Server Support** | vLLM and Ollama | [Server Integrations →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002F) |\n| **Local Model Support** | transformers and llama.cpp | [Model Integrations →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002F) |\n| **API Support** | OpenAI and Gemini | [API Integrations →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002F) |\n\n## Core Features\n\n| Feature | Description | Documentation |\n|---------|-------------|:-------------:|\n| **Multiple Choices** | Constrain outputs to predefined options | [Multiple Choices Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#multiple-choices) |\n| **Function Calls** | Infer structure from function signatures | [Function Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#json-schemas) |\n| **JSON\u002FPydantic** | Generate outputs matching JSON schemas | [JSON Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#json-schemas) |\n| **Regular Expressions** | Generate text following a regex pattern | [Regex Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#regex-patterns) |\n| **Grammars** | Enforce complex output structures | [Grammar Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#context-free-grammars) |\n\n## Other Features\n\n| Feature | Description | Documentation |\n|---------|-------------|:-------------:|\n| **Prompt templates** | Separate complex prompts from code | [Template Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Futility\u002Ftemplate\u002F) |\n| **Custome types** | Intuitive interface to build complex types | [Python Types Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#basic-python-types) |\n| **Applications** | Encapsulate templates and types into functions | [Application Guide →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Futility\u002Fapplication\u002F) |\n\n## About .txt\n\n\u003Cdiv align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_03dac4339ec7.png\" alt=\"dottxt logo\" width=100>\u003C\u002Fimg>\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_4a98fcb999f9.png\" alt=\"dottxt logo\" width=100>\u003C\u002Fimg>\n\u003C\u002Fdiv>\n\nOutlines is developed and maintained by [.txt](https:\u002F\u002Fdottxt.co), a company dedicated to making LLMs more reliable for production applications.\n\nOur focus is on advancing structured generation technology through:\n\n- 🧪 **Cutting-edge Research**: We publish our findings on [structured generation](http:\u002F\u002Fblog.dottxt.co\u002Fperformance-gsm8k.html)\n- 🚀 **Enterprise-grade solutions**: You can license [our enterprise-grade libraries](https:\u002F\u002Fdocs.dottxt.co).\n- 🧩 **Open Source Collaboration**: We believe in building in public and contributing to the community\n\nFollow us on [Twitter](https:\u002F\u002Ftwitter.com\u002Fdottxtai) or check out our [blog](https:\u002F\u002Fblog.dottxt.co\u002F) to stay updated on our latest work in making LLMs more reliable.\n\n## Community\n\n\u003Cdiv align=\"center\" style=\"margin-bottom: 1em;\">\n\n[![Contributors][contributors-badge]][contributors]\n[![Stars][stars-badge]][stars]\n[![Downloads][downloads-badge]][pypistats]\n[![Discord badge][discord-badge]][discord]\n\n\u003C\u002Fdiv>\n\n- 💡 **Have an idea?** Come chat with us on [Discord][discord]\n- 🐞 **Found a bug?** Open an [issue](https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fissues)\n- 🧩  **Want to contribute?** Consult our [contribution guide](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Fcommunity\u002Fcontribute\u002F).\n\n\n## Cite Outlines\n\n```\n@article{willard2023efficient,\n  title={Efficient Guided Generation for Large Language Models},\n  author={Willard, Brandon T and Louf, R{\\'e}mi},\n  journal={arXiv preprint arXiv:2307.09702},\n  year={2023}\n}\n```\n\n[contributors]: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fgraphs\u002Fcontributors\n[contributors-badge]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fcontributors\u002Fdottxt-ai\u002Foutlines?style=flat-square&logo=github&logoColor=white&color=ECEFF4\n[dottxt-blog]: https:\u002F\u002Fblog.dottxt.co\u002F\n[dottxt-blog-badge]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdottxt%20blog-a6b4a3\n[dottxt-twitter]: https:\u002F\u002Ftwitter.com\u002Fdottxtai\n[dottxt-twitter-badge]: https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fdottxtai?style=social\n[discord]: https:\u002F\u002Fdiscord.gg\u002FR9DSu34mGd\n[discord-badge]: https:\u002F\u002Fimg.shields.io\u002Fdiscord\u002F1182316225284554793?color=ddb8ca&logo=discord&logoColor=white&style=flat-square\n[downloads-badge]: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fdm\u002Foutlines?color=A6B4A3&logo=python&logoColor=white&style=flat-square\n[pypistats]: https:\u002F\u002Fpypistats.org\u002Fpackages\u002Foutlines\n[pypi-version-badge]: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Foutlines?style=flat-square&logoColor=white&color=ddb8ca\n[pypi]: https:\u002F\u002Fpypi.org\u002Fproject\u002Foutlines\u002F\n[stars]: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fstargazers\n[stars-badge]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fdottxt-ai\u002Foutlines?style=flat-square&logo=github&color=BD932F&logoColor=white\n[twitter-badge]: https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fdottxtai?style=flat-square&logo=x&logoColor=white&color=bd932f\n[twitter]: https:\u002F\u002Fx.com\u002Fdottxtai\n","\u003Cdiv align=\"center\" style=\"margin-bottom: 1em;\">\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_72d2e33fb7a9.png\" alt=\"Outlines Logo\" width=300>\u003C\u002Fimg>\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_99d9e491ee45.png\" alt=\"Outlines Logo\" width=300>\u003C\u002Fimg>\n\n\n 🗒️ *面向大语言模型的结构化输出* 🗒️\n\n由 [.txt](https:\u002F\u002Fdottxt.co) 团队用心打造 ❤👷️\n\u003Cbr>深受 NVIDIA、Cohere、HuggingFace、vLLM 等信赖。\n\n\u003C!-- 项目徽章 -->\n[![PyPI 版本][pypi-version-badge]][pypi]\n[![下载量][downloads-badge]][pypistats]\n[![星标][stars-badge]][stars]\n\n\u003C!-- 社区徽章 -->\n[![Discord][discord-badge]][discord]\n[![博客][dottxt-blog-badge]][dottxt-blog]\n[![Twitter][twitter-badge]][twitter]\n\n\u003C\u002Fdiv>\n\n## 🚀 构建结构化生成的未来\n\n我们正与精选合作伙伴携手，开发结构化生成的新接口。\n\n需要 XML、FHIR、自定义模式或语法吗？欢迎联系我们。\n\n进行模式审计：只需分享一个模式，我们会展示在生成过程中哪些部分会出错、如何通过约束修复这些问题，以及修复前后的合规率。请在此处报名 [here](https:\u002F\u002Fh1xbpbfsf0w.typeform.com\u002Fto\u002FrtFUraA2?typeform)。\n\n## 目录\n\n- [为什么选择 Outlines？](#why-outlines)\n- [快速入门](#quickstart)\n- [真实场景示例](#real-world-examples)\n  - [🙋‍♂️ 客服工单分类](#customer-support-triage)\n  - [📦 电商商品分类](#e-commerce-product-categorization)\n  - [📊 解析不完整数据中的事件详情](#parse-event-details-with-incomplete-data)\n  - [🗂️ 将文档归类为预定义类型](#categorize-documents-into-predefined-types)\n  - [📅 使用函数调用安排会议](#schedule-a-meeting-with-function-calling)\n  - [📝 动态生成可复用模板的提示](#dynamically-generate-prompts-with-re-usable-templates)\n- [使用 Outlines 的客户](#they-use-outlines)\n- [模型集成](#model-integrations)\n- [核心功能](#core-features)\n- [其他功能](#other-features)\n- [关于 .txt](#about-txt)\n- [社区](#community)\n\n\u003Cdiv align=\"center\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_a3b3988ac2b8.png\" width=300>\u003C\u002Fimg>\u003C\u002Fdiv>\n\n## 为什么选择 Outlines？\n\n大语言模型功能强大，但其输出往往难以预测。大多数解决方案试图在生成后通过解析、正则表达式或易失效的代码来修复不良输出。\n\n而 Outlines 能够在生成过程中直接保证结构化输出——无论使用哪种大语言模型。\n\n- **兼容任何模型**：同一段代码可在 OpenAI、Ollama、vLLM 等多种模型上运行。\n- **集成简单**：只需传入期望的输出类型：`model(prompt, output_type)`。\n- **结构绝对有效**：不再有解析难题或 JSON 格式错误。\n- **不受供应商限制**：无需更改代码即可切换模型。\n\n\n### Outlines 的理念\n\n\u003Cdiv align=\"center\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_5590864468e4.png\" width=300>\u003C\u002Fimg>\u003C\u002Fdiv>\n\nOutlines 遵循一种简洁的模式，类似于 Python 自身的类型系统。只需指定所需的输出类型，Outlines 就会确保你的数据完全符合该结构：\n\n- 对于“是\u002F否”回答，使用 `Literal[\"Yes\", \"No\"]`。\n- 对于数值，使用 `int`。\n- 对于复杂对象，则使用 [Pydantic 模型](https:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002F) 定义结构。\n\n## 快速入门\n\n开始使用 Outlines 非常简单：\n\n### 1. 安装 Outlines\n\n``` shell\npip install outlines\n```\n\n### 2. 连接至您首选的模型\n\n``` python\nimport outlines\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n```\n\n### 3. 从简单的结构化输出入手\n\n``` python\nfrom typing import Literal\nfrom pydantic import BaseModel\n\n\n# 简单分类\nsentiment = model(\n    \"分析：‘这款产品彻底改变了我的生活！’\",\n    Literal[\"Positive\", \"Negative\", \"Neutral\"]\n)\nprint(sentiment)  # \"Positive\"\n\n# 提取特定类型\ntemperature = model(\"水的沸点是多少摄氏度？\", int)\nprint(temperature)  # 100\n```\n\n### 4. 创建复杂结构\n\n``` python\nfrom pydantic import BaseModel\nfrom enum import Enum\n\nclass Rating(Enum):\n    poor = 1\n    fair = 2\n    good = 3\n    excellent = 4\n\nclass ProductReview(BaseModel):\n    rating: Rating\n    pros: list[str]\n    cons: list[str]\n    summary: str\n\nreview = model(\n    \"评价：XPS 13 的电池续航出色，显示屏惊艳，但机身发热严重，摄像头质量较差。\",\n    ProductReview,\n    max_new_tokens=200,\n)\n\nreview = ProductReview.model_validate_json(review)\nprint(f\"评分：{review.rating.name}\")  # \"评分：good\"\nprint(f\"优点：{review.pros}\")           # \"优点：['出色的电池续航', '惊艳的显示屏']\"\nprint(f\"总结：{review.summary}\")     # \"总结：一款显示效果优秀但散热问题明显的笔记本电脑\"\n```\n\n## 真实场景示例\n\n以下是一些可用于生产的示例，展示了 Outlines 如何解决常见问题：\n\n\u003Cdetails id=\"customer-support-triage\">\u003Csummary>\u003Cb>🙋‍♂️ 客服工单分类\u003C\u002Fb>\n\u003Cbr>此示例演示如何将自由格式的客户邮件转换为结构化的服务工单。通过解析优先级、类别和升级标志等属性，代码能够实现支持问题的自动化路由和处理。\n\u003C\u002Fsummary>\n\n``` python\nimport outlines\nfrom enum import Enum\nfrom pydantic import BaseModel\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\nfrom typing import List\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\ndef alert_manager(ticket):\n    print(\"警报！\", ticket)\n\n\nclass TicketPriority(str, Enum):\n    low = \"low\"\n    medium = \"medium\"\n    high = \"high\"\n    urgent = \"urgent\"\n\nclass ServiceTicket(BaseModel):\n    priority: TicketPriority\n    category: str\n    requires_manager: bool\n    summary: str\n    action_items: List[str]\n\n\ncustomer_email = \"\"\"\n主题：紧急 — 支付后仍无法访问账户\n\n我3小时前支付了高级套餐费用，但至今仍无法使用任何功能。我已经多次尝试退出并重新登录，但这仍然无效。这种情况实在无法接受，因为我还有一个小时就要为客户做演示，急需使用分析仪表盘。请立即解决问题，否则请退还我的款项。\n\"\"\"\n\nprompt = f\"\"\"\n\u003C|im_start|>user\n请分析这封客户邮件：\n\n{customer_email}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\"\n\nticket = model(\n    prompt,\n    ServiceTicket,\n    max_new_tokens=500\n)\n\n# 使用结构化数据路由工单\nticket = ServiceTicket.model_validate_json(ticket)\nif ticket.priority == \"urgent\" or ticket.requires_manager:\n    alert_manager(ticket)\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails id=\"e-commerce-product-categorization\">\u003Csummary>\u003Cb>📦 电商产品分类\u003C\u002Fb>\n\u003Cbr>此用例展示了 outlines 如何将产品描述转换为结构化的分类数据（例如主类目、子类目和属性），从而简化库存管理等任务。每个产品描述都会自动处理，减少手动分类的开销。\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom pydantic import BaseModel\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\nfrom typing import List, Optional\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\ndef update_inventory(product, category, sub_category):\n    print(f\"已更新 {product.split(',')[0]}，归入 {category}\u002F{sub_category} 类别\")\n\n\nclass ProductCategory(BaseModel):\n    main_category: str\n    sub_category: str\n    attributes: List[str]\n    brand_match: Optional[str]\n\n# 批量处理产品描述\nproduct_descriptions = [\n    \"苹果 iPhone 15 Pro Max 256GB 钛金属款，6.7 英寸 Super Retina XDR 显示屏，支持 ProMotion 技术\",\n    \"有机棉 T 恤，男士中码，海军蓝，100% 可持续材料\",\n    \"KitchenAid 立式搅拌机，5 夸脱容量，红色，10 档速度调节，带揉面钩附件\"\n]\n\ntemplate = outlines.Template.from_string(\"\"\"\n\u003C|im_start|>user\n请对以下产品进行分类：\n\n{{ description }}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\")\n\n# 获取所有产品的结构化分类\ncategories = model(\n    [template(description=desc) for desc in product_descriptions],\n    ProductCategory,\n    max_new_tokens=200\n)\n\n# 使用分类结果进行库存管理\ncategories = [\n    ProductCategory.model_validate_json(category) for category in categories\n]\nfor product, category in zip(product_descriptions, categories):\n    update_inventory(product, category.main_category, category.sub_category)\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails id=\"parse-event-details-with-incomplete-data\">\u003Csummary>\u003Cb>📊 解析不完整数据的活动详情\u003C\u002Fb>\n\u003Cbr>本示例使用 outlines 将活动描述解析为结构化信息（如活动名称、日期、地点、类型和主题），即使数据不完整也能处理。它利用联合类型返回结构化的活动信息或“我不知道”的默认答案，确保在不同场景下都能稳健地提取信息。\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom typing import Union, List, Literal\nfrom pydantic import BaseModel\nfrom enum import Enum\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\nclass EventType(str, Enum):\n    conference = \"conference\"\n    webinar = \"webinar\"\n    workshop = \"workshop\"\n    meetup = \"meetup\"\n    other = \"other\"\n\n\nclass EventInfo(BaseModel):\n    \"\"\"关于科技活动的结构化信息\"\"\"\n    name: str\n    date: str\n    location: str\n    event_type: EventType\n    topics: List[str]\n    registration_required: bool\n\n# 创建一个联合类型，可以是结构化的 EventInfo 或者 “我不知道”\nEventResponse = Union[EventInfo, Literal[\"我不知道\"]]\n\n# 示例活动描述\nevent_descriptions = [\n    # 完整信息\n    \"\"\"\n    欢迎参加 2023 年 DevCon 开发者大会，本次顶级开发者会议将于 2023 年 11 月 15 日至 17 日在旧金山会议中心举行。会议主题包括人工智能\u002F机器学习、云基础设施和 Web3。需提前注册。\n    \"\"\",\n\n    # 信息不足\n    \"\"\"\n    下周将举办一场科技活动，更多详情即将公布！\n    \"\"\"\n]\n\n# 处理活动\nresults = []\nfor description in event_descriptions:\n    prompt = f\"\"\"\n\u003C|im_start>system\n您是一位乐于助人的助手\n\u003C|im_end|>\n\u003C|im_start>user\n请提取以下科技活动的结构化信息：\n\n{description}\n\n如果信息足够完整，请返回包含以下字段的 JSON 对象：\n\n- name：活动名称\n- date：活动日期\n- location：活动地点\n- event_type：活动类型，可选值为 'conference'、'webinar'、'workshop'、'meetup' 或 'other'\n- topics：会议主题列表\n- registration_required：是否需要注册\n\n如果现有信息不足以填写上述 JSON，且仅在此情况下，请回答 '我不知道'。\n\u003C|im_end|>\n\u003C|im_start>assistant\n\"\"\"\n    # 联合类型使模型能够返回结构化数据或 “我不知道”\n    result = model(prompt, EventResponse, max_new_tokens=200)\n    results.append(result)\n\n# 显示结果\nfor i, result in enumerate(results):\n    print(f\"活动 {i+1}:\")\n    if isinstance(result, str):\n        print(f\"  {result}\")\n    else:\n        # 这是一个 EventInfo 对象\n        print(f\"  名称：{result.name}\")\n        print(f\"  类型：{result.event_type}\")\n        print(f\"  日期：{result.date}\")\n        print(f\"  主题：{', '.join(result.topics)}\")\n    print()\n\n# 在下游流程中使用结构化数据\nstructured_count = sum(1 for r in results if isinstance(r, EventInfo))\nprint(f\"成功从 {structured_count} 场活动中提取了数据，总共有 {len(results)} 场活动\")\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails id=\"categorize-documents-into-predefined-types\">\u003Csummary>\u003Cb>🗂️ 将文档分类为预定义类型\u003C\u002Fb>\n\u003Cbr>在此案例中，outlines 使用字面量类型规范将文档分类为预定义类别（例如“财务报告”、“法律合同”）。分类结果以表格形式展示，并通过类别分布汇总图呈现，说明结构化输出如何简化内容管理。\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom typing import Literal, List\nimport pandas as pd\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\n# 使用 Literal 定义分类类别\nDocumentCategory = Literal[\n    \"财务报告\",\n    \"法律合同\",\n    \"技术文档\",\n    \"营销材料\",\n    \"个人信件\"\n]\n\n# 待分类的示例文档\ndocuments = [\n    \"第三季度财务摘要：收入同比增长15%，达到1240万美元。EBITDA利润率从去年第三季度的19%提升至23%。运营费用...\",\n\n    \"本协议由甲方和乙方于…日签订，以下简称‘双方’，\",\n\n    \"该API接受带有JSON负载的POST请求。必需参数包括‘user_id’和‘transaction_type’。成功时，端点返回200状态码。\"\n]\n\ntemplate = outlines.Template.from_string(\"\"\"\n\u003C|im_start|>user\n请将以下文档精确地归类到下列类别之一：\n- 财务报告\n- 法律合同\n- 技术文档\n- 市场营销材料\n- 个人通信\n\n文档：\n{{ document }}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\")\n\n# 对文档进行分类\ndef classify_documents(texts: List[str]) -> List[DocumentCategory]:\n    results = []\n\n    for text in texts:\n        prompt = template(document=text)\n        # 模型必须返回预定义的其中一个类别\n        category = model(prompt, DocumentCategory, max_new_tokens=200)\n        results.append(category)\n\n    return results\n\n# 执行分类\nclassifications = classify_documents(documents)\n\n# 创建一个简单的结果表格\nresults_df = pd.DataFrame({\n    \"文档\": [doc[:50] + \"...\" for doc in documents],\n    \"分类\": classifications\n})\n\nprint(results_df)\n\n# 按类别统计文档数量\ncategory_counts = pd.Series(classifications).value_counts()\nprint(\"\\n类别分布：\")\nprint(category_counts)\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary id=\"schedule-a-meeting-with-function-calling\">\u003Cb>📅 使用函数调用从请求中安排会议\u003C\u002Fb>\n\u003Cbr>此示例展示了outlines如何解析自然语言会议请求，并将其转换为与预定义函数参数匹配的结构化格式。一旦提取出会议详情（例如标题、日期、时长、参会人员），这些信息就会被用来自动安排会议。\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nimport json\nfrom typing import List, Optional\nfrom datetime import date\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002Fphi-4\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\n# 定义一个带类型参数的函数\ndef schedule_meeting(\n    title: str,\n    date: date,\n    duration_minutes: int,\n    attendees: List[str],\n    location: Optional[str] = None,\n    agenda_items: Optional[List[str]] = None\n):\n    \"\"\"根据指定的细节安排会议\"\"\"\n    # 在实际应用中，这会创建会议\n    meeting = {\n        \"title\": title,\n        \"date\": date,\n        \"duration_minutes\": duration_minutes,\n        \"attendees\": attendees,\n        \"location\": location,\n        \"agenda_items\": agenda_items\n    }\n    return f\"会议‘{title}’已安排在{date}举行，共有{len(attendees)}位参会者\"\n\n# 自然语言请求\nuser_request = \"\"\"\n我需要下周二下午2点与工程团队安排一次产品路线图评审会议。会议应持续90分钟。请邀请john@example.com、sarah@example.com以及product@example.com的产品团队参加。\n\"\"\"\n\n# Outlines会自动从函数签名中推断出所需的结构\nprompt = f\"\"\"\n\u003C|im_start|>user\n请从该请求中提取会议详情：\n\n{user_request}\n\u003C|im_end|>\n\u003C|im_start|>assistant\n\"\"\"\nmeeting_params = model(prompt, schedule_meeting, max_new_tokens=200)\n\n# 结果是一个与函数参数匹配的字典\nmeeting_params = json.loads(meeting_params)\nprint(meeting_params)\n\n# 使用提取的参数调用函数\nresult = schedule_meeting(**meeting_params)\nprint(result)\n# “会议‘产品路线图评审’已安排在2023年10月17日举行，共有3位参会者”\n```\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary id=\"dynamically-generate-prompts-with-re-usable-templates\">\u003Cb>📝 使用可重用模板动态生成提示\u003C\u002Fb>\n\u003Cbr>通过基于Jinja的模板，此示例展示了如何为情感分析等任务生成动态提示。它说明了如何轻松地复用和自定义提示——包括少样本学习策略——以适应不同的内容类型，同时确保输出保持结构化。\n\u003C\u002Fsummary>\n\n```python\nimport outlines\nfrom typing import List, Literal\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\n\nMODEL_NAME = \"microsoft\u002Fphi-4\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n\n\n# 1. 创建一个使用Jinja语法的可重用模板\nsentiment_template = outlines.Template.from_string(\"\"\"\n\u003C|im_start>user\n请分析以下{{ content_type }}的情感倾向：\n\n{{ text }}\n\n请将您的分析结果表述为“正面”、“负面”或“中性”。\n\u003C|im_end>\n\u003C|im_start>assistant\n\"\"\")\n\n# 2. 使用不同参数生成提示\nreview = \"这家餐厅完全超出了我的预期。服务太棒了！\"\nprompt = sentiment_template(content_type=\"评论\", text=review)\n\n# 3. 使用模板化的提示进行结构化生成\nresult = model(prompt, Literal[\"正面\", \"负面\", \"中性\"])\nprint(result)  # \"正面\"\n\n# 模板也可以从文件中加载\nexample_template = outlines.Template.from_file(\"templates\u002Ffew_shot.txt\")\n\n# 结合示例进行少样本学习\nexamples = [\n    (\"食物很冷\", \"负面\"),\n    (\"员工很友好\", \"正面\")\n]\nfew_shot_prompt = example_template(examples=examples, query=\"服务很慢\")\nprint(few_shot_prompt)\n```\n\u003C\u002Fdetails>\n\n## 他们使用outlines\n\n\u003Cdiv align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_5611259f6ff7.png\" alt=\"用户Logo\">\u003C\u002Fimg>\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_bd1ef7b4ab09.png\" alt=\"用户Logo\">\u003C\u002Fimg>\n\u003C\u002Fdiv>\n\n## 模型集成\n\n| 模型类型 | 描述 | 文档 |\n|---------|-------------|:-------------:|\n| **服务器支持** | vLLM 和 Ollama | [服务器集成 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002F) |\n| **本地模型支持** | transformers 和 llama.cpp | [模型集成 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002F) |\n| **API支持** | OpenAI 和 Gemini | [API集成 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002F) |\n\n## 核心功能\n\n| 功能 | 描述 | 文档 |\n|---------|-------------|:-------------:|\n| **多选** | 将输出限制为预定义选项 | [多选指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#multiple-choices) |\n| **函数调用** | 从函数签名中推断结构 | [函数指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#json-schemas) |\n| **JSON\u002FPydantic** | 生成符合 JSON 模式的输出 | [JSON 指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#json-schemas) |\n| **正则表达式** | 生成符合正则表达式模式的文本 | [正则表达式指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#regex-patterns) |\n| **语法** | 强制复杂的输出结构 | [语法指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#context-free-grammars) |\n\n## 其他功能\n\n| 功能 | 描述 | 文档 |\n|---------|-------------|:-------------:|\n| **提示模板** | 将复杂提示与代码分离 | [模板指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Futility\u002Ftemplate\u002F) |\n| **自定义类型** | 直观的界面用于构建复杂类型 | [Python 类型指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Foutput_types\u002F#basic-python-types) |\n| **应用** | 将模板和类型封装成函数 | [应用指南 →](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Futility\u002Fapplication\u002F) |\n\n## 关于 .txt\n\n\u003Cdiv align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_03dac4339ec7.png\" alt=\"dottxt logo\" width=100>\u003C\u002Fimg>\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_readme_4a98fcb999f9.png\" alt=\"dottxt logo\" width=100>\u003C\u002Fimg>\n\u003C\u002Fdiv>\n\nOutlines 由 [.txt](https:\u002F\u002Fdottxt.co) 开发并维护，该公司致力于使大语言模型在生产级应用中更加可靠。\n\n我们的重点是通过以下方式推动结构化生成技术的发展：\n\n- 🧪 **前沿研究**: 我们在 [结构化生成](http:\u002F\u002Fblog.dottxt.co\u002Fperformance-gsm8k.html) 上发表研究成果\n- 🚀 **企业级解决方案**: 您可以授权使用 [我们的企业级库](https:\u002F\u002Fdocs.dottxt.co)。\n- 🧩 **开源协作**: 我们相信公开协作并为社区做出贡献。\n\n请关注我们的 [Twitter](https:\u002F\u002Ftwitter.com\u002Fdottxtai) 或访问我们的 [博客](https:\u002F\u002Fblog.dottxt.co)，以了解我们在提升大语言模型可靠性方面的最新进展。\n\n## 社区\n\n\u003Cdiv align=\"center\" style=\"margin-bottom: 1em;\">\n\n[![贡献者][contributors-badge]][contributors]\n[![星标][stars-badge]][stars]\n[![下载量][downloads-badge]][pypistats]\n[![Discord徽章][discord-badge]][discord]\n\n\u003C\u002Fdiv>\n\n- 💡 **有想法吗？** 来 [Discord][discord] 和我们聊聊\n- 🐞 **发现错误了吗？** 请提交 [issue](https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fissues)\n- 🧩 **想贡献吗？** 请参阅我们的 [贡献指南](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Fcommunity\u002Fcontribute\u002F).\n\n\n## 引用 Outlines\n\n```\n@article{willard2023efficient,\n  title={高效的大语言模型引导式生成},\n  author={Willard, Brandon T and Louf, R{\\'e}mi},\n  journal={arXiv 预印本 arXiv:2307.09702},\n  year={2023}\n}\n```\n\n[contributors]: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fgraphs\u002Fcontributors\n[contributors-badge]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fcontributors\u002Fdottxt-ai\u002Foutlines?style=flat-square&logo=github&logoColor=white&color=ECEFF4\n[dottxt-blog]: https:\u002F\u002Fblog.dottxt.co\u002F\n[dottxt-blog-badge]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdottxt%20blog-a6b4a3\n[dottxt-twitter]: https:\u002F\u002Ftwitter.com\u002Fdottxtai\n[dottxt-twitter-badge]: https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fdottxtai?style=social\n[discord]: https:\u002F\u002Fdiscord.gg\u002FR9DSu34mGd\n[discord-badge]: https:\u002F\u002Fimg.shields.io\u002Fdiscord\u002F1182316225284554793?color=ddb8ca&logo=discord&logoColor=white&style=flat-square\n[downloads-badge]: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fdm\u002Foutlines?color=A6B4A3&logo=python&logoColor=white&style=flat-square\n[pypistats]: https:\u002F\u002Fpypistats.org\u002Fpackages\u002Foutlines\n[pypi-version-badge]: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Foutlines?style=flat-square&logoColor=white&color=ddb8ca\n[pypi]: https:\u002F\u002Fpypi.org\u002Fproject\u002Foutlines\u002F\n[stars]: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fstargazers\n[stars-badge]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fdottxt-ai\u002Foutlines?style=flat-square&logo=github&color=BD932F&logoColor=white\n[twitter-badge]: https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fdottxtai?style=flat-square&logo=x&logoColor=white&color=bd932f\n[twitter]: https:\u002F\u002Fx.com\u002Fdottxtai","# Outlines 快速上手指南\n\n## 环境准备\n\n- **系统要求**：支持 Windows、Linux、macOS 等主流操作系统\n- **前置依赖**：\n  - Python 3.8 或更高版本\n  - `transformers` 库（用于加载模型）\n  - `pydantic` 库（用于定义结构化输出）\n\n> 建议使用国内镜像源加速安装，例如：\n> ```bash\n> pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple outlines\n> ```\n\n## 安装步骤\n\n```shell\npip install outlines\n```\n\n> 如果需要使用国内镜像源，可使用以下命令：\n> ```bash\n> pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple outlines\n> ```\n\n## 基本使用\n\n### 1. 加载模型\n\n```python\nimport outlines\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\nMODEL_NAME = \"microsoft\u002FPhi-3-mini-4k-instruct\"\nmodel = outlines.from_transformers(\n    AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map=\"auto\"),\n    AutoTokenizer.from_pretrained(MODEL_NAME)\n)\n```\n\n### 2. 使用简单结构化输出\n\n```python\nfrom typing import Literal\nfrom pydantic import BaseModel\n\n# 简单分类\nsentiment = model(\n    \"Analyze: 'This product completely changed my life!'\",\n    Literal[\"Positive\", \"Negative\", \"Neutral\"]\n)\nprint(sentiment)  # \"Positive\"\n\n# 提取特定类型\ntemperature = model(\"What's the boiling point of water in Celsius?\", int)\nprint(temperature)  # 100\n```\n\n### 3. 创建复杂结构\n\n```python\nfrom pydantic import BaseModel\nfrom enum import Enum\n\nclass Rating(Enum):\n    poor = 1\n    fair = 2\n    good = 3\n    excellent = 4\n\nclass ProductReview(BaseModel):\n    rating: Rating\n    pros: list[str]\n    cons: list[str]\n    summary: str\n\nreview = model(\n    \"Review: The XPS 13 has great battery life and a stunning display, but it runs hot and the webcam is poor quality.\",\n    ProductReview,\n    max_new_tokens=200,\n)\n\nreview = ProductReview.model_validate_json(review)\nprint(f\"Rating: {review.rating.name}\")  # \"Rating: good\"\nprint(f\"Pros: {review.pros}\")           # \"Pros: ['great battery life', 'stunning display']\"\nprint(f\"Summary: {review.summary}\")     # \"Summary: Good laptop with great display but thermal issues\"\n```","某医疗信息系统的开发团队需要从患者病历中提取关键信息，如诊断结果、用药建议和检查项目。这些信息用于后续的电子健康记录系统整合。\n\n### 没有 outlines 时\n- 依赖正则表达式或手动解析，容易出错且维护成本高\n- 不同医生的书写风格差异大，导致提取准确率低\n- 需要频繁调整解析逻辑以适应新格式的病历\n- 提取的数据结构不稳定，难以直接用于系统集成\n\n### 使用 outlines 后\n- 直接定义 Pydantic 模型，确保提取数据结构一致\n- 自动处理不同书写风格，提升提取准确率\n- 无需修改代码即可适配多种病历格式\n- 输出数据可直接用于系统集成，减少后期处理\n\n通过结构化生成，显著提升了病历信息提取的效率与准确性。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdottxt-ai_outlines_55908644.png","dottxt-ai",".txt","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fdottxt-ai_98c1f1f4.png","Making AI speak the language of any application",null,"contact@dottxt.co","dottxtai","https:\u002F\u002Fdottxt.co","https:\u002F\u002Fgithub.com\u002Fdottxt-ai",[85,89],{"name":86,"color":87,"percentage":88},"Python","#3572A5",99.7,{"name":90,"color":91,"percentage":92},"Nix","#7e7eff",0.3,13625,675,"2026-04-05T10:29:12","Apache-2.0","Linux, macOS, Windows","未说明",{"notes":100,"python":101,"dependencies":102},"需要安装 transformers 和 torch 库，建议使用 GPU 加速。首次运行可能需要下载模型文件","3.8+",[103,104,105,106],"torch>=2.0","transformers>=4.30","accelerate","pydantic",[15],[109,110,111,112,113,114,115,116],"generative-ai","llms","prompt-engineering","symbolic-ai","cfg","json","regex","structured-generation","2026-03-27T02:49:30.150509","2026-04-06T06:46:08.487544",[120,125,130,135,140,144],{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},5394,"使用 vLLM 时，RegexLogitsProcessor 在多 GPU 上出现错误如何解决？","尝试在 `main` 分支上测试，维护者建议重新测试并报告结果。如果问题仍然存在，可能需要检查是否已正确应用补丁或等待后续版本修复。","https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fissues\u002F524",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},5395,"使用 JSONLogitsProcessor 时遇到 'LLM' 对象没有 'tokenizer' 属性的错误如何解决？","需要对 `adapt_tokenizer` 进行修改，参考 [此处](https:\u002F\u002Fgithub.com\u002Foutlines-dev\u002Foutlines\u002Fblob\u002F7fae436345e621a955e1e6ea610f74cf59f9466f\u002Foutlines\u002Fserve\u002Fvllm.py#L80) 的代码进行适配。","https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fissues\u002F624",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},5396,"安装 outlines 时提示需要安装 datasets 库如何解决？","尝试安装特定版本的 datasets，例如 `datasets==2.21.0`，因为某些版本可能存在兼容性问题。","https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fissues\u002F382",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},5397,"在 Google Colab 中无法安装 outlines 的原因是什么？","由于 Colab 环境中缺少 Rust 编译工具链，导致 outlines core 无法编译。可以尝试通过其他方式安装或配置环境。","https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fissues\u002F1198",{"id":141,"question_zh":142,"answer_zh":143,"source_url":124},5398,"使用 RegexLogitsProcessor 时出现 TypeError: __call__() 缺少参数如何解决？","请确认是否已正确应用补丁，并确保使用的是最新版本的代码。如问题仍存在，建议联系维护者反馈。",{"id":145,"question_zh":146,"answer_zh":147,"source_url":139},5399,"如何解决 outlines 安装过程中因 Rust 缺失导致的编译失败？","在支持 Rust 的环境中安装，或者尝试使用预编译的二进制包。对于 Colab 等无 Rust 支持的环境，可能需要寻找替代方案。",[149,154,159,164,169,174,179,184,189,194,199,204,209,214,219,224,229,234,239,244],{"id":150,"version":151,"summary_zh":152,"released_at":153},104859,"1.2.12","## What's Changed\r\n* Add a link to the audit form in the README and the doc website by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1822\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.11...1.2.12","2026-03-03T11:06:02",{"id":155,"version":156,"summary_zh":157,"released_at":158},104860,"1.2.11","## What's Changed\r\n* Add documentation preview when opening a PR by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1818\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.10...1.2.11","2026-02-13T07:16:31",{"id":160,"version":161,"summary_zh":162,"released_at":163},104861,"1.2.10","## What's Changed\r\n* Correct mlx-lm example unpacking operator by @Anri-Lombard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1786\r\n* Remove todos by @Anri-Lombard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1788\r\n* fix: correct chat format usage by @Ki-Seki in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1790\r\n* Add AsyncOllama to __all__ exports by @Anri-Lombard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1791\r\n* fix: Best-effort use of chat completion by @Ki-Seki in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1789\r\n* Fix bug in JsonSchema resulting in the schema validation not running by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1795\r\n* Update the is_int_instance to exclude booleans by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1799\r\n* Have the _handle_list function gives an explicit error if no args by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1801\r\n* Initial lm studio integration by @Anri-Lombard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1787\r\n* Add sentencepiece to transformers optional dependencies by @majiayu000 in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1796\r\n* Add a step in the GitHub actions to cache HF models by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1807\r\n* Upgrade outlines_core and update imports by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1808\r\n* Add a step to free disk space in the CI by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1804\r\n* Fix typo in vision argument of Ollama by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1811\r\n* Move from supported Python version from 3.9-3.12 to 3.10-3.13 by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1813\r\n* Add architecture documentation to the Guide section by @majiayu000 in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1797\r\n* Add parametrized Transformers smoke test for tokenizer robustness by @kudos07 in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1814\r\n* Fix a bug in the Transformers tokenizer by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1817\r\n\r\n## New Contributors\r\n* @Anri-Lombard made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1786\r\n* @majiayu000 made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1796\r\n* @kudos07 made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1814\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.9...1.2.10","2026-02-06T07:30:59",{"id":165,"version":166,"summary_zh":167,"released_at":168},104862,"1.2.9","## What's Changed\r\n* fix: Refactor sampling parameters in VLLMOffline to use StructuredOutputsParams by @Ki-Seki in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1779\r\n* docs: clarify use of `SamplingParams` in model response examples by @Ki-Seki in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1777\r\n* Update the uv.lock by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1783\r\n\r\n## New Contributors\r\n* @Ki-Seki made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1779\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.8...1.2.9","2025-11-24T12:48:04",{"id":170,"version":171,"summary_zh":172,"released_at":173},104863,"1.2.8","## What's Changed\r\n* Use uv sync in the CI instead of pip install by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1767\r\n* Fix error in the batch method of the MLXLM model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1772\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.7...1.2.8","2025-10-27T10:59:47",{"id":175,"version":176,"summary_zh":177,"released_at":178},104864,"1.2.7","## What's Changed\r\n* Add the device_dtype init parameter to the transformers model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1762\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.6...1.2.7","2025-10-14T16:26:27",{"id":180,"version":181,"summary_zh":182,"released_at":183},104865,"1.2.6","## What's Changed\r\n* Fix correct handling of chat multimodal inputs in TransformersMM class by @laitifranz in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1728\r\n* Add batch generation to the MLXLM model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1759\r\n* Feature\u002Fmistral ai integration by @yasteven in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1755\r\n* Add json type conversion by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1761\r\n* Fix installation instructions by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1764\r\n* Add design partner CTA in docs by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1766\r\n\r\n## New Contributors\r\n* @yasteven made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1755\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.5...1.2.6","2025-10-14T08:35:05",{"id":185,"version":186,"summary_zh":187,"released_at":188},104866,"1.2.5","## What's Changed\r\n* Update the output_type formatting of the llamacpp model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1753\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.4...1.2.5","2025-09-15T20:07:34",{"id":190,"version":191,"summary_zh":192,"released_at":193},104867,"1.2.4","## What's Changed\r\n* Fix a bug in OutlinesCore backend about advancing when in final state by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1727\r\n* Jax\u002Ftensorflow deprecation by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1726\r\n* Update workflow to test API models, use manual trigger by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1734\r\n* fix typings by resolving exports by @the-vampiire in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1731\r\n* Remove redundant parameter api models tests workflow by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1735\r\n* Remove the benchmarks workflow by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1737\r\n* Update vLLM model references and API key usage in documentation by @laitifranz in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1745\r\n* Fix the image download issue in the tests by creating an image ourselves by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1747\r\n* Reduce the number of mandatory dependencies + update uv.lock by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1740\r\n* Add support for the Chat input to the MLXLM model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1748\r\n* Update uv.lock by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1749\r\n* Add setuptools to the list of transformers dependencies by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1750\r\n\r\n## New Contributors\r\n* @the-vampiire made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1731\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.3...1.2.4","2025-09-02T12:34:15",{"id":195,"version":196,"summary_zh":197,"released_at":198},104868,"1.2.3","## What's Changed\r\n* Create AsyncOpenAI model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1721\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.2...1.2.3","2025-08-11T21:21:10",{"id":200,"version":201,"summary_zh":202,"released_at":203},104869,"1.2.2","## What's Changed\r\n* Fix a bug in the `outlines_core` backend for the `Transformers` model about the token to string conversion by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1716\r\n* Fix a bug regarding the `eos_token` in the `LlamaCpp` tokenizer by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1712\r\n* Fix a bug related to the device of the bitmasks for torch tensors by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1714\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.1...1.2.2","2025-08-08T13:13:16",{"id":205,"version":206,"summary_zh":207,"released_at":208},104870,"1.2.1","## What's Changed\r\n* Create our own logits processor for Xgrammar, add support for mlx by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1706\r\n* Turn tokens into strings before building the Outlines-Core Vocabulary by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1707\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.2.0...1.2.1","2025-08-04T14:45:37",{"id":210,"version":211,"summary_zh":212,"released_at":213},104871,"1.2.0","## What's Changed\r\n* Remove dead link to VLM example from examples index by @laitifranz in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1685\r\n* Fix: JSON schema union types (type arrays) fail with 'type must be a string' error by @brightlikethelight in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1675\r\n* Update docs with OpenRouter guide by @Oni-giri in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1691\r\n* Fix broken wheel builds caused by ambiguous packaging instructions by @neilmehta24 in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1690\r\n* Support different backends on top of outlines_core by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1689\r\n* Import fix in base.py by @Oni-giri in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1703\r\n* Upgrade outlines-core to 0.2.11 and remove experimental CFG code by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1700\r\n\r\n## New Contributors\r\n* @laitifranz made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1685\r\n* @brightlikethelight made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1675\r\n* @Oni-giri made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1691\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.1.1...1.2.0","2025-07-31T14:15:48",{"id":215,"version":216,"summary_zh":217,"released_at":218},104872,"1.1.1","## What's Changed\r\n* Set add_generation_template to True in chat formatting for Transformers by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1684\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.1.0...1.1.1","2025-07-11T12:10:32",{"id":220,"version":221,"summary_zh":222,"released_at":223},104873,"1.1.0","## What's Changed\r\n* Create the inputs module and modify the treatment of multimodal inputs by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1677\r\n* Create the Chat input and add it to the models by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1680\r\n* Misc doc fixes by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1683\r\n* Remove deprecated features from v0 by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1682\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.0.4...1.1.0","2025-07-10T18:24:09",{"id":225,"version":226,"summary_zh":227,"released_at":228},104874,"1.0.4","## What's Changed\r\n* Create Choice output type by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1671\r\n* Add the ensure_ascii parameter to JsonSchema by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1672\r\n* Add a batch method to models by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1674\r\n* Fix error tokenizer arg for transformers models' generate method by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1679\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.0.3...1.0.4","2025-07-04T19:23:42",{"id":230,"version":231,"summary_zh":232,"released_at":233},104875,"1.0.3","## What's Changed\r\n* Add llm.txt file by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1661\r\n* Fix nightly tests (remove Slack alert causing troubles) by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1660\r\n* Fix error with additionalProperties for the OpenAI model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1668\r\n* Add  the AsyncOllama model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1669\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.0.2...1.0.3","2025-07-01T09:21:26",{"id":235,"version":236,"summary_zh":237,"released_at":238},104876,"1.0.2","## What's Changed\r\n* Fix typos in getting started guide by @ganglike248 in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1644\r\n* Move VLM guide and remove Docker CI Action by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1643\r\n* Fix example typo in README by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1650\r\n* Add testing and documentation for vision input for VLLM model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1648\r\n* Add support for vision input for the Ollama model by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1647\r\n* Add setup example for local server by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1646\r\n* Add IPv4, UUID4, and Hex String Types by @jacobmarks in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1655\r\n* Fix the FastAPI example by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1662\r\n\r\n## New Contributors\r\n* @ganglike248 made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1644\r\n* @jacobmarks made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1655\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.0.1...1.0.2","2025-06-26T10:33:12",{"id":240,"version":241,"summary_zh":242,"released_at":243},104877,"1.0.1","## What's Changed\r\n* Fix broken links in the README by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1625\r\n* Fix the broken links in the home page of the documentation by @RobinPicard in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1628\r\n* Fix typos across the codebase by @sukrucildirr in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1631\r\n* Update the documentation content and styling by @rlouf in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1636\r\n\r\n## New Contributors\r\n* @sukrucildirr made their first contribution in https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fpull\u002F1631\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fdottxt-ai\u002Foutlines\u002Fcompare\u002F1.0.0...1.0.1","2025-06-20T13:00:13",{"id":245,"version":246,"summary_zh":247,"released_at":248},104878,"1.0.0","## Why a new major version?\r\n\r\nThe v1 intends on making Outlines more closely focused on constrained generation. To do so, we delegate a wider range of tasks to the users and inference libraries. On top of making Outlines leaner, this design provides more flexibility to the users and let them use interfaces they are already familiar with.\r\n\r\nOur approach is inspired by the unix best practices — each element does one thing well, and we compose those functional elements.\r\n\r\nAs this new version deprecates some previously available features of Outlines, we have written a migration guide that gives detailed information on how to upgrade your v0 code to v1.\r\n\r\n## Deprecated\r\n\r\nAll deprecated features listed below will be removed in version 1.1.0. Until then, a warning will be displayed with information on how to migrate your code to v1.\r\n\r\n- The model loader functions from the `models` module (`transformers`, `openai`, etc.) have been deprecated. They are replaced by equivalent functions prefixed with `from_` such as `from_transformers`, `from_openai`, etc. The new loader functions accept different arguments compared to the old ones. They now typically require an instance of an engine\u002Fclient from the associated inference library. This change was made to avoid duplicating inference library logic and to give users more control over inference engine\u002Fclient initialization.\r\n[Documentation](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels)\r\n\r\n```python\r\n# v0\r\nfrom outlines import models\r\nfrom transformers import BertForSequenceClassification, BertTokenizer\r\n\r\nmodel = models.transformers(\r\n    model_name=\"prajjwal1\u002Fbert-tiny\",\r\n    model_class=BertForSequenceClassification,\r\n    tokenizer_class=BertTokenizer,\r\n    model_kwargs={\"use_cache\": False},\r\n    tokenizer_kwargs={\"model_max_length\": 512},\r\n)\r\n\r\n# v1\r\nimport outlines\r\nfrom transformers import BertForSequenceClassification, BertTokenizer\r\n\r\nhf_model = BertForSequenceClassification.from_pretrained(\"prajjwal1\u002Fbert-tiny\", use_cache=False)\r\nhf_tokenizer = BertTokenizer.from_pretrained(\"prajjwal1\u002Fbert-tiny\", model_max_length=512)\r\nmodel = outlines.from_transformers(hf_model, hf_tokenizer)\r\n```\r\n\r\n- The `generate` module and the associated functions (`json`, `choice`…) have been deprecated. They are replaced by the `Generator` constructor. While you had to select the right generate function for your output type, you can now provide any output type supported by Outlines to the unique `Generator` object.\r\n[Documentation](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fcore\u002Fgenerator)\r\n    \r\n\r\n```python\r\n# v0\r\nfrom pydantic import BaseModel\r\nfrom outlines import generate, models\r\n\r\nclass Character(BaseModel):\r\n\tname: str\r\n\t\t\r\nmodel = models.openai(\"gpt-4o\")\r\ngenerator = generate.json(model, Character)\r\n\r\n# v1\r\nfrom openai import OpenAI\r\nfrom pydantic import BaseModel\r\nfrom outlines import Generator, from_openai\r\n\r\nclass Character(BaseModel):\r\n\tname: str\r\n\r\nmodel = from_openai(OpenAI())\r\ngenerator = Generator(model, Character)\r\n```\r\n\r\n- The `TransformersVision` model has been deprecated. It's replaced by `TransformersMultiModal`, which is more general as it supports additional input types beyond images, such as audio. When calling it, instead of providing the prompt and image assets separately, both should now be included in a single dictionary. The model is loaded with `from_transformers` just like the `Transformers` model, but the second argument must be a processor instead of a tokenizer.\r\n[Documentation](https:\u002F\u002Fdottxt-ai.github.io\u002Foutlines\u002Flatest\u002Ffeatures\u002Fmodels\u002Ftransformers_multimodal)\r\n    \r\n\r\n```python\r\n# v0\r\nfrom io import BytesIO\r\nfrom urllib.request import urlopen\r\nfrom PIL import Image\r\nfrom transformers import LlavaForConditionalGeneration\r\nfrom outlines import models, generate\r\n\r\ndef img_from_url(url):\r\n    img_byte_stream = BytesIO(urlopen(url).read())\r\n    return Image.open(img_byte_stream).convert(\"RGB\")\r\n\r\nmodel = models.transformers_vision(\r\n    model_name=\"trl-internal-testing\u002Ftiny-LlavaForConditionalGeneration\",\r\n    model_class=LlavaForConditionalGeneration,\r\n)\r\ngenerator = generate.text(model)\r\nresult = generator(\r\n    \"Describe the image \u003Cimage>\",\r\n    img_from_url(\"https:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002F2\u002F25\u002FSiam_lilacpoint.jpg\")\r\n)\r\n\r\n# v1\r\nfrom io import BytesIO\r\nfrom urllib.request import urlopen\r\nfrom PIL import Image\r\nfrom transformers import LlavaForConditionalGeneration, AutoProcessor\r\nimport outlines\r\n\r\ndef img_from_url(url):\r\n    img_byte_stream = BytesIO(urlopen(url).read())\r\n    return Image.open(img_byte_stream).convert(\"RGB\")\r\n\r\nmodel = outlines.from_transformers(\r\n\tLlavaForConditionalGeneration.from_pretrained(\"trl-internal-testing\u002Ftiny-LlavaForConditionalGeneration\"),\r\n\tAutoProcessor.from_pretrained(\"trl-internal-testing\u002Ftiny-LlavaForConditionalGeneration\")\r\n)\r\nimage = img_from_url(\"https:\u002F\u002Fupload.wikimedia.org\u002Fwikipedia\u002Fcommons\u002F2\u002F25\u002FSiam_lilacpoint.jpg\")\r\nresult = model({\"text\": \"Describe the image \u003Cimage>\", ","2025-06-18T15:32:18"]