[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-Azure-Samples--azure-search-openai-demo-csharp":3,"tool-Azure-Samples--azure-search-openai-demo-csharp":65},[4,17,27,35,48,57],{"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 真正成长为懂上",151314,2,"2026-04-11T23:32:58",[13,14,15],"开发框架","Agent","语言模型","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,3,"2026-04-06T11:19:32",[15,26,14,13],"图像",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":10,"last_commit_at":33,"category_tags":34,"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":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":10,"last_commit_at":41,"category_tags":42,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",85092,"2026-04-10T11:13:16",[26,43,44,45,14,46,15,13,47],"数据工具","视频","插件","其他","音频",{"id":49,"name":50,"github_repo":51,"description_zh":52,"stars":53,"difficulty_score":54,"last_commit_at":55,"category_tags":56,"status":16},5784,"funNLP","fighting41love\u002FfunNLP","funNLP 是一个专为中文自然语言处理（NLP）打造的超级资源库，被誉为\"NLP 民工的乐园”。它并非单一的软件工具，而是一个汇集了海量开源项目、数据集、预训练模型和实用代码的综合性平台。\n\n面对中文 NLP 领域资源分散、入门门槛高以及特定场景数据匮乏的痛点，funNLP 提供了“一站式”解决方案。这里不仅涵盖了分词、命名实体识别、情感分析、文本摘要等基础任务的标准工具，还独特地收录了丰富的垂直领域资源，如法律、医疗、金融行业的专用词库与数据集，甚至包含古诗词生成、歌词创作等趣味应用。其核心亮点在于极高的全面性与实用性，从基础的字典词典到前沿的 BERT、GPT-2 模型代码，再到高质量的标注数据和竞赛方案，应有尽有。\n\n无论是刚刚踏入 NLP 领域的学生、需要快速验证想法的算法工程师，还是从事人工智能研究的学者，都能在这里找到急需的“武器弹药”。对于开发者而言，它能大幅减少寻找数据和复现模型的时间；对于研究者，它提供了丰富的基准测试资源和前沿技术参考。funNLP 以开放共享的精神，极大地降低了中文自然语言处理的开发与研究成本，是中文 AI 社区不可或缺的宝藏仓库。",79857,1,"2026-04-08T20:11:31",[15,43,46],{"id":58,"name":59,"github_repo":60,"description_zh":61,"stars":62,"difficulty_score":54,"last_commit_at":63,"category_tags":64,"status":16},6590,"gpt4all","nomic-ai\u002Fgpt4all","GPT4All 是一款让普通电脑也能轻松运行大型语言模型（LLM）的开源工具。它的核心目标是打破算力壁垒，让用户无需依赖昂贵的显卡（GPU）或云端 API，即可在普通的笔记本电脑和台式机上私密、离线地部署和使用大模型。\n\n对于担心数据隐私、希望完全掌控本地数据的企业用户、研究人员以及技术爱好者来说，GPT4All 提供了理想的解决方案。它解决了传统大模型必须联网调用或需要高端硬件才能运行的痛点，让日常设备也能成为强大的 AI 助手。无论是希望构建本地知识库的开发者，还是单纯想体验私有化 AI 聊天的普通用户，都能从中受益。\n\n技术上，GPT4All 基于高效的 `llama.cpp` 后端，支持多种主流模型架构（包括最新的 DeepSeek R1 蒸馏模型），并采用 GGUF 格式优化推理速度。它不仅提供界面友好的桌面客户端，支持 Windows、macOS 和 Linux 等多平台一键安装，还为开发者提供了便捷的 Python 库，可轻松集成到 LangChain 等生态中。通过简单的下载和配置，用户即可立即开始探索本地大模型的无限可能。",77307,"2026-04-11T06:52:37",[15,13],{"id":66,"github_repo":67,"name":68,"description_en":69,"description_zh":70,"ai_summary_zh":71,"readme_en":72,"readme_zh":73,"quickstart_zh":74,"use_case_zh":75,"hero_image_url":76,"owner_login":77,"owner_name":78,"owner_avatar_url":79,"owner_bio":80,"owner_company":81,"owner_location":81,"owner_email":81,"owner_twitter":81,"owner_website":82,"owner_url":83,"languages":84,"stars":121,"forks":122,"last_commit_at":123,"license":124,"difficulty_score":125,"env_os":126,"env_gpu":127,"env_ram":127,"env_deps":128,"category_tags":139,"github_topics":140,"view_count":10,"oss_zip_url":81,"oss_zip_packed_at":81,"status":16,"created_at":148,"updated_at":149,"faqs":150,"releases":176},6757,"Azure-Samples\u002Fazure-search-openai-demo-csharp","azure-search-openai-demo-csharp","A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure Cognitive Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences. ","azure-search-openai-demo-csharp 是一个基于 .NET 技术栈构建的开源示例应用，旨在帮助开发者快速实现“检索增强生成”（RAG）模式。它巧妙地将 Azure OpenAI 服务的大语言模型能力与 Azure AI Search 的企业级数据检索功能相结合，让用户能够像使用 ChatGPT 一样，针对私有数据进行自然对话和问答。\n\n该工具主要解决了大语言模型无法直接访问企业内部数据或容易产生“幻觉”的痛点。通过预先索引企业文档（如员工手册、政策文件或职位描述），它能确保 AI 的回答不仅流畅自然，而且严格基于事实依据，从而安全地释放企业数据价值。示例中内置了虚构的\"Contoso Electronics\"公司数据，方便用户立即体验从数据上传到智能问答的完整流程。\n\n这款工具特别适合熟悉 C# 和 Azure 云平台的软件开发人员及架构师使用。无论是希望构建内部知识管理助手、智能客服系统，还是探索 AI 与企业数据融合场景的技术团队，都能从中获得宝贵的参考代码和架构思路。其技术亮点在于提供了端到端的部署方案，支持语音交互、多轮对话及可视化界面，并兼容 Git","azure-search-openai-demo-csharp 是一个基于 .NET 技术栈构建的开源示例应用，旨在帮助开发者快速实现“检索增强生成”（RAG）模式。它巧妙地将 Azure OpenAI 服务的大语言模型能力与 Azure AI Search 的企业级数据检索功能相结合，让用户能够像使用 ChatGPT 一样，针对私有数据进行自然对话和问答。\n\n该工具主要解决了大语言模型无法直接访问企业内部数据或容易产生“幻觉”的痛点。通过预先索引企业文档（如员工手册、政策文件或职位描述），它能确保 AI 的回答不仅流畅自然，而且严格基于事实依据，从而安全地释放企业数据价值。示例中内置了虚构的\"Contoso Electronics\"公司数据，方便用户立即体验从数据上传到智能问答的完整流程。\n\n这款工具特别适合熟悉 C# 和 Azure 云平台的软件开发人员及架构师使用。无论是希望构建内部知识管理助手、智能客服系统，还是探索 AI 与企业数据融合场景的技术团队，都能从中获得宝贵的参考代码和架构思路。其技术亮点在于提供了端到端的部署方案，支持语音交互、多轮对话及可视化界面，并兼容 GitHub Codespaces 等现代化开发环境，极大地降低了智能应用的原型验证门槛。","---\npage_type: sample\nlanguages:\n- azdeveloper\n- csharp\n- html\n- bicep\nproducts:\n- ai-services\n- azure-blob-storage\n- azure-container-apps\n- azure-cognitive-search\n- azure-openai\n- aspnet-core\n- blazor\n- defender-for-cloud\n- azure-monitor\n- dotnet-maui\nurlFragment: azure-search-openai-demo-csharp\nname: ChatGPT + Enterprise data (csharp)\ndescription: A csharp sample app that chats with your data using OpenAI and AI Search.\n---\n\u003C!-- YAML front-matter schema: https:\u002F\u002Freview.learn.microsoft.com\u002Fen-us\u002Fhelp\u002Fcontribute\u002Fsamples\u002Fprocess\u002Fonboarding?branch=main#supported-metadata-fields-for-readmemd -->\n\n## Table of Contents\n\n- [Features](#features)\n- [Application Architecture](#application-architecture)\n- [Azure account requirements](#account-requirements)\n- [Getting Started](#getting-started)\n  - [Cost estimation](#cost-estimation)\n  - [Project setup](#project-setup)\n    - [GitHub Codespaces](#github-codespaces)\n    - [VS Code Dev Containers](#vs-code-remote-containers)\n    - [Local environment](#local-environment)\n  - [Deployment](#deployment)\n    - [Deploying from scratch](#deploying-from-scratch)\n    - [Deploying with existing Azure resources](#use-existing-resources)\n    - [Deploying again](#deploying-or-re-deploying-a-local-clone-of-the-repo)\n    - [Deploying App Spaces](#deploying-your-repo-using-app-spaces)\n    - [Running locally](#running-locally)\n    - [Sharing environments](#sharing-environments)\n    - [Clean up resources](#clean-up-resources)\n  - [Using the app](#using-the-app)\n- [Enabling optional features](#enabling-optional-features)\n  - [Enabling Application Insights](#enabling-optional-features)\n  - [Enabling authentication](#enabling-authentication)\n  - [Enable GPT-4V support](#enable-gpt-4v-support)\n- [Guidance](#guidance) \n  - [Productionizing](#productionizing)\n  - [Resources](#resources)\n  - [FAQ](#faq)\n\n# ChatGPT + Enterprise data with Azure OpenAI and Azure AI Search (.NET)\n\n![GitHub Workflow Status](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Factions\u002Fworkflow\u002Fstatus\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fdotnet-build.yml?label=BUILD%20%26%20TEST&logo=github&style=for-the-badge)\n[![Open in GitHub - Codespaces](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https:\u002F\u002Fgithub.com\u002Fcodespaces\u002Fnew?hide_repo_select=true&ref=main&repo=624102171&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)\n[![Open in Remote - Containers](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https:\u002F\u002Fvscode.dev\u002Fredirect?url=vscode:\u002F\u002Fms-vscode-remote.remote-containers\u002FcloneInVolume?url=https:\u002F\u002Fgithub.com\u002Fazure-samples\u002Fazure-search-openai-demo-csharp)\n\nThis sample demonstrates a few approaches for creating ChatGPT-like experiences over your own data using the Retrieval Augmented Generation pattern. It uses Azure OpenAI Service to access the ChatGPT model (`gpt-4o-mini`), and Azure AI Search for data indexing and retrieval.\n\nThe repo includes sample data so it's ready to try end-to-end. In this sample application, we use a fictitious company called Contoso Electronics, and the experience allows its employees to ask questions about the benefits, internal policies, as well as job descriptions and roles.\n\n![RAG Architecture](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_716da11a32af.png)\n\nFor more details on how this application was built, check out:\n\n- [Transform your business with smart .NET apps powered by Azure and ChatGPT blog post](https:\u002F\u002Faka.ms\u002Fbuild-dotnet-ai-blog)\n- [Build Intelligent Apps with .NET and Azure - Build Session](https:\u002F\u002Fbuild.microsoft.com\u002Fsessions\u002Ff8f953f3-2e58-4535-92ae-5cb30ef2b9b0)\n\nWe want to hear from you! Are you interested in building or currently building intelligent apps? Take a few minutes to complete this survey.\n\n[**Take the survey**](https:\u002F\u002Faka.ms\u002Fdotnet-build-oai-survey)\n\n## Features\n\n- Voice Chat, Chat and Q&A interfaces\n- Explores various options to help users evaluate the trustworthiness of responses with citations, tracking of source content, etc.\n- Shows possible approaches for data preparation, prompt construction, and orchestration of interaction between model (ChatGPT) and retriever (Azure AI Search)\n- Settings directly in the UX to tweak the behavior and experiment with options\n\n![Chat screen](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_8457361e9517.png)\n\n## Application architecture\n\n- **User interface** - The application’s chat interface is a [Blazor WebAssembly](https:\u002F\u002Flearn.microsoft.com\u002Faspnet\u002Fcore\u002Fblazor\u002F) application. This interface is what accepts user queries, routes request to the application backend, and displays generated responses.\n- **Backend** - The application backend is an [ASP.NET Core Minimal API](https:\u002F\u002Flearn.microsoft.com\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fminimal-apis\u002Foverview). The backend hosts the Blazor static web application and what orchestrates the interactions among the different services. Services used in this application include:\n   - [**Azure AI Search**](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fsearch\u002Fsearch-what-is-azure-search) – indexes documents from the data stored in an Azure Storage Account. This makes the documents searchable using [vector search](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fsearch\u002Fsearch-get-started-vector) capabilities. \n   - [**Azure OpenAI Service**](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fai-services\u002Fopenai\u002Foverview) – provides the Large Language Models to generate responses. [Semantic Kernel](https:\u002F\u002Flearn.microsoft.com\u002Fsemantic-kernel\u002Fwhatissk) is used in conjunction with the Azure OpenAI Service to orchestrate the more complex AI workflows.\n\n## Getting Started\n\n### Account Requirements\n\nIn order to deploy and run this example, you'll need\n\n- **Azure Account** - If you're new to Azure, get an [Azure account for free](https:\u002F\u002Faka.ms\u002Ffree) and you'll get some free Azure credits to get started.\n- **Azure account permissions** - Your Azure Account must have `Microsoft.Authorization\u002FroleAssignments\u002Fwrite` permissions, such as [User Access Administrator](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Frole-based-access-control\u002Fbuilt-in-roles#user-access-administrator) or [Owner](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Frole-based-access-control\u002Fbuilt-in-roles#owner).\n\n> [!WARNING]\u003Cbr>\n> By default this sample will create an Azure Container App, and Azure AI Search resource that have a monthly cost, as well as Azure AI Document Intelligence resource that has cost per document page. You can switch them to free versions of each of them if you want to avoid this cost by changing the parameters file under the infra folder (though there are some limits to consider; for example, you can have up to 1 free Azure AI Search resource per subscription, and the free Azure AI Document Intelligence resource only analyzes the first 2 pages of each document.)\n\n### Cost estimation\n\nPricing varies per region and usage, so it isn't possible to predict exact costs for your usage. However, you can try the [Azure pricing calculator](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fcalculator\u002F) for the resources below:\n\n- [**Azure Container Apps**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fcontainer-apps\u002F). Environment type: Consumption Only. The solution uses the Consumption plan, as we don't have specific hardware requirements.\n- [**Azure OpenAI Service**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fcognitive-services\u002Fopenai-service\u002F). Standard tier, GPT and Ada models. Pricing per 1K tokens used, and at least 1K tokens are used per question. \n- [**Azure AI Document Intelligence**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fai-document-intelligence\u002F). SO (Standard) tier using pre-built layout. Pricing per document page, sample documents have 261 pages total.\n- [**Azure AI Search**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fsearch\u002F) Basic tier, 1 replica, free level of semantic search. Pricing per hour.\n- [**Azure Blob Storage**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fstorage\u002Fblobs\u002F). Standard tier with ZRS (Zone-redundant storage). Pricing per storage and read operations. \n- [**Azure Monitor**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fmonitor\u002F). Pay-as-you-go tier. Costs based on data ingested.\n\nTo reduce costs, you can switch to free SKUs for various services, but those SKUs have limitations. See this [guide on deploying with minimal costs](.\u002Fdocs\u002Fdeploy_lowcost.md) for more details.\n\n⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use, either by deleting the resource group in the Portal or running `azd down`.\n\n### Project setup\n\nYou have a few options for setting up this project. The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up [locally](#local-environment) if desired.\n\n#### GitHub Codespaces\n\nYou can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:\n\n[![Open in GitHub - Codespaces](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https:\u002F\u002Fgithub.com\u002Fcodespaces\u002Fnew?hide_repo_select=true&ref=main&repo=624102171&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)\n\n#### VS Code Remote Containers\n\nA related option is VS Code Remote Containers, which will open the project in your local VS Code using the [Dev Containers](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=ms-vscode-remote.remote-containers) extension:\n\n[![Open in Remote - Containers](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https:\u002F\u002Fvscode.dev\u002Fredirect?url=vscode:\u002F\u002Fms-vscode-remote.remote-containers\u002FcloneInVolume?url=https:\u002F\u002Fgithub.com\u002Fazure-samples\u002Fazure-search-openai-demo-csharp)\n\n#### Local environment\n\nInstall the following prerequisites:\n\n- [Azure Developer CLI](https:\u002F\u002Faka.ms\u002Fazure-dev\u002Finstall)\n- [.NET 8](https:\u002F\u002Fdotnet.microsoft.com\u002Fdownload\u002Fdotnet\u002F8.0)\n- [Git](https:\u002F\u002Fgit-scm.com\u002Fdownloads)\n- [Powershell 7+ (pwsh)](https:\u002F\u002Fgithub.com\u002Fpowershell\u002Fpowershell) - For Windows users only.\n  \n   > **Important**: \n   > Ensure you can run `pwsh.exe` from a PowerShell command. If this fails, you likely need to upgrade PowerShell.\n\n- [Docker](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F)\n\n   > **Important**:\n   > Ensure Docker is running before running any `azd` provisioning \u002F deployment commands.\n\nThen, run the following commands to get the project on your local environment:\n\n   1. Run `azd auth login`\n   1. Clone the repository or run `azd init -t azure-search-openai-demo-csharp`\n   1. Run `azd env new azure-search-openai-demo-csharp`\n\n### Deployment\n\n#### Deploying from scratch\n\n[📺 Live stream: Deploying from scratch in CodeSpaces](https:\u002F\u002Fyoutu.be\u002FTORUsRNimM0)\n[📺 Live stream: Deploying from scratch in Windows 11](https:\u002F\u002Fyoutu.be\u002FwgSnkxGH2Sk?si=C4zAbLKhK3LoAS43)\n\n> **Important**:\n> Ensure Docker is running before running any `azd` provisioning \u002F deployment commands.\n\nExecute the following command, if you don't have any pre-existing Azure services and want to start from a fresh deployment.\n\n1. Run `azd up` - This will provision Azure resources and deploy this sample to those resources, including building the search index based on the files found in the `.\u002Fdata` folder.\n   - For the target location, the regions that currently support the model used in this sample are **East US**. For an up-to-date list of regions and models, check [here](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcognitive-services\u002Fopenai\u002Fconcepts\u002Fmodels)\n   - If you have access to multiple Azure subscriptions, you will be prompted to select the subscription you want to use. If you only have access to one subscription, it will be selected automatically.\n\n   > **Note**:\n   > This application uses the `gpt-4o-mini` model. When choosing which region to deploy to, make sure they're available in that region (i.e. EastUS). For more information, see the [Azure OpenAI Service documentation](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fai-services\u002Fopenai\u002Fconcepts\u002Fmodels#standard-deployment-model-availability).\n\n1. After the application has been successfully deployed you will see a URL printed to the console. Click that URL to interact with the application in your browser.\n\nIt will look like the following:\n\n!['Output from running azd up'](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_89594710ce48.png)\n\n> [!NOTE]:\n> It may take a few minutes for the application to be fully deployed.\n> After the application is deployed, it will also take a few minutes to process the documents to be added into the vector database.\n\n#### Use existing resources\n\nIf you have existing resources in Azure that you wish to use, you can configure `azd` to use those by setting the following `azd` environment variables:\n\n1. Run `azd env set AZURE_OPENAI_SERVICE {Name of existing OpenAI service}`\n1. Run `azd env set AZURE_OPENAI_RESOURCE_GROUP {Name of existing resource group that OpenAI service is provisioned to}`\n1. Run `azd env set AZURE_OPENAI_CHATGPT_DEPLOYMENT {Name of existing ChatGPT deployment}`. Only needed if your ChatGPT deployment is not the default 'chat'.\n1. Run `azd env set AZURE_OPENAI_EMBEDDING_DEPLOYMENT {Name of existing embedding model deployment}`. Only needed if your embedding model deployment is not the default `embedding`.\n1. Run `azd up`\n\n> [!NOTE]\u003Cbr> \n> You can also use existing Search and Storage Accounts. See `.\u002Finfra\u002Fmain.parameters.json` for list of environment variables to pass to `azd env set` to configure those existing resources.\n\n#### Deploying or re-deploying a local clone of the repo\n\n> [!IMPORTANT]\u003Cbr>\n> Ensure Docker is running before running any `azd` provisioning \u002F deployment commands.\n\n- Run `azd up`\n\n#### Deploying your repo using App Spaces\n\n> [!NOTE]\u003Cbr>\n> Make sure you have AZD supported bicep files in your repository and add an initial GitHub Actions Workflow file which can either be triggered manually (for initial deployment) or on code change (automatically re-deploying with the latest changes)\n> To make your repository compatible with App Spaces, you need to make changes to your main bicep and main parameters file to allow AZD to deploy to an existing resource group with the appropriate tags.\n\n1. Add AZURE_RESOURCE_GROUP to main parameters file to read the value from environment variable set in GitHub Actions workflow file by App Spaces.\n   ```json\n   \"resourceGroupName\": {\n      \"value\": \"${AZURE_RESOURCE_GROUP}\"\n    }\n   ```\n2. Add AZURE_TAGS to main parameters file to read the value from environment variable set in GitHub Actions workflow file by App Spaces.\n   ```json\n   \"tags\": {\n      \"value\": \"${AZURE_TAGS}\"\n    }\n   ```\n3. Add support for resource group and tags in your main bicep file to read the value being set by App Spaces.\n   ```bicep\n   param resourceGroupName string = ''\n   param tags string = ''\n   ```\n4. Combine the default tags set by Azd with those being set by App Spaces. Replace _tags initialization_ in your main bicep file with the following -\n   ````bicep\n   var baseTags = { 'azd-env-name': environmentName }\n   var updatedTags = union(empty(tags) ? {} : base64ToJson(tags), baseTags)\n   Make sure to use \"updatedTags\" when assigning \"tags\" to resource group created in your bicep file and update the other resources to use \"baseTags\" instead of \"tags\". For example -\n   ```json\n   resource rg 'Microsoft.Resources\u002FresourceGroups@2021-04-01' = {\n     name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'\n     location: location\n     tags: updatedTags\n   }\n   ````\n\n#### Running locally\n\n> [!IMPORTANT]\u003Cbr>\n> Ensure Docker is running before running any `azd` provisioning \u002F deployment commands.\n\n1. Run `azd auth login`\n1. After the application deploys, set the environment variable `AZURE_KEY_VAULT_ENDPOINT`. You can find the value in the _.azure\u002FYOUR-ENVIRONMENT-NAME\u002F.env_ file or the Azure portal.\n1. Run the following .NET CLI command to start the ASP.NET Core Minimal API server (client host):\n\n   ```dotnetcli\n   dotnet run --project .\u002Fapp\u002Fbackend\u002FMinimalApi.csproj --urls=http:\u002F\u002Flocalhost:7181\u002F\n   ```\n\nNavigate to \u003Chttp:\u002F\u002Flocalhost:7181>, and test out the app.\n\n#### Running locally with the .NET MAUI client\n\nThis sample includes a .NET MAUI client, packaging the experience as an app that can run on a Windows\u002FmacOS desktop or on Android and iOS devices. The MAUI client here is implemented using Blazor hybrid, letting it share most code with the website frontend.\n\n1. Open _app\u002Fapp-maui.sln_ to open the solution that includes the MAUI client\n\n1. Edit _app\u002Fmaui-blazor\u002FMauiProgram.cs_, updating `client.BaseAddress` with the URL for the backend.\n\n   If it's running in Azure, use the URL for the service backend from the steps above. If running locally, use \u003Chttp:\u002F\u002Flocalhost:7181>.\n\n1. Set **MauiBlazor** as the startup project and run the app\n\n#### Sharing Environments\n\nRun the following if you want to give someone else access to the deployed and existing environment.\n\n1. Install the [Azure CLI](https:\u002F\u002Flearn.microsoft.com\u002Fcli\u002Fazure\u002Finstall-azure-cli)\n1. Run `azd init -t azure-search-openai-demo-csharp`\n1. Run `azd env refresh -e {environment name}` - Note that they will need the azd environment name, subscription Id, and location to run this command - you can find those values in your `.\u002Fazure\u002F{env name}\u002F.env` file. This will populate their azd environment's .env file with all the settings needed to run the app locally.\n1. Run `pwsh .\u002Fscripts\u002Froles.ps1` - This will assign all of the necessary roles to the user so they can run the app locally. If they do not have the necessary permission to create roles in the subscription, then you may need to run this script for them. Just be sure to set the `AZURE_PRINCIPAL_ID` environment variable in the azd .env file or in the active shell to their Azure Id, which they can get with `az account show`.\n\n#### Clean up resources\n\nRun `azd down`\n\n### Using the app\n\n- In Azure: navigate to the Azure Container App deployed by `azd`. The URL is printed out when `azd` completes (as \"Endpoint\"), or you can find it in the Azure portal.\n- When running locally, navigate to \u003Chttp:\u002F\u002Flocalhost:7181> for the client app and \u003Chttp:\u002F\u002Flocalhost:7181\u002Fswagger> for the Open API server page.\n\nOnce in the web app:\n\n- On the **Voice Chat** page, select the voice settings dialog and configure text-to-speech preferences.\n  - You can either type messages to interact with Blazor Clippy, or select the Speak toggle button to use speech-to-text as your input.\n- Try different topics in **Chat** context. For chat, try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.\n- Explore citations and sources\n- Click on the \"settings\" icon to try different options, tweak prompts, etc.\n\n## Enabling optional features\n\n### Enabling Application Insights\n\nTo enable Application Insights and the tracing of each request, along with the logging of errors, set the `AZURE_USE_APPLICATION_INSIGHTS` variable to true before running `azd up`\n\n1. Run `azd env set AZURE_USE_APPLICATION_INSIGHTS true`\n1. Run `azd up`\n\nTo see the performance data, go to the Application Insights resource in your resource group, click on the \"Investigate -> Performance\" blade and navigate to any HTTP request to see the timing data.\nTo inspect the performance of chat requests, use the \"Drill into Samples\" button to see end-to-end traces of all the API calls made for any chat request:\n\n![Tracing screenshot](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_754e6587b9d0.png)\n\nTo see any exceptions and server errors, navigate to the \"Investigate -> Failures\" blade and use the filtering tools to locate a specific exception. You can see Python stack traces on the right-hand side.\n\n### Enabling authentication\n\nBy default, the deployed Azure container app will have no authentication or access restrictions enabled, meaning anyone with routable network access to the container app can chat with your indexed data.  You can require authentication to your Azure Active Directory by following the [Add container app authentication](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcontainer-apps\u002Fauthentication-azure-active-directory) tutorial and set it up against the deployed container app.\n\nTo then limit access to a specific set of users or groups, you can follow the steps from [Restrict your Azure AD app to a set of users](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Factive-directory\u002Fdevelop\u002Fhowto-restrict-your-app-to-a-set-of-users) by changing \"Assignment Required?\" option under the Enterprise Application, and then assigning users\u002Fgroups access.  Users not granted explicit access will receive the error message -AADSTS50105: Your administrator has configured the application \u003Capp_name> to block users unless they are specifically granted ('assigned') access to the application.-\n\n### Enable vision (multi-modal) support\n\nWith `GPT-4o-mini`, it's possible to support an enrichmented retrival augmented generation by providing both text and image as source content. To enable vision support, you need to enable `USE_VISION` and use `GPT-4o` or `GPT-4o-mini` model when provisioning.\n\n> [!NOTE]\n> You would need to re-indexing supporting material and re-deploy the application after enabling GPT-4o support if you have already deployed the application before. This is because enabling GPT-4o support requires new fields to be added to the search index.\n\nTo enable GPT-4V support with Azure OpenAI Service, run the following commands:\n\n```bash\nazd env set USE_VISION true\nazd env set USE_AOAI true\nazd env set AZURE_OPENAI_CHATGPT_MODEL_NAME gpt-4o-mini\nazd env set AZURE_OPENAI_RESOURCE_LOCATION eastus # Please check the gpt model availability for more details.\nazd up\n```\n\nTo enable vision support with OpenAI, run the following commands:\n\n```bash\nazd env set USE_VISION true\nazd env set USE_AOAI false\nazd env set OPENAI_CHATGPT_DEPLOYMENT gpt-4o\nazd up\n```\n\nTo clean up previously deployed resources, run the following command:\n\n```bash\nazd down --purge\nazd env set AZD_PREPDOCS_RAN false # This is to ensure that the documents are re-indexed with the new fields.\n```\n\n## Guidance\n\nBesides the tips below, you can find extensive documentation in the [docs](.\u002Fdocs) folder.\n\n### Productionizing\n\nThis sample is designed to be a starting point for your own production application,\nbut you should do a thorough review of the security and performance before deploying\nto production. Here are some things to consider:\n\n- **OpenAI Capacity**: The default TPM (tokens per minute) is set to 30K. That is equivalent to approximately 30 conversations per minute (assuming 1K per user message\u002Fresponse). You can increase the capacity by changing the `chatGptDeploymentCapacity` and `embeddingDeploymentCapacity` parameters in `infra\u002Fmain.bicep` to your account's maximum capacity. You can also view the Quotas tab in [Azure OpenAI studio](https:\u002F\u002Foai.azure.com\u002F) to understand how much capacity you have.\n\n- **Azure Storage**: The default storage account uses the `Standard_LRS` SKU. To improve your resiliency, we recommend using `Standard_ZRS` for production deployments, which you can specify using the `sku` property under the `storage` module in `infra\u002Fmain.bicep`.\n\n- **Azure AI Search**: If you see errors about search service capacity being exceeded, you may find it helpful to increase the number of replicas by changing `replicaCount` in `infra\u002Fcore\u002Fsearch\u002Fsearch-services.bicep` or manually scaling it from the Azure Portal.\n\n- **Azure Container Apps**: By default, this application deploys containers with 0.5 CPU Cores and 1GB of memory. The minimum replicas is 1 and maximum 10. For this app, you can set values such as `containerCpuCoreCount`, `containerMaxReplicas `, `containerMemory`, `containerMinReplicas` in the `infra\u002Fcore\u002Fhost\u002Fcontainer-app.bicep` file to fit your needs. You can use auto-scaling rules or scheduled scaling rules, and scale up the [maximum\u002Fminimum](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcontainer-apps\u002Fscale-app) based on load.\n\n- **Authentication**: By default, the deployed app is publicly accessible. We recommend restricting access to authenticated users. See [Enabling authentication](#enabling-authentication) above for how to enable authentication.\n\n- **Networking**: We recommend deploying inside a Virtual Network. If the app is only for internal enterprise use, use a private DNS zone. Also consider using Azure API Management (APIM) for firewalls and other forms of protection. For more details, read [Azure OpenAI Landing Zone reference architecture](https:\u002F\u002Ftechcommunity.microsoft.com\u002Ft5\u002Fazure-architecture-blog\u002Fazure-openai-landing-zone-reference-architecture\u002Fba-p\u002F3882102).\n\n- **Loadtesting**: We recommend running a loadtest for your expected number of users.\n\n- **Stream tokens to web clients**: Consider using SignalR library which allows bi-directional communication between clients and server. You can easily reuse the single persistent connection for streaming down tokens to clients and receiving signals from them. SignalR simplifies implementing common features in AI chatbot, such as token cancellation. When leveraging [Azure SignalR service](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fazure-signalr\u002Fsignalr-overview), you can easily scale to 1M connections. Additionally, Azure SignalR fits nicely in a serverless deployment, providing a cost-efficient solution without worrying about server management. Refer to the [signalr branch](https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Ftree\u002Fsignalr) for code sample.\n\n### Resources\n\n- [Revolutionize your Enterprise Data with ChatGPT: Next-gen Apps w\u002F Azure OpenAI and Azure AI Search](https:\u002F\u002Faka.ms\u002Fentgptsearchblog)\n- [Azure AI Search](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fsearch\u002Fsearch-what-is-azure-search)\n- [Azure OpenAI Service](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcognitive-services\u002Fopenai\u002Foverview)\n- [`Azure.AI.OpenAI` NuGet package](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FAzure.AI.OpenAI)\n- [Original Blazor App](https:\u002F\u002Fgithub.com\u002FIEvangelist\u002Fblazor-azure-openai)\n\n> [!NOTE]\u003Cbr>\n> The PDF documents used in this demo contain information generated using a language model (Azure OpenAI Service). The information contained in these documents is only for demonstration purposes and does not reflect the opinions or beliefs of Microsoft. Microsoft makes no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information contained in this document. All rights reserved to Microsoft.\n\n### FAQ\n\n**_Question_**: Why do we need to break up the PDFs into chunks when Azure AI Search supports searching large documents?\n\n**_Answer_**: Chunking allows us to limit the amount of information we send to OpenAI due to token limits. By breaking up the content, it allows us to easily find potential chunks of text that we can inject into OpenAI. The method of chunking we use leverages a sliding window of text such that sentences that end one chunk will start the next. This allows us to reduce the chance of losing the context of the text.\n","---\npage_type: 示例\nlanguages:\n- azdeveloper\n- csharp\n- html\n- bicep\nproducts:\n- ai-services\n- azure-blob-storage\n- azure-container-apps\n- azure-cognitive-search\n- azure-openai\n- aspnet-core\n- blazor\n- defender-for-cloud\n- azure-monitor\n- dotnet-maui\nurlFragment: azure-search-openai-demo-csharp\nname: ChatGPT + 企业数据 (csharp)\ndescription: 一个使用 OpenAI 和 AI 搜索与您的数据对话的 C# 示例应用。\n---\n\u003C!-- YAML 前置内容模式：https:\u002F\u002Freview.learn.microsoft.com\u002Fen-us\u002Fhelp\u002Fcontribute\u002Fsamples\u002Fprocess\u002Fonboarding?branch=main#supported-metadata-fields-for-readmemd -->\n\n## 目录\n\n- [功能](#features)\n- [应用程序架构](#application-architecture)\n- [Azure 账户要求](#account-requirements)\n- [开始使用](#getting-started)\n  - [成本估算](#cost-estimation)\n  - [项目设置](#project-setup)\n    - [GitHub Codespaces](#github-codespaces)\n    - [VS Code 远程容器](#vs-code-remote-containers)\n    - [本地环境](#local-environment)\n  - [部署](#deployment)\n    - [从头开始部署](#deploying-from-scratch)\n    - [使用现有 Azure 资源部署](#use-existing-resources)\n    - [再次部署](#deploying-or-re-deploying-a-local-clone-of-the-repo)\n    - [使用 App Spaces 部署](#deploying-your-repo-using-app-spaces)\n    - [本地运行](#running-locally)\n    - [共享环境](#sharing-environments)\n    - [清理资源](#clean-up-resources)\n  - [使用应用程序](#using-the-app)\n- [启用可选功能](#enabling-optional-features)\n  - [启用 Application Insights](#enabling-optional-features)\n  - [启用身份验证](#enabling-authentication)\n  - [启用 GPT-4V 支持](#enable-gpt-4v-support)\n- [指导](#guidance) \n  - [生产化](#productionizing)\n  - [资源](#resources)\n  - [常见问题](#faq)\n\n# 使用 Azure OpenAI 和 Azure AI 搜索的 ChatGPT + 企业数据 (.NET)\n\n![GitHub 工作流状态](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Factions\u002Fworkflow\u002Fstatus\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fdotnet-build.yml?label=BUILD%20%26%20TEST&logo=github&style=for-the-badge)\n[![在 GitHub - Codespaces 中打开](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https:\u002F\u002Fgithub.com\u002Fcodespaces\u002Fnew?hide_repo_select=true&ref=main&repo=624102171&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)\n[![在 Remote - Containers 中打开](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https:\u002F\u002Fvscode.dev\u002Fredirect?url=vscode:\u002F\u002Fms-vscode-remote.remote-containers\u002FcloneInVolume?url=https:\u002F\u002Fgithub.com\u002Fazure-samples\u002Fazure-search-openai-demo-csharp)\n\n本示例演示了如何使用检索增强生成模式，在您自己的数据上构建类似 ChatGPT 的体验。它使用 Azure OpenAI 服务访问 ChatGPT 模型 (`gpt-4o-mini`) ，并使用 Azure AI 搜索进行数据索引和检索。\n\n该仓库包含示例数据，因此您可以直接从头到尾尝试。在这个示例应用程序中，我们使用一家名为 Contoso Electronics 的虚构公司，该体验允许其员工询问有关福利、内部政策以及职位描述和角色的问题。\n\n![RAG 架构](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_716da11a32af.png)\n\n有关此应用程序构建方式的更多详细信息，请参阅：\n\n- [利用 Azure 和 ChatGPT 提供支持的智能 .NET 应用程序改变您的业务博客文章](https:\u002F\u002Faka.ms\u002Fbuild-dotnet-ai-blog)\n- [使用 .NET 和 Azure 构建智能应用程序 - Build 会议](https:\u002F\u002Fbuild.microsoft.com\u002Fsessions\u002Ff8f953f3-2e58-4535-92ae-5cb30ef2b9b0)\n\n我们很想听听您的意见！您是否有兴趣构建或目前正在构建智能应用程序？请花几分钟时间完成这份调查问卷。\n\n[**参与调查**](https:\u002F\u002Faka.ms\u002Fdotnet-build-oai-survey)\n\n## 功能\n\n- 语音聊天、聊天和问答界面\n- 探索多种选项，帮助用户通过引用、源内容跟踪等方式评估响应的可信度\n- 展示数据准备、提示构造以及模型 (ChatGPT) 和检索器 (Azure AI 搜索) 之间交互编排的可能方法\n- 在用户体验中直接提供设置，以调整行为并试验不同选项\n\n![聊天界面](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_8457361e9517.png)\n\n## 应用程序架构\n\n- **用户界面** - 应用程序的聊天界面是一个 [Blazor WebAssembly](https:\u002F\u002Flearn.microsoft.com\u002Faspnet\u002Fcore\u002Fblazor\u002F) 应用程序。该界面负责接收用户查询、将请求路由到应用程序后端，并显示生成的响应。\n- **后端** - 应用程序后端是 [ASP.NET Core Minimal API](https:\u002F\u002Flearn.microsoft.com\u002Faspnet\u002Fcore\u002Ffundamentals\u002Fminimal-apis\u002Foverview)。后端托管 Blazor 静态 Web 应用程序，并负责协调不同服务之间的交互。本应用程序中使用的服务包括：\n   - [**Azure AI 搜索**](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fsearch\u002Fsearch-what-is-azure-search) – 将存储在 Azure 存储帐户中的文档编制索引。这使得文档能够使用 [向量搜索](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fsearch\u002Fsearch-get-started-vector) 功能进行搜索。\n   - [**Azure OpenAI 服务**](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fai-services\u002Fopenai\u002Foverview) – 提供大型语言模型来生成响应。[Semantic Kernel](https:\u002F\u002Flearn.microsoft.com\u002Fsemantic-kernel\u002Fwhatissk) 与 Azure OpenAI 服务结合使用，用于编排更复杂的 AI 工作流。\n\n## 开始使用\n\n### 账户要求\n\n为了部署和运行本示例，您需要\n\n- **Azure 账户** - 如果您是 Azure 新手，请获取一个 [免费 Azure 账户](https:\u002F\u002Faka.ms\u002Ffree)，您将获得一些免费的 Azure 积分以开始使用。\n- **Azure 账户权限** - 您的 Azure 账户必须具有 `Microsoft.Authorization\u002FroleAssignments\u002Fwrite` 权限，例如 [用户访问管理员](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Frole-based-access-control\u002Fbuilt-in-roles#user-access-administrator) 或 [所有者](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Frole-based-access-control\u002Fbuilt-in-roles#owner)。\n\n> [!警告]\u003Cbr>\n> 默认情况下，本示例将创建每月会产生费用的 Azure 容器应用和 Azure AI 搜索资源，以及按文档页数计费的 Azure AI 文档智能资源。如果您想避免这些费用，可以通过更改 infra 文件夹下的参数文件将其切换为免费版本（不过需要注意一些限制；例如，每个订阅最多只能有一个免费的 Azure AI 搜索资源，而免费的 Azure AI 文档智能资源仅分析每份文档的前两页。)\n\n### 成本估算\n\n定价因地区和使用情况而异，因此无法准确预测您的具体费用。不过，您可以使用 [Azure 定价计算器](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fcalculator\u002F) 来估算以下资源的成本：\n\n- [**Azure 容器应用**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fcontainer-apps\u002F)。环境类型：仅按使用量计费。该解决方案使用按使用量计费计划，因为我们没有特定的硬件要求。\n- [**Azure OpenAI 服务**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fcognitive-services\u002Fopenai-service\u002F)。标准层，GPT 和 Ada 模型。按每 1,000 个 token 的用量计费，且每个问题至少会使用 1,000 个 token。\n- [**Azure AI 文档智能**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fai-document-intelligence\u002F)。使用预构建布局的 SO（标准）层。按文档页数计费，示例文档共有 261 页。\n- [**Azure AI 搜索**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fsearch\u002F) 基本层，1 个副本，免费语义搜索级别。按小时计费。\n- [**Azure Blob 存储**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fstorage\u002Fblobs\u002F)。标准层，采用 ZRS（区域冗余存储）。按存储和读取操作计费。\n- [**Azure Monitor**](https:\u002F\u002Fazure.microsoft.com\u002Fpricing\u002Fdetails\u002Fmonitor\u002F)。按需付费层。费用基于所摄入的数据。\n\n为了降低成本，您可以切换到各种服务的免费 SKU，但这些 SKU 存在限制。有关更多详细信息，请参阅此[低成本部署指南](.\u002Fdocs\u002Fdeploy_lowcost.md)。\n\n⚠️ 为避免不必要的成本，请务必在不再使用应用程序时将其关闭，方法是在门户中删除资源组，或运行 `azd down`。\n\n### 项目设置\n\n您有几种方式可以设置该项目。最简单的方式是使用 GitHub Codespaces，因为它会为您自动配置所有工具，但如果您愿意，也可以在本地进行设置。\n\n#### GitHub Codespaces\n\n您可以通过 GitHub Codespaces 虚拟运行此仓库，它将在您的浏览器中打开一个基于 Web 的 VS Code：\n\n[![在 GitHub - Codespaces 中打开](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=brightgreen&logo=github)](https:\u002F\u002Fgithub.com\u002Fcodespaces\u002Fnew?hide_repo_select=true&ref=main&repo=624102171&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=WestUs2)\n\n#### VS Code 远程容器\n\n另一种相关选项是 VS Code 远程容器，它将使用 [Dev Containers](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=ms-vscode-remote.remote-containers) 扩展，在您的本地 VS Code 中打开该项目：\n\n[![在远程 - 容器中打开](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?style=for-the-badge&label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https:\u002F\u002Fvscode.dev\u002Fredirect?url=vscode:\u002F\u002Fms-vscode-remote.remote-containers\u002FcloneInVolume?url=https:\u002F\u002Fgithub.com\u002Fazure-samples\u002Fazure-search-openai-demo-csharp)\n\n#### 本地环境\n\n请安装以下先决条件：\n\n- [Azure 开发者 CLI](https:\u002F\u002Faka.ms\u002Fazure-dev\u002Finstall)\n- [.NET 8](https:\u002F\u002Fdotnet.microsoft.com\u002Fdownload\u002Fdotnet\u002F8.0)\n- [Git](https:\u002F\u002Fgit-scm.com\u002Fdownloads)\n- [Powershell 7+ (pwsh)](https:\u002F\u002Fgithub.com\u002Fpowershell\u002Fpowershell) - 仅适用于 Windows 用户。\n  \n   > **重要提示**:\n   > 确保您可以在 PowerShell 命令行中运行 `pwsh.exe`。如果失败，您可能需要升级 PowerShell。\n\n- [Docker](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F)\n\n   > **重要提示**:\n   > 在运行任何 `azd` 配置或部署命令之前，请确保 Docker 已启动并正在运行。\n\n然后，运行以下命令以在您的本地环境中获取该项目：\n\n   1. 运行 `azd auth login`\n   1. 克隆仓库或运行 `azd init -t azure-search-openai-demo-csharp`\n   1. 运行 `azd env new azure-search-openai-demo-csharp`\n\n### 部署\n\n#### 从头开始部署\n\n[📺 直播：在 Codespaces 中从头开始部署](https:\u002F\u002Fyoutu.be\u002FTORUsRNimM0)\n[📺 直播：在 Windows 11 中从头开始部署](https:\u002F\u002Fyoutu.be\u002FwgSnkxGH2Sk?si=C4zAbLKhK3LoAS43)\n\n> **重要提示**:\n> 在运行任何 `azd` 配置或部署命令之前，请确保 Docker 已启动并正在运行。\n\n如果您没有任何现有的 Azure 服务，并希望从头开始部署，请执行以下命令：\n\n   1. 运行 `azd up` - 此命令将配置 Azure 资源并将示例部署到这些资源上，包括根据 `.\u002Fdata` 文件夹中的文件构建搜索索引。\n   - 对于目标位置，目前支持本示例中使用的模型的区域是 **美国东部**。有关最新区域和模型列表，请查看 [此处](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcognitive-services\u002Fopenai\u002Fconcepts\u002Fmodels)。\n   - 如果您有权访问多个 Azure 订阅，系统将提示您选择要使用的订阅。如果您只有一份订阅权限，则会自动选择该订阅。\n\n   > **注释**:\n   > 本应用程序使用 `gpt-4o-mini` 模型。在选择部署区域时，请确保该区域支持此模型（即美国东部）。更多信息请参阅 [Azure OpenAI 服务文档](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fai-services\u002Fopenai\u002Fconcepts\u002Fmodels#standard-deployment-model-availability)。\n\n   1. 应用程序成功部署后，控制台将显示一个 URL。单击该 URL 即可在浏览器中与应用程序交互。\n\n输出将如下所示：\n\n!['Output from running azd up'](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_89594710ce48.png)\n\n> [!注意]:\n> 应用程序完全部署可能需要几分钟时间。\n> 部署完成后，还需要几分钟来处理要添加到向量数据库中的文档。\n\n#### 使用现有资源\n\n如果您已在 Azure 中拥有想要使用的资源，可以通过设置以下 `azd` 环境变量来配置 `azd` 使用这些资源：\n\n   1. 运行 `azd env set AZURE_OPENAI_SERVICE {现有 OpenAI 服务名称}`\n   1. 运行 `azd env set AZURE_OPENAI_RESOURCE_GROUP {OpenAI 服务所在的现有资源组名称}`\n   1. 运行 `azd env set AZURE_OPENAI_CHATGPT_DEPLOYMENT {现有 ChatGPT 部署名称}`。仅当您的 ChatGPT 部署不是默认的 'chat' 时才需要。\n   1. 运行 `azd env set AZURE_OPENAI_EMBEDDING_DEPLOYMENT {现有嵌入模型部署名称}`。仅当您的嵌入模型部署不是默认的 `embedding` 时才需要。\n   1. 运行 `azd up`\n\n> [!注意]\u003Cbr> \n> 您还可以使用现有的搜索和存储账户。有关要传递给 `azd env set` 以配置这些现有资源的环境变量列表，请参阅 `.\u002Finfra\u002Fmain.parameters.json`。\n\n#### 部署或重新部署本地克隆的仓库\n\n> [!重要]\u003Cbr>\n> 在运行任何 `azd` 配置或部署命令之前，请确保 Docker 已启动并正在运行。\n\n- 运行 `azd up`\n\n#### 使用 App Spaces 部署您的仓库\n\n> [!NOTE]\u003Cbr>\n> 确保您的仓库中包含 AZD 支持的 Bicep 文件，并添加一个初始的 GitHub Actions 工作流文件。该工作流可以手动触发（用于首次部署）或在代码更改时自动触发（使用最新更改重新部署）。\n> 为使您的仓库与 App Spaces 兼容，您需要修改主 Bicep 文件和主参数文件，以允许 AZD 部署到具有相应标签的现有资源组。\n\n1. 在主参数文件中添加 `AZURE_RESOURCE_GROUP`，以便从 App Spaces 在 GitHub Actions 工作流文件中设置的环境变量中读取值。\n   ```json\n   \"resourceGroupName\": {\n      \"value\": \"${AZURE_RESOURCE_GROUP}\"\n    }\n   ```\n2. 在主参数文件中添加 `AZURE_TAGS`，以便从 App Spaces 在 GitHub Actions 工作流文件中设置的环境变量中读取值。\n   ```json\n   \"tags\": {\n      \"value\": \"${AZURE_TAGS}\"\n    }\n   ```\n3. 在主 Bicep 文件中添加对资源组和标签的支持，以读取由 App Spaces 设置的值。\n   ```bicep\n   param resourceGroupName string = ''\n   param tags string = ''\n   ```\n4. 将 Azd 设置的默认标签与 App Spaces 设置的标签合并。将主 Bicep 文件中的 _tags 初始化_ 替换为以下内容：\n   ````bicep\n   var baseTags = { 'azd-env-name': environmentName }\n   var updatedTags = union(empty(tags) ? {} : base64ToJson(tags), baseTags)\n   使用 \"updatedTags\" 为 Bicep 文件中创建的资源组分配 \"tags\"，并将其他资源更新为使用 \"baseTags\" 而不是 \"tags\"。例如：\n   ```json\n   resource rg 'Microsoft.Resources\u002FresourceGroups@2021-04-01' = {\n     name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'\n     location: location\n     tags: updatedTags\n   }\n   ````\n\n#### 本地运行\n\n> [!IMPORTANT]\u003Cbr>\n> 在运行任何 `azd` 配置\u002F部署命令之前，请确保 Docker 已启动并正在运行。\n\n1. 运行 `azd auth login`\n1. 应用程序部署完成后，设置环境变量 `AZURE_KEY_VAULT_ENDPOINT`。您可以在 _.azure\u002FYOUR-ENVIRONMENT-NAME\u002F.env_ 文件或 Azure 门户中找到该值。\n1. 运行以下 .NET CLI 命令以启动 ASP.NET Core Minimal API 服务器（客户端主机）：\n\n   ```dotnetcli\n   dotnet run --project .\u002Fapp\u002Fbackend\u002FMinimalApi.csproj --urls=http:\u002F\u002Flocalhost:7181\u002F\n   ```\n\n导航至 \u003Chttp:\u002F\u002Flocalhost:7181>,测试应用程序。\n\n#### 使用 .NET MAUI 客户端本地运行\n\n此示例包含一个 .NET MAUI 客户端，将体验打包成可在 Windows\u002FmacOS 桌面以及 Android 和 iOS 设备上运行的应用程序。这里的 MAUI 客户端使用 Blazor 混合实现，使其能够与网站前端共享大部分代码。\n\n1. 打开 _app\u002Fapp-maui.sln_ 以打开包含 MAUI 客户端的解决方案\n1. 编辑 _app\u002Fmaui-blazor\u002FMauiProgram.cs_，将 `client.BaseAddress` 更新为后端的 URL。\n   如果是在 Azure 上运行，则使用上述步骤中的服务后端 URL；如果是在本地运行，则使用 \u003Chttp:\u002F\u002Flocalhost:7181>。\n1. 将 **MauiBlazor** 设置为启动项目并运行应用程序\n\n#### 共享环境\n\n如果您想让其他人访问已部署的现有环境，请执行以下操作：\n\n1. 安装 [Azure CLI](https:\u002F\u002Flearn.microsoft.com\u002Fcli\u002Fazure\u002Finstall-azure-cli)\n1. 运行 `azd init -t azure-search-openai-demo-csharp`\n1. 运行 `azd env refresh -e {environment name}` - 请注意，他们需要 azd 环境名称、订阅 ID 和位置才能运行此命令，这些信息可在您的 `.\u002Fazure\u002F{env name}\u002F.env` 文件中找到。这将填充他们的 azd 环境的 .env 文件，包含在本地运行应用程序所需的所有设置。\n1. 运行 `pwsh .\u002Fscripts\u002Froles.ps1` - 这将为用户分配所有必要的角色，以便他们能够在本地运行应用程序。如果他们没有在订阅中创建角色的权限，则可能需要您代为运行此脚本。只需确保在 azd .env 文件或当前 shell 中将 `AZURE_PRINCIPAL_ID` 环境变量设置为用户的 Azure ID，该 ID 可通过 `az account show` 获取。\n\n#### 清理资源\n\n运行 `azd down`\n\n\n\n### 使用应用程序\n\n- 在 Azure 中：导航至由 `azd` 部署的 Azure 容器应用。URL 会在 `azd` 完成时打印出来（显示为“Endpoint”），或者您也可以在 Azure 门户中找到它。\n- 在本地运行时，导航至 \u003Chttp:\u002F\u002Flocalhost:7181> 访问客户端应用程序，以及 \u003Chttp:\u002F\u002Flocalhost:7181\u002Fswagger> 访问 Open API 服务器页面。\n\n进入 Web 应用程序后：\n\n- 在 **语音聊天** 页面上，选择语音设置对话框并配置文本转语音偏好。\n  - 您可以输入消息与 Blazor Clippy 互动，或选择“Speak”切换按钮以使用语音转文本作为输入。\n- 尝试不同的 **聊天** 主题。对于聊天，您可以尝试提出后续问题、澄清疑问、要求简化或详细说明答案等。\n- 探索引用和来源\n- 单击“设置”图标以尝试不同选项、调整提示等。\n\n## 启用可选功能\n\n### 启用 Application Insights\n\n要启用 Application Insights 并跟踪每个请求以及记录错误，请在运行 `azd up` 之前将 `AZURE_USE_APPLICATION_INSIGHTS` 变量设置为 true。\n\n1. 运行 `azd env set AZURE_USE_APPLICATION_INSIGHTS true`\n1. 运行 `azd up`\n\n要查看性能数据，前往您资源组中的 Application Insights 资源，单击“Investigate -> Performance”面板，然后导航到任意 HTTP 请求以查看计时数据。\n要检查聊天请求的性能，使用“Drill into Samples”按钮查看针对任何聊天请求所进行的所有 API 调用的端到端跟踪记录：\n\n![追踪截图](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_readme_754e6587b9d0.png)\n\n要查看任何异常和服务器错误，导航到“Investigate -> Failures”面板，并使用筛选工具定位特定异常。您可以在右侧看到 Python 堆栈跟踪。\n\n### 启用身份验证\n\n默认情况下，部署的 Azure 容器应用不会启用任何身份验证或访问限制，这意味着任何具有可路由网络访问权限的人都可以与您索引的数据进行对话。您可以通过遵循 [添加容器应用身份验证](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcontainer-apps\u002Fauthentication-azure-active-directory) 教程，并将其配置到已部署的容器应用上，来要求使用 Azure Active Directory 进行身份验证。\n\n要将访问权限限制为特定用户或组，您可以按照 [将 Azure AD 应用程序限制为一组用户](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Factive-directory\u002Fdevelop\u002Fhowto-restrict-your-app-to-a-set-of-users) 中的步骤操作：在企业应用程序中更改“是否需要分配？”选项，然后为用户\u002F组分配访问权限。未被明确授予访问权限的用户将收到错误消息 -AADSTS50105: 您的管理员已将应用程序 \u003Capp_name> 配置为阻止用户访问，除非他们被特别授予（“分配”）对该应用程序的访问权限。-\n\n### 启用视觉（多模态）支持\n\n借助 `GPT-4o-mini`，可以通过同时提供文本和图像作为源内容，实现增强的检索增强生成。要启用视觉支持，您需要在预配时启用 `USE_VISION` 并使用 `GPT-4o` 或 `GPT-4o-mini` 模型。\n\n> [!注意]\n> 如果您之前已经部署了应用程序，在启用 GPT-4o 支持后，您需要重新索引支持材料并重新部署应用程序。这是因为启用 GPT-4o 支持需要向搜索索引中添加新字段。\n\n要通过 Azure OpenAI 服务启用 GPT-4V 支持，请运行以下命令：\n\n```bash\nazd env set USE_VISION true\nazd env set USE_AOAI true\nazd env set AZURE_OPENAI_CHATGPT_MODEL_NAME gpt-4o-mini\nazd env set AZURE_OPENAI_RESOURCE_LOCATION eastus # 请查看 GPT 模型的可用性以获取更多详细信息。\nazd up\n```\n\n要通过 OpenAI 启用视觉支持，请运行以下命令：\n\n```bash\nazd env set USE_VISION true\nazd env set USE_AOAI false\nazd env set OPENAI_CHATGPT_DEPLOYMENT gpt-4o\nazd up\n```\n\n要清理之前部署的资源，请运行以下命令：\n\n```bash\nazd down --purge\nazd env set AZD_PREPDOCS_RAN false # 这是为了确保文档会使用新字段重新索引。\n```\n\n## 指导\n\n除了以下提示外，您还可以在 [docs](.\u002Fdocs) 文件夹中找到详细的文档。\n\n### 生产环境部署\n\n本示例旨在作为您自己的生产应用程序的起点，但在部署到生产环境之前，您应全面审查安全性和性能。以下是一些需要考虑的事项：\n\n- **OpenAI 容量**：默认的 TPM（每分钟令牌数）设置为 3 万。这相当于大约每分钟 30 次对话（假设每位用户的消息\u002F回复约为 1 千个令牌）。您可以根据自己的账户最大容量，通过更改 `infra\u002Fmain.bicep` 中的 `chatGptDeploymentCapacity` 和 `embeddingDeploymentCapacity` 参数来提高容量。您也可以在 [Azure OpenAI Studio](https:\u002F\u002Foai.azure.com\u002F) 的“配额”选项卡中查看自己拥有的容量。\n\n- **Azure 存储**：默认存储帐户使用的是 `Standard_LRS` SKU。为了提高系统的容错能力，我们建议在生产部署中使用 `Standard_ZRS`，您可以在 `infra\u002Fmain.bicep` 中的 `storage` 模块下使用 `sku` 属性进行指定。\n\n- **Azure AI 搜索**：如果您遇到有关搜索服务容量超限的错误，可以尝试通过更改 `infra\u002Fcore\u002Fsearch\u002Fsearch-services.bicep` 中的 `replicaCount` 来增加副本数量，或者直接从 Azure 门户手动扩展。\n\n- **Azure 容器应用**：默认情况下，此应用程序部署的容器具有 0.5 个 CPU 核心和 1GB 内存。最小副本数为 1，最大为 10。对于此应用程序，您可以根据需求在 `infra\u002Fcore\u002Fhost\u002Fcontainer-app.bicep` 文件中设置 `containerCpuCoreCount`、`containerMaxReplicas`、`containerMemory` 和 `containerMinReplicas` 等参数。您还可以使用自动缩放规则或计划性缩放规则，并根据负载情况调整 [最大\u002F最小](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcontainer-apps\u002Fscale-app) 副本数。\n\n- **身份验证**：默认情况下，部署的应用程序是公开可访问的。我们建议将访问权限限制为经过身份验证的用户。有关如何启用身份验证，请参阅上方的 [启用身份验证](#enabling-authentication) 部分。\n\n- **网络**：我们建议在虚拟网络内部署应用程序。如果应用程序仅供企业内部使用，则应使用专用 DNS 区域。此外，还可以考虑使用 Azure API 管理 (APIM) 来实现防火墙和其他形式的保护措施。有关更多信息，请参阅 [Azure OpenAI 登陆区参考架构](https:\u002F\u002Ftechcommunity.microsoft.com\u002Ft5\u002Fazure-architecture-blog\u002Fazure-openai-landing-zone-reference-architecture\u002Fba-p\u002F3882102)。\n\n- **负载测试**：我们建议针对预期的用户数量运行负载测试。\n\n- **向 Web 客户端流式传输令牌**：可以考虑使用 SignalR 库，它允许客户端与服务器之间的双向通信。您可以轻松地复用单个持久连接来向客户端流式传输令牌，并接收来自客户端的信号。SignalR 简化了在 AI 聊天机器人中实现常见功能的过程，例如取消令牌发送。当使用 [Azure SignalR 服务](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fazure-signalr\u002Fsignalr-overview) 时，它可以轻松扩展到 100 万个连接。此外，Azure SignalR 非常适合无服务器部署，提供了一种经济高效的解决方案，无需担心服务器管理问题。有关代码示例，请参阅 [signalr 分支](https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Ftree\u002Fsignalr)。\n\n### 资源\n\n- [利用 ChatGPT 彻底革新您的企业数据：基于 Azure OpenAI 和 Azure AI 搜索的新一代应用程序](https:\u002F\u002Faka.ms\u002Fentgptsearchblog)\n- [Azure AI 搜索](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fsearch\u002Fsearch-what-is-azure-search)\n- [Azure OpenAI 服务](https:\u002F\u002Flearn.microsoft.com\u002Fazure\u002Fcognitive-services\u002Fopenai\u002Foverview)\n- [`Azure.AI.OpenAI` NuGet 包](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FAzure.AI.OpenAI)\n- [原始 Blazor 应用程序](https:\u002F\u002Fgithub.com\u002FIEvangelist\u002Fblazor-azure-openai)\n\n> [!注意]\u003Cbr>\n> 本演示中使用的 PDF 文档包含使用语言模型（Azure OpenAI 服务）生成的信息。这些文档中的信息仅用于演示目的，并不反映 Microsoft 的观点或信念。Microsoft 对本文档中所含信息的完整性、准确性、可靠性、适用性或可用性不作任何明示或暗示的陈述或保证。所有权利归 Microsoft 所有。\n\n### 常见问题解答\n\n**_问题_**: 为什么在 Azure AI 搜索支持搜索大型文档的情况下，我们还需要将 PDF 文件拆分成块？\n\n**_回答_**: 拆分文本块是为了应对 OpenAI 的令牌限制，从而控制每次发送给 OpenAI 的信息量。通过将内容拆分成块，我们可以更方便地找到适合注入 OpenAI 的文本片段。我们采用的拆分方法使用滑动窗口技术：前一个块末尾的句子会成为下一个块的开头。这样可以有效降低丢失文本上下文的风险。","# azure-search-openai-demo-csharp 快速上手指南\n\n本指南帮助中国开发者快速部署基于 .NET 的\"ChatGPT + 企业数据”示例应用。该应用利用 Azure OpenAI Service 和 Azure AI Search，实现基于私有数据的检索增强生成（RAG）对话体验。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n### 系统要求\n- **操作系统**：Windows 10\u002F11, macOS, 或 Linux\n- **Azure 账号**：需拥有有效的 Azure 订阅，且账号具备 `Microsoft.Authorization\u002FroleAssignments\u002Fwrite` 权限（如“用户访问管理员”或“所有者”角色）。\n  > **注意**：默认部署会创建产生费用的资源（如 Azure Container Apps, Azure AI Search 等）。若需降低成本，可参考官方文档修改配置以使用免费层级（有限额）。\n\n### 前置依赖\n请安装以下工具：\n\n1. **.NET 8 SDK**\n   - 下载地址：[https:\u002F\u002Fdotnet.microsoft.com\u002Fdownload\u002Fdotnet\u002F8.0](https:\u002F\u002Fdotnet.microsoft.com\u002Fdownload\u002Fdotnet\u002F8.0)\n   - 国内加速镜像：[清华大学 .NET 镜像](https:\u002F\u002Fmirrors.tuna.tsinghua.edu.cn\u002Fdotnet\u002F)\n\n2. **Azure Developer CLI (azd)**\n   - 安装命令 (Windows PowerShell): `powershell -ex AllSigned -c \"Invoke-RestMethod 'https:\u002F\u002Faka.ms\u002Finstall-azd.ps1' | Invoke-Expression\"`\n   - 安装命令 (Linux\u002FMac): `curl -fsSL https:\u002F\u002Faka.ms\u002Finstall-azd.sh | bash`\n   - 国内用户若下载缓慢，可尝试手动下载二进制文件并配置环境变量。\n\n3. **Git**\n   - 下载地址：[https:\u002F\u002Fgit-scm.com\u002Fdownloads](https:\u002F\u002Fgit-scm.com\u002Fdownloads)\n   - 国内加速镜像：[清华大学 Git 镜像](https:\u002F\u002Fmirrors.tuna.tsinghua.edu.cn\u002Fgit\u002F)\n\n4. **Docker Desktop**\n   - 下载地址：[https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F](https:\u002F\u002Fwww.docker.com\u002Fproducts\u002Fdocker-desktop\u002F)\n   - **重要**：在执行任何部署命令前，必须确保 Docker 引擎正在运行。\n\n5. **PowerShell 7+ (仅限 Windows 用户)**\n   - 确保可以在终端中运行 `pwsh.exe`。如果失败，请升级 PowerShell。\n\n## 安装步骤\n\n您可以选择使用 GitHub Codespaces 在线开发，或在本地环境部署。以下介绍**本地环境**的部署流程。\n\n### 1. 认证与初始化\n打开终端（Windows 推荐使用 PowerShell），执行以下命令登录 Azure 并初始化项目：\n\n```bash\n# 登录 Azure 开发者 CLI\nazd auth login\n\n# 克隆仓库并初始化环境 (或者直接 git clone 后运行下一步)\nazd init -t azure-search-openai-demo-csharp\n\n# 创建新的环境配置\nazd env new azure-search-openai-demo-csharp\n```\n\n### 2. 部署资源\n执行以下命令将应用部署到 Azure。此过程会自动创建所需的 Azure 资源（包括 AI 搜索索引、OpenAI 实例、容器应用等），并将 `.\u002Fdata` 文件夹中的示例数据（Contoso Electronics 虚构公司数据）上传并建立索引。\n\n```bash\n#  provision 资源并部署应用\nazd up\n```\n\n**部署注意事项：**\n- **区域选择**：当提示选择区域时，请选择支持 `gpt-4o-mini` 模型的区域，例如 **East US**。其他区域可能因模型不可用而导致部署失败。\n- **订阅选择**：如果您有多个订阅，系统将提示您选择；若只有一个，将自动选中。\n- **耗时**：首次部署可能需要几分钟时间，具体取决于网络状况和资源创建速度。\n\n## 基本使用\n\n部署成功后，终端会输出应用的访问地址。\n\n### 1. 访问应用\n在浏览器中打开 `azd up` 命令输出中显示的 URL（通常是以 `.azurecontainerapps.io` 结尾的地址）。\n\n### 2. 体验功能\n应用加载后，您将看到类似 ChatGPT 的界面，但背后连接的是示例企业数据：\n- **提问测试**：在对话框中输入关于\"Contoso Electronics\"公司员工福利、内部政策或职位描述的问题。\n  - 示例问题：`What are the health benefits for employees?` (员工有哪些健康福利？)\n  - 示例问题：`What is the policy on remote work?` (远程办公的政策是什么？)\n- **查看引用**：点击回答下方的引用来源，可以追踪回答依据的具体文档片段，验证回答的可信度。\n- **调整设置**：利用界面上的设置选项，微调行为参数或实验不同的提示词策略。\n\n### 3. 本地运行（可选）\n如果您希望在本地调试后端或前端，而非使用已部署的云端服务，请确保已获取相关服务的连接字符串，然后运行：\n\n```bash\n# 启动本地后端和前端\ndotnet run\n```\n*(注：本地运行通常需要手动配置 `appsettings.json` 或通过 `azd env get-values` 获取环境变量)*\n\n### 4. 清理资源\n为避免产生不必要的费用，测试完成后请及时删除资源：\n\n```bash\nazd down\n```\n确认删除操作后，所有由 `azd up` 创建的资源组将被移除。","Contoso 电子公司的 HR 团队每天需要处理大量员工关于内部福利政策、职位职责及合规流程的咨询，传统方式依赖人工检索分散的文档库。\n\n### 没有 azure-search-openai-demo-csharp 时\n- 员工提问后，HR 人员需手动在多个 PDF 和 Word 文档中关键词搜索，平均响应时间超过 30 分钟。\n- 非结构化数据（如旧版员工手册）难以被精准定位，常导致回答遗漏关键条款或提供过时信息。\n- 缺乏统一的问答界面，员工习惯通过邮件或即时通讯碎片化提问，导致重复劳动且知识无法沉淀。\n- 新入职培训期间，导师需花费大量时间反复解答基础政策问题，无法聚焦于核心业务指导。\n\n### 使用 azure-search-openai-demo-csharp 后\n- 系统利用 Azure AI Search 自动索引企业文档，结合 Azure OpenAI 实现秒级精准回答，将响应时间缩短至 5 秒内。\n- 检索增强生成（RAG）模式确保答案严格基于最新上传的政策文件，自动标注来源段落，杜绝幻觉与过时信息。\n- 提供类 ChatGPT 的统一对话界面，支持自然语言多轮追问，员工可自助解决 80% 的常规咨询，释放 HR 生产力。\n- 内置语音交互与多端支持（包括 Blazor 和 MAUI），新员工可随时通过手机或电脑获取标准化的入职指引。\n\nazure-search-openai-demo-csharp 通过将静态企业数据转化为可对话的智能知识库，显著降低了内部沟通成本并提升了信息获取的准确性。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FAzure-Samples_azure-search-openai-demo-csharp_8457361e.png","Azure-Samples","Azure Samples","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FAzure-Samples_101a6251.png","Microsoft Azure code samples and examples in .NET, Java, Python, JavaScript, TypeScript, PHP and Ruby",null,"https:\u002F\u002Flearn.microsoft.com\u002Fazure","https:\u002F\u002Fgithub.com\u002FAzure-Samples",[85,89,93,97,101,105,109,113,117],{"name":86,"color":87,"percentage":88},"C#","#178600",51.5,{"name":90,"color":91,"percentage":92},"Bicep","#519aba",27.6,{"name":94,"color":95,"percentage":96},"HTML","#e34c26",14.6,{"name":98,"color":99,"percentage":100},"Shell","#89e051",2.3,{"name":102,"color":103,"percentage":104},"CSS","#663399",1.5,{"name":106,"color":107,"percentage":108},"PowerShell","#012456",1.4,{"name":110,"color":111,"percentage":112},"JavaScript","#f1e05a",0.8,{"name":114,"color":115,"percentage":116},"Dockerfile","#384d54",0.2,{"name":118,"color":119,"percentage":120},"Smalltalk","#596706",0,827,687,"2026-04-09T13:27:54","MIT",4,"Linux, macOS, Windows","未说明",{"notes":129,"python":127,"dependencies":130},"该项目是基于 .NET (C#) 的应用，非 Python 项目。核心运行依赖包括 .NET 8 SDK、Azure Developer CLI、Git、Docker（部署前必须运行）以及 Windows 用户所需的 PowerShell 7+。应用后端使用 ASP.NET Core Minimal API，前端使用 Blazor WebAssembly。部署目标为 Azure 云环境（如 Azure Container Apps、Azure AI Search、Azure OpenAI Service），本地运行主要用于开发调试或容器化部署。默认使用 gpt-4o-mini 模型，需确保所选 Azure 区域支持该模型（如 East US）。",[131,132,133,134,135,136,137,138],".NET 8","Azure Developer CLI (azd)","Git","PowerShell 7+ (Windows 必需)","Docker","ASP.NET Core","Blazor WebAssembly","Semantic Kernel",[15],[141,142,143,144,145,146,147],"azd-templates","chatgpt","csharp","openai","dotnet","azure","ai-azd-templates","2026-03-27T02:49:30.150509","2026-04-12T07:53:58.007092",[151,156,161,166,171],{"id":152,"question_zh":153,"answer_zh":154,"source_url":155},30477,"运行 'azd up' 时构建服务 'web' 失败，提示 Docker 相关错误怎么办？","这通常是因为 Docker Desktop 未运行导致的。在执行 'azd up' 命令之前，请确保已启动 Docker Desktop。虽然该要求可能在先决条件中提到，但在每次运行部署命令前确认 Docker 正在运行是解决此问题的关键。","https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fissues\u002F106",{"id":157,"question_zh":158,"answer_zh":159,"source_url":160},30478,"部署时遇到 'text-davinci-003' 模型不再支持的错误如何解决？","Azure OpenAI 已不再支持在新部署中使用 'text-davinci-003' 模型。目前的计划是使用 Turbo 模型进行单一部署。如果遇到配额（Quota）系统变更导致的部署验证失败，可以尝试手动调整配额：\n1. 进入 Azure OpenAI Studio。\n2. 找到 'Quotas'（配额）选项卡。\n3. 将相关部署的 TPM（每分钟令牌数）滑动调整为 1K (1,000)。\n4. 保存或应用更改后重试部署。","https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fissues\u002F115",{"id":162,"question_zh":163,"answer_zh":164,"source_url":165},30479,"界面上的“上传文件”功能点击后无反应，或者上传后无法被聊天机器人检索到怎么办？","这是一个已知问题。上传功能依赖 Azure Function 来处理文档并将其拆分页面，但该函数可能尚未正确部署或触发。\n临时解决方案：不要依赖浏览器上传，而是使用本地脚本重新构建索引。可以通过 'azd' 重置跟踪 'prepdocs' 是否已运行的环境变量，然后运行本地的 'prepDocs.ps1' 或 'prepDocs.sh' 脚本来处理所有本地文件并重建索引。这样可以确保文档被正确处理并可供查询。","https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fissues\u002F150",{"id":167,"question_zh":168,"answer_zh":169,"source_url":170},30480,"执行 'azd up' 时为什么会被要求输入 'openAIApiKey' 基础设施参数？","该参数是可选的。如果提供此密钥，部署将使用现有的 OpenAI 服务；如果留空（直接回车跳过），部署流程会自动创建一个新的 Azure OpenAI 服务并使用它。因此，如果您希望自动创建资源，可以直接跳过此输入。","https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fissues\u002F318",{"id":172,"question_zh":173,"answer_zh":174,"source_url":175},30481,"部署在 Redis 容器应用阶段失败，报错 'Operation expired' 怎么办？","在最新版本的应用中，Redis 已不再用于缓存，因此该部署步骤实际上是多余的或已过时。如果遇到此错误，可以忽略与 Redis 相关的配置，或者拉取最新版本的代码，因为维护者已在后续版本中移除了对 Redis 缓存的依赖。","https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fissues\u002F108",[177,182],{"id":178,"version":179,"summary_zh":180,"released_at":181},214754,"2024-09-16","## 总览\n本次发布包含低成本部署流程、更新的 Azure AI Document Intelligence 参考文档，以及一段全新的从 Codespaces 部署的视频教程。此外，还引入了用于关闭过时问题的工作流、README 文件的更新，以及修复了 SettingsPanel.razor 中的一个拼写错误。\n\n## 变更内容\n* 添加低成本部署流程并更新 Azure AI Document Intelligence 参考文档，由 @elbruno 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F364 中完成。\n* 添加视频以说明如何从 Codespaces 进行部署，由 @elbruno 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F361 中完成。\n* 引入 GitHub 工作流以关闭过时的问题和拉取请求，由 @elbruno 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F365 中完成。\n* 更新 README 文件，在成本估算部分补充完整细节，由 @elbruno 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F366 中完成。\n* 修复 SettingsPanel.razor 中的拼写错误，由 @shribr 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F369 中完成。\n* 在 README.md 中添加“指导”主章节，由 @elbruno 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F368 中完成。\n* 将 East US 设置为运行 azd up 的唯一建议区域，由 @elbruno 在 https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F367 中完成。\n\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fcompare\u002F2024-08-28...2024-09-16","2024-09-16T15:30:02",{"id":183,"version":184,"summary_zh":185,"released_at":186},214755,"2024-08-28","## 截至2024年8月28日的主要变更\n- 将NuGet包更新至最新版本。\n- 将默认模型从gpt-35-turbo更改为gpt-4o-mini。\n- 将默认的Azure部署区域更改为美国东部。\n- 删除关于申请AOAI访问权限的段落。\n- 优化YAML文件。\n- 在README中添加Azure AI Search相关内容。\n- 从官方仓库更新核心AZD Bicep模块。\n- 实现聊天协议。\n\n\n## 变更内容\n* 初始PR：由@dluc在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F2中提交的带有.NET后端的azure-search-openai-demo项目。\n* SK升级、重构及代码风格优化：由@dluc在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F3中完成。\n* Azure模板重命名为‘azure-search-openai-demo-csharp’：由@adrianwyatt在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F6中完成。\n* 用最小API替换MVC：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F5中完成。\n* 更新README.md：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F7中完成。\n* 移除start.sh中的Python相关代码：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F8中完成。\n* 在引用中获取内联文档：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F9中完成。\n* 添加聊天服务：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F12中完成。\n* 修复utils中历史记录解析的bug：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F13中完成。\n* 添加retrievereadretrieve方法：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F14中完成。\n* 添加decompose方法：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F18中完成。\n* 移除React前端，添加.NET Blazor前端：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F22中完成。\n* 更新README.md中的图片：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F23中完成。\n* 移除本地化功能：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F24中完成。\n* SK升级：由@dluc在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F28中完成。\n* 提升计划器稳定性：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F26中完成。\n* 在异步API中传递CancellationToken：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F30中完成。\n* 添加bUnit组件测试项目：由@IEvangelist在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F29中完成。\n* 改进搜索文档功能：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F27中完成。\n* 将前端部署至SWA：由@LittleLittleCloud在https:\u002F\u002Fgithub.com\u002FAzure-Samples\u002Fazure-search-openai-demo-csharp\u002Fpull\u002F32中完成。\n* 清理工作","2024-08-28T18:31:18"]