[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-OkGoDoIt--OpenAI-API-dotnet":3,"tool-OkGoDoIt--OpenAI-API-dotnet":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",145895,2,"2026-04-08T11:32:59",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108111,"2026-04-08T11:23:26",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":79,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":32,"env_os":92,"env_gpu":93,"env_ram":93,"env_deps":94,"category_tags":101,"github_topics":102,"view_count":32,"oss_zip_url":80,"oss_zip_packed_at":80,"status":17,"created_at":120,"updated_at":121,"faqs":122,"releases":123},5539,"OkGoDoIt\u002FOpenAI-API-dotnet","OpenAI-API-dotnet","An unofficial C#\u002F.NET SDK for accessing the OpenAI GPT-3 API","OpenAI-API-dotnet 是一款专为 C# 和 .NET 开发者设计的开源库，旨在简化对 OpenAI 各类 API 的调用。它让开发者能够轻松在 .NET 应用中集成 GPT-3.5、GPT-4（含 Turbo 版本）、DALL-E 图像生成、语音识别与合成、文本嵌入及内容审核等强大功能。\n\n过去，.NET 开发者调用 OpenAI 接口往往需要手动处理复杂的 HTTP 请求和 JSON 解析，过程繁琐且易错。OpenAI-API-dotnet 通过提供类型安全、简洁易懂的封装方法，将这一过程变得像调用本地函数一样简单，显著降低了开发门槛并提升了编码效率。值得一提的是，该项目的原始版本（v1.11 及之前）由社区维护，因其稳定性至今仍被广泛使用；而从 v2.0 开始，微软已正式接手并将其升级为官方支持的 .NET 库，确保了功能的持续更新与全面覆盖。\n\n这款工具非常适合熟悉 C# 语言的软件工程师、全栈开发者以及希望在 Windows、Linux 或 macOS 平台上构建 AI 应用的技术团队。无论是开发聊天机器人、智能客服，还是进行多模态内容创作，OpenAI-API-","OpenAI-API-dotnet 是一款专为 C# 和 .NET 开发者设计的开源库，旨在简化对 OpenAI 各类 API 的调用。它让开发者能够轻松在 .NET 应用中集成 GPT-3.5、GPT-4（含 Turbo 版本）、DALL-E 图像生成、语音识别与合成、文本嵌入及内容审核等强大功能。\n\n过去，.NET 开发者调用 OpenAI 接口往往需要手动处理复杂的 HTTP 请求和 JSON 解析，过程繁琐且易错。OpenAI-API-dotnet 通过提供类型安全、简洁易懂的封装方法，将这一过程变得像调用本地函数一样简单，显著降低了开发门槛并提升了编码效率。值得一提的是，该项目的原始版本（v1.11 及之前）由社区维护，因其稳定性至今仍被广泛使用；而从 v2.0 开始，微软已正式接手并将其升级为官方支持的 .NET 库，确保了功能的持续更新与全面覆盖。\n\n这款工具非常适合熟悉 C# 语言的软件工程师、全栈开发者以及希望在 Windows、Linux 或 macOS 平台上构建 AI 应用的技术团队。无论是开发聊天机器人、智能客服，还是进行多模态内容创作，OpenAI-API-dotnet 都能提供流畅的开发体验。其基于 .NET Standard 2.0 构建，兼容性极强，可无缝运行于从传统 .NET Framework 到最新 .NET Core 的各类环境中，是 .NET 生态接入大模型能力的理想桥梁。","Microsoft reached out to me about transitioning this library into a new official C# OpenAI library and now it's ready to go!  Starting with [v2.0.0-beta.3](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F2.0.0-beta.3), the official library now has full coverage and will stay up-to-date.  More details in the blog post here: https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\n\nThis github repo will remain here to document my original version of the library through [version 1.11, which is still available on Nuget as well](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0).\n🎉 \n\n# C#\u002F.NET SDK for accessing the OpenAI APIs, including GPT-3.5\u002F4, GPT-3.5\u002F4-Turbo, and DALL-E 2\u002F3\n\nA simple C# .NET wrapper library to use with OpenAI's API.  More context [on my blog](https:\u002F\u002Frogerpincombe.com\u002Fopenai-dotnet-api).  **This is my original unofficial wrapper library around the OpenAI API.**\n\n## Quick Example\n\n```csharp\nvar api = new OpenAI_API.OpenAIAPI(\"YOUR_API_KEY\");\nvar result = await api.Chat.CreateChatCompletionAsync(\"Hello!\");\nConsole.WriteLine(result);\n\u002F\u002F should print something like \"Hi! How can I help you?\"\n```\n\n## Readme\n\n * [Status](#Status)\n * [Requirements](#requirements)\n * [Installation](#install-from-nuget)\n * [Authentication](#authentication)\n * [Chat API](#chat-api)\n\t* [Conversations](#chat-conversations)\n\t* [Streaming Results](#chat-streaming)\n\t* [GPT Vision](#gpt-vision)\n\t* [Chat Endpoint](#chat-endpoint-requests)\n\t* [Conversation History Context Length Management](#Conversation-History-Context-Length-Management)\n\t* [JSON Mode](#json-mode)\n * [Completions API](#completions-api)\n\t* [Streaming completion results](#streaming)\n * [Audio](#audio)\n\t* [Text to Speech](#text-to-speech-tts)\n\t* [Transcribe Audio to Text](#transcription-speech-to-text)\n\t* [Translate Audio to English Text](#translations-non-english-speech-to-english-text)\n * [Embeddings API](#embeddings)\n * [Moderation API](#moderation)\n * [Files API](#files-for-fine-tuning)\n * [Image APIs (DALL-E)](#images)\n\t* [DALLE-E 3](#dall-e-3)\n * [Azure](#azure)\n * [Additional Documentation](#documentation)\n * [License](#license)\n\n## Status\n[![OpenAI](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOkGoDoIt_OpenAI-API-dotnet_readme_fc8d30c5dfcd.png)](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F)\n\nStarting with [v2.0.0-beta](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F2.0.0-beta.3), this library has been adopted by Microsoft.  The new official version of the library will have full coverage and will stay fully up-to-date. More details in the blog post here: [https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\u002F](https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\u002F)\nThis github repo will remain here to document my original version of the library through [version 1.11, which is still available on Nuget as well](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0).\n\n## Requirements\n\nThis library is based on .NET Standard 2.0, so it should work across all versions of .Net, from the traditional .NET Framework >=4.7.2 to .NET (Core) >= 3.0.  It should work across console apps, winforms, wpf, asp.net, unity, Xamarin, etc.  It should work across Windows, Linux, and Mac, and possibly even mobile.  There are minimal dependencies, and it's licensed in the public domain.\n\n## Getting started\n\n### Install from NuGet\n\nInstall package [`OpenAI` v1.11 from Nuget](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0).  Here's how via commandline:\n```powershell\nInstall-Package OpenAI -Version 1.11.0\n```\n\n### Authentication\nThere are 3 ways to provide your API keys, in order of precedence:\n1.  Pass keys directly to `APIAuthentication(string key)` constructor\n2.  Set environment var for OPENAI_API_KEY (or OPENAI_KEY for backwards compatibility)\n3.  Include a config file in the local directory or in your user directory named `.openai` and containing the line:\n```shell\nOPENAI_API_KEY=sk-aaaabbbbbccccddddd\n```\n\nYou use the `APIAuthentication` when you initialize the API as shown:\n```csharp\n\u002F\u002F for example\nOpenAIAPI api = new OpenAIAPI(\"YOUR_API_KEY\"); \u002F\u002F shorthand\n\u002F\u002F or\nOpenAIAPI api = new OpenAIAPI(new APIAuthentication(\"YOUR_API_KEY\")); \u002F\u002F create object manually\n\u002F\u002F or\nOpenAIAPI api = new OpenAIAPI(APIAuthentication LoadFromEnv()); \u002F\u002F use env vars\n\u002F\u002F or\nOpenAIAPI api = new OpenAIAPI(APIAuthentication LoadFromPath()); \u002F\u002F use config file (can optionally specify where to look)\n\u002F\u002F or\nOpenAIAPI api = new OpenAIAPI(); \u002F\u002F uses default, env, or config file\n```\n\nYou may optionally include an openAIOrganization (OPENAI_ORGANIZATION in env or config file) specifying which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.  Organization IDs can be found on your [Organization settings](https:\u002F\u002Fbeta.openai.com\u002Faccount\u002Forg-settings) page.\n```csharp\n\u002F\u002F for example\nOpenAIAPI api = new OpenAIAPI(new APIAuthentication(\"YOUR_API_KEY\",\"org-yourOrgHere\"));\n```\n\n### Chat API\nThe Chat API is accessed via `OpenAIAPI.Chat`.  There are two ways to use the Chat Endpoint, either via simplified conversations or with the full Request\u002FResponse methods.\n\n#### Chat Conversations\nThe Conversation Class allows you to easily interact with ChatGPT by adding messages to a chat and asking ChatGPT to reply.\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.Model = Model.GPT4_Turbo;\nchat.RequestParameters.Temperature = 0;\n\n\u002F\u002F\u002F give instruction as System\nchat.AppendSystemMessage(\"You are a teacher who helps children understand if things are animals or not.  If the user tells you an animal, you say \\\"yes\\\".  If the user tells you something that is not an animal, you say \\\"no\\\".  You only ever respond with \\\"yes\\\" or \\\"no\\\".  You do not say anything else.\");\n\n\u002F\u002F give a few examples as user and assistant\nchat.AppendUserInput(\"Is this an animal? Cat\");\nchat.AppendExampleChatbotOutput(\"Yes\");\nchat.AppendUserInput(\"Is this an animal? House\");\nchat.AppendExampleChatbotOutput(\"No\");\n\n\u002F\u002F now let's ask it a question\nchat.AppendUserInput(\"Is this an animal? Dog\");\n\u002F\u002F and get the response\nstring response = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"Yes\"\n\n\u002F\u002F and continue the conversation by asking another\nchat.AppendUserInput(\"Is this an animal? Chair\");\n\u002F\u002F and get another response\nresponse = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"No\"\n\n\u002F\u002F the entire chat history is available in chat.Messages\nforeach (ChatMessage msg in chat.Messages)\n{\n\tConsole.WriteLine($\"{msg.Role}: {msg.Content}\");\n}\n```\n\n#### Chat Streaming\n\nStreaming allows you to get results are they are generated, which can help your application feel more responsive.\n\nUsing the new C# 8.0 async iterators:\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.AppendUserInput(\"How to make a hamburger?\");\n\nawait foreach (var res in chat.StreamResponseEnumerableFromChatbotAsync())\n{\n\tConsole.Write(res);\n}\n```\n\nOr if using classic .NET Framework or C# \u003C8.0:\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.AppendUserInput(\"How to make a hamburger?\");\n\nawait chat.StreamResponseFromChatbotAsync(res =>\n{\n\tConsole.Write(res);\n});\n```\n\n#### GPT Vision\n\nYou can send images to the chat to use the new GPT-4 Vision model.  This only works with the `Model.GPT4_Vision` model.  Please see https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fvision for more information and limitations.\n\n```csharp\n\u002F\u002F the simplest form\nvar result = await api.Chat.CreateChatCompletionAsync(\"What is the primary non-white color in this logo?\", ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"));\n\n\u002F\u002F or in a conversation\nvar chat = api.Chat.CreateConversation();\nchat.Model = Model.GPT4_Vision;\nchat.AppendSystemMessage(\"You are a graphic design assistant who helps identify colors.\");\nchat.AppendUserInput(\"What are the primary non-white colors in this logo?\", ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"));\nstring response = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"Blue and purple\"\nchat.AppendUserInput(\"What are the primary non-white colors in this logo?\", ImageInput.FromImageUrl(\"https:\u002F\u002Frogerpincombe.com\u002Ftemplates\u002Frp\u002Fcenter-aligned-no-shadow-small.png\"));\nresponse = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"Blue, red, and yellow\"\n\n\u002F\u002F or when manually creating the ChatMessage\nmessageWithImage = new ChatMessage(ChatMessageRole.User, \"What colors do these logos have in common?\");\nmessageWithImage.images.Add(ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"));\nmessageWithImage.images.Add(ImageInput.FromImageUrl(\"https:\u002F\u002Frogerpincombe.com\u002Ftemplates\u002Frp\u002Fcenter-aligned-no-shadow-small.png\"));\n\n\u002F\u002F you can specify multiple images at once\nchat.AppendUserInput(\"What colors do these logos have in common?\", ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"), ImageInput.FromImageUrl(\"https:\u002F\u002Frogerpincombe.com\u002Ftemplates\u002Frp\u002Fcenter-aligned-no-shadow-small.png\"));\n```\n\n\n#### Conversation History Context Length Management\nIf the chat conversation history gets too long, it may not fit into the context length of the model.  By default, the earliest non-system message(s) will be removed from the chat history and the API call will be retried.  You may disable this by setting `chat.AutoTruncateOnContextLengthExceeded = false`, or you can override the truncation algorithm like this:\n\n```csharp\nchat.OnTruncationNeeded += (sender, args) =>\n{\n\t\u002F\u002F args is a List\u003CChatMessage> with the current chat history.  Remove or edit as nessisary.\n\t\u002F\u002F replace this with more sophisticated logic for your use-case, such as summarizing the chat history\n\tfor (int i = 0; i \u003C args.Count; i++)\n\t{\n\t\tif (args[i].Role != ChatMessageRole.System)\n\t\t{\n\t\t\targs.RemoveAt(i);\n\t\t\treturn;\n\t\t}\n\t}\n};\n```\n\nYou may also wish to use a new model with a larger context length.  You can do this by setting `chat.Model = Model.GPT4_Turbo` or `chat.Model = Model.ChatGPTTurbo_16k`, etc.\n\nYou can see token usage via `chat.MostRecentApiResult.Usage.PromptTokens` and related properties. \n\n#### Chat Endpoint Requests\nYou can access full control of the Chat API by using the `OpenAIAPI.Chat.CreateChatCompletionAsync()` and related methods.\n\n```csharp\nasync Task\u003CChatResult> CreateChatCompletionAsync(ChatRequest request);\n\n\u002F\u002F for example\nvar result = await api.Chat.CreateChatCompletionAsync(new ChatRequest()\n\t{\n\t\tModel = Model.ChatGPTTurbo,\n\t\tTemperature = 0.1,\n\t\tMaxTokens = 50,\n\t\tMessages = new ChatMessage[] {\n\t\t\tnew ChatMessage(ChatMessageRole.User, \"Hello!\")\n\t\t}\n\t})\n\u002F\u002F or\nvar result = api.Chat.CreateChatCompletionAsync(\"Hello!\");\n\nvar reply = results.Choices[0].Message;\nConsole.WriteLine($\"{reply.Role}: {reply.Content.Trim()}\");\n\u002F\u002F or\nConsole.WriteLine(results);\n```\n\nIt returns a `ChatResult` which is mostly metadata, so use its `.ToString()` method to get the text if all you want is assistant's reply text.\n\nThere's also an async streaming API which works similarly to the [Completions endpoint streaming results](#streaming). \n\n#### JSON Mode\n\nWith the new `Model.GPT4_Turbo` or `gpt-3.5-turbo-1106` models, you can set the `ChatRequest.ResponseFormat` to `ChatRequest.ResponseFormats.JsonObject` to enable JSON mode.\nWhen JSON mode is enabled, the model is constrained to only generate strings that parse into valid JSON object.\nSee https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Ftext-generation\u002Fjson-mode for more details.\n\n```csharp\nChatRequest chatRequest = new ChatRequest()\n{\n\tModel = model,\n\tTemperature = 0.0,\n\tMaxTokens = 500,\n\tResponseFormat = ChatRequest.ResponseFormats.JsonObject,\n\tMessages = new ChatMessage[] {\n\t\tnew ChatMessage(ChatMessageRole.System, \"You are a helpful assistant designed to output JSON.\"),\n\t\tnew ChatMessage(ChatMessageRole.User, \"Who won the world series in 2020?  Return JSON of a 'wins' dictionary with the year as the numeric key and the winning team as the string value.\")\n\t}\n};\n\nvar results = await api.Chat.CreateChatCompletionAsync(chatRequest);\nConsole.WriteLine(results);\n\u002F* prints:\n{\n  \"wins\": {\n\t2020: \"Los Angeles Dodgers\"\n  }\n}\n*\u002F\n```\n\n\n\n### Completions API\nCompletions are considered legacy by OpenAI.  The Completion API is accessed via `OpenAIAPI.Completions`:\n\n```csharp\nasync Task\u003CCompletionResult> CreateCompletionAsync(CompletionRequest request);\n\n\u002F\u002F for example\nvar result = await api.Completions.CreateCompletionAsync(new CompletionRequest(\"One Two Three One Two\", model: Model.CurieText, temperature: 0.1));\n\u002F\u002F or\nvar result = await api.Completions.CreateCompletionAsync(\"One Two Three One Two\", temperature: 0.1);\n\u002F\u002F or other convenience overloads\n```\nYou can create your `CompletionRequest` ahead of time or use one of the helper overloads for convenience.  It returns a `CompletionResult` which is mostly metadata, so use its `.ToString()` method to get the text if all you want is the completion.\n\n#### Streaming\nStreaming allows you to get results are they are generated, which can help your application feel more responsive, especially on slow models like Davinci.\n\nUsing the new C# 8.0 async iterators:\n```csharp\nIAsyncEnumerable\u003CCompletionResult> StreamCompletionEnumerableAsync(CompletionRequest request);\n\n\u002F\u002F for example\nawait foreach (var token in api.Completions.StreamCompletionEnumerableAsync(new CompletionRequest(\"My name is Roger and I am a principal software engineer at Salesforce.  This is my resume:\", Model.DavinciText, 200, 0.5, presencePenalty: 0.1, frequencyPenalty: 0.1)))\n{\n\tConsole.Write(token);\n}\n```\n\nOr if using classic .NET framework or C# \u003C8.0:\n```csharp\nasync Task StreamCompletionAsync(CompletionRequest request, Action\u003CCompletionResult> resultHandler);\n\n\u002F\u002F for example\nawait api.Completions.StreamCompletionAsync(\n\tnew CompletionRequest(\"My name is Roger and I am a principal software engineer at Salesforce.  This is my resume:\", Model.DavinciText, 200, 0.5, presencePenalty: 0.1, frequencyPenalty: 0.1),\n\tres => ResumeTextbox.Text += res.ToString());\n```\n\n### Audio\nThe Audio API's are Text to Speech, Transcription (speech to text), and Translation (non-English speech to English text).\n\n#### Text to Speech (TTS)\nThe TTS API is accessed via `OpenAIAPI.TextToSpeech`:\n\n```csharp\nawait api.TextToSpeech.SaveSpeechToFileAsync(\"Hello, brave new world!  This is a test.\", outputPath);\n\u002F\u002F You can open it in the defaul audio player like this:\nProcess.Start(outputPath);\n```\n\nYou can also specify all of the request parameters with a `TextToSpeechRequest` object:\n\n```csharp\nvar request = new TextToSpeechRequest()\n{\n\tInput = \"Hello, brave new world!  This is a test.\",\n\tResponseFormat = ResponseFormats.AAC,\n\tModel = Model.TTS_HD,\n\tVoice = Voices.Nova,\n\tSpeed = 0.9\n};\nawait api.TextToSpeech.SaveSpeechToFileAsync(request, \"test.aac\");\n```\n\nInstead of saving to a file, you can get audio byte stream with `api.TextToSpeech.GetSpeechAsStreamAsync(request)`:\n\n```csharp\nusing (Stream result = await api.TextToSpeech.GetSpeechAsStreamAsync(\"Hello, brave new world!\", Voices.Fable))\nusing (StreamReader reader = new StreamReader(result))\n{\n\t\u002F\u002F do something with the audio stream here\n}\n```\n\n#### Transcription (Speech to Text)\n\nThe Audio Transcription API allows you to generate text from audio, in any of the supported languages.  It is accessed via `OpenAIAPI.Transcriptions`:\n\n```csharp\nstring resultText = await api.Transcriptions.GetTextAsync(\"path\u002Fto\u002Ffile.mp3\");\n```\n\nYou can ask for verbose results, which will give you segment and token-level information, as well as the standard OpenAI metadata such as processing time:\n\n```csharp\nAudioResultVerbose result = await api.Transcriptions.GetWithDetailsAsync(\"path\u002Fto\u002Ffile.m4a\");\nConsole.WriteLine(result.ProcessingTime.TotalMilliseconds); \u002F\u002F 496ms\nConsole.WriteLine(result.text); \u002F\u002F \"Hello, this is a test of the transcription function.\"\nConsole.WriteLine(result.language); \u002F\u002F \"english\"\nConsole.WriteLine(result.segments[0].no_speech_prob); \u002F\u002F 0.03712\n\u002F\u002F etc\n```\n\nYou can also ask for results in SRT or VTT format, which is useful for generating subtitles for videos:\n\n```csharp\nstring result = await api.Transcriptions.GetAsFormatAsync(\"path\u002Fto\u002Ffile.m4a\", AudioRequest.ResponseFormats.SRT);\n```\n\nAdditional parameters such as temperature, prompt, language, etc can be specified either per-request or as a default:\n\n```csharp\n\u002F\u002F inline\nresult = await api.Transcriptions.GetTextAsync(\"conversation.mp3\", \"en\", \"This is a transcript of a conversation between a medical doctor and her patient: \", 0.3);\n\n\u002F\u002F set defaults\napi.Transcriptions.DefaultTranscriptionRequestArgs.Language = \"en\";\n```\n\nInstead of providing a local file on disk, you can provide a stream of audio bytes.  This can be useful for streaming audio from the microphone or another source without having to first write to disk.  Please not you must specify a filename, which does not have to exist, but which must have an accurate extension for the type of audio that you are sending.  OpenAI uses the filename extension to determine what format your audio stream is in.\n\n```csharp\nusing (var audioStream = File.OpenRead(\"path-here.mp3\"))\n{\n\treturn await api.Transcriptions.GetTextAsync(audioStream, \"file.mp3\");\n}\n```\n\n#### Translations (Non-English Speech to English Text)\n\nTranslations allow you to transcribe text from any of the supported languages to English.  OpenAI does not support translating into any other language, only English.  It is accessed via `OpenAIAPI.Translations`.\nIt supports all of the same functionality as the Transcriptions.\n\n```csharp\nstring result = await api.Translations.GetTextAsync(\"chinese-example.m4a\");\n```\n\n### Embeddings\nThe Embedding API is accessed via `OpenAIAPI.Embeddings`:\n\n```csharp\nasync Task\u003CEmbeddingResult> CreateEmbeddingAsync(EmbeddingRequest request);\n\n\u002F\u002F for example\nvar result = await api.Embeddings.CreateEmbeddingAsync(new EmbeddingRequest(\"A test text for embedding\", model: Model.AdaTextEmbedding));\n\u002F\u002F or\nvar result = await api.Embeddings.CreateEmbeddingAsync(\"A test text for embedding\");\n```\n\nThe embedding result contains a lot of metadata, the actual vector of floats is in result.Data[].Embedding.\n\nFor simplicity, you can directly ask for the vector of floats and disgard the extra metadata with `api.Embeddings.GetEmbeddingsAsync(\"test text here\")`\n\n\n### Moderation\nThe Moderation API is accessed via `OpenAIAPI.Moderation`:\n\n```csharp\nasync Task\u003CModerationResult> CreateEmbeddingAsync(ModerationRequest request);\n\n\u002F\u002F for example\nvar result = await api.Moderation.CallModerationAsync(new ModerationRequest(\"A test text for moderating\", Model.TextModerationLatest));\n\u002F\u002F or\nvar result = await api.Moderation.CallModerationAsync(\"A test text for moderating\");\n\nConsole.WriteLine(result.results[0].MainContentFlag);\n```\n\nThe results are in `.results[0]` and have nice helper methods like `FlaggedCategories` and `MainContentFlag`.\n\n\n### Files (for fine-tuning)\nThe Files API endpoint is accessed via `OpenAIAPI.Files`:\n\n```csharp\n\u002F\u002F uploading\nasync Task\u003CFile> UploadFileAsync(string filePath, string purpose = \"fine-tune\");\n\n\u002F\u002F for example\nvar response = await api.Files.UploadFileAsync(\"fine-tuning-data.jsonl\");\nConsole.Write(response.Id); \u002F\u002Fthe id of the uploaded file\n\n\u002F\u002F listing\nasync Task\u003CList\u003CFile>> GetFilesAsync();\n\n\u002F\u002F for example\nvar response = await api.Files.GetFilesAsync();\nforeach (var file in response)\n{\n\tConsole.WriteLine(file.Name);\n}\n```\n\nThere are also methods to get file contents, delete a file, etc.\n\nThe fine-tuning endpoint itself has not yet been implemented, but will be added soon.\n\n### Images\nThe DALL-E Image Generation API is accessed via `OpenAIAPI.ImageGenerations`:\n\n```csharp\nasync Task\u003CImageResult> CreateImageAsync(ImageGenerationRequest request);\n\n\u002F\u002F for example\nvar result = await api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest(\"A drawing of a computer writing a test\", 1, ImageSize._512));\n\u002F\u002F or\nvar result = await api.ImageGenerations.CreateImageAsync(\"A drawing of a computer writing a test\");\n\nConsole.WriteLine(result.Data[0].Url);\n```\n\nThe image result contains a URL for an online image or a base64-encoded image, depending on the ImageGenerationRequest.ResponseFormat (url is the default).\n\n#### DALL-E 3\n\nUse DALL-E 3 like this:\n\n```csharp\nasync Task\u003CImageResult> CreateImageAsync(ImageGenerationRequest request);\n\n\u002F\u002F for example\nvar result = await api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest(\"A drawing of a computer writing a test\", OpenAI_API.Models.Model.DALLE3, ImageSize._1024x1792, \"hd\"));\n\u002F\u002F or\nvar result = await api.ImageGenerations.CreateImageAsync(\"A drawing of a computer writing a test\", OpenAI_API.Models.Model.DALLE3);\n\nConsole.WriteLine(result.Data[0].Url);\n```\n\n## Azure\n\nFor using the Azure OpenAI Service, you need to specify the name of your Azure OpenAI resource as well as your model deployment id.\n\n_I do not have access to the Microsoft Azure OpenAI service, so I am unable to test this functionality.  If you have access and can test, please submit an issue describing your results.  A PR with integration tests would also be greatly appreciated.  Specifically, it is unclear to me that specifying models works the same way with Azure._\n\nRefer the [Azure OpenAI documentation](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fcognitive-services\u002Fopenai\u002Freference) and [detailed screenshots in #64](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fissues\u002F64#issuecomment-1479276020) for further information.\n\nConfiguration should look something like this for the Azure service:\n\n```csharp\nOpenAIAPI api = OpenAIAPI.ForAzure(\"YourResourceName\", \"deploymentId\", \"api-key\");\napi.ApiVersion = \"2023-03-15-preview\"; \u002F\u002F needed to access chat endpoint on Azure\n```\n\nYou may then use the `api` object like normal.  You may also specify the `APIAuthentication` is any of the other ways listed in the [Authentication](#authentication) section above.  Currently this library only supports the api-key flow, not the AD-Flow.\n\nAs of April 2, 2023, you need to manually select api version `2023-03-15-preview` as shown above to access the chat endpoint on Azure.  Once this is out of preview I will update the default.\n\n## IHttpClientFactory\nYou may specify an `IHttpClientFactory` to be used for HTTP requests, which allows for tweaking http request properties, connection pooling, and mocking.  Details in [#103](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F103).\n\n```csharp\nOpenAIAPI api = new OpenAIAPI();\napi.HttpClientFactory = myIHttpClientFactoryObject;\n```\n\n## Documentation\n\nEvery single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense.  That combined with the official OpenAI documentation should be enough to get started.  Feel free to open an issue here if you have any questions.  Better documentation may come later.\n\n## License\n\nCC-0 Public Domain\n\nThis library is licensed CC-0, in the public domain.  You can use it for whatever you want, publicly or privately, without worrying about permission or licensing or whatever.  It's just a wrapper around the OpenAI API, so you still need to get access to OpenAI from them directly.  I am not affiliated with OpenAI and this library is not endorsed by them, I just have beta access and wanted to make a C# library to access it more easily.  Hopefully others find this useful as well.  Feel free to open a PR if there's anything you want to contribute.\n","微软联系了我，希望将这个库迁移到新的官方 C# OpenAI 库中，现在它已经准备就绪！从 [v2.0.0-beta.3](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F2.0.0-beta.3) 开始，官方库现已实现全面覆盖，并将持续保持更新。更多详情请参见此博客文章：https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\n\n此 GitHub 仓库将继续保留，用于记录我最初的库版本，直至 [1.11 版本，该版本目前仍可在 NuGet 上获取](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0)。\n🎉 \n\n# 用于访问 OpenAI API 的 C#\u002F.NET SDK，包括 GPT-3.5\u002F4、GPT-3.5\u002F4-Turbo 以及 DALL-E 2\u002F3\n\n一个简单的 C# .NET 封装库，用于与 OpenAI 的 API 配合使用。更多背景信息请参阅我的博客：[https:\u002F\u002Frogerpincombe.com\u002Fopenai-dotnet-api](https:\u002F\u002Frogerpincombe.com\u002Fopenai-dotnet-api)。**这是我最初开发的非官方 OpenAI API 封装库。**\n\n## 快速示例\n\n```csharp\nvar api = new OpenAI_API.OpenAIAPI(\"YOUR_API_KEY\");\nvar result = await api.Chat.CreateChatCompletionAsync(\"Hello!\");\nConsole.WriteLine(result);\n\u002F\u002F 应该打印出类似“Hi! How can I help you?”的内容\n```\n\n## 自述文件\n\n * [状态](#Status)\n * [要求](#requirements)\n * [安装](#install-from-nuget)\n * [身份验证](#authentication)\n * [聊天 API](#chat-api)\n\t* [对话](#chat-conversations)\n\t* [流式响应](#chat-streaming)\n\t* [GPT 视觉](#gpt-vision)\n\t* [聊天端点](#chat-endpoint-requests)\n\t* [对话历史上下文长度管理](#Conversation-History-Context-Length-Management)\n\t* [JSON 模式](#json-mode)\n * [完成度 API](#completions-api)\n\t* [流式完成结果](#streaming)\n * [音频](#audio)\n\t* [文本转语音](#text-to-speech-tts)\n\t* [音频转文字](#transcription-speech-to-text)\n\t* [音频翻译成英文](#translations-non-english-speech-to-english-text)\n * [嵌入 API](#embeddings)\n * [内容审核 API](#moderation)\n * [文件 API](#files-for-fine-tuning)\n * [图像 API (DALL-E)](#images)\n\t* [DALLE-E 3](#dall-e-3)\n * [Azure](#azure)\n * [附加文档](#documentation)\n * [许可证](#license)\n\n## 状态\n[![OpenAI](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOkGoDoIt_OpenAI-API-dotnet_readme_fc8d30c5dfcd.png)](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F)\n\n自 [v2.0.0-beta](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F2.0.0-beta.3) 起，该库已被微软采纳。新官方版本的库将实现全面覆盖，并始终保持最新状态。更多详细信息请参阅此博客文章：[https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\u002F](https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\u002F)。此 GitHub 仓库将继续保留，以记录我最初的库版本，直至 [1.11 版本，该版本目前仍可在 NuGet 上获取](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0)。\n\n## 要求\n\n该库基于 .NET Standard 2.0，因此应在所有 .NET 版本上运行，从传统的 .NET Framework >=4.7.2 到 .NET (Core) >= 3.0。它适用于控制台应用程序、WinForms、WPF、ASP.NET、Unity、Xamarin 等多种平台。此外，它还应能在 Windows、Linux 和 Mac 系统上运行，甚至可能支持移动设备。该库依赖项极少，并采用公共领域许可。\n\n## 入门指南\n\n### 从 NuGet 安装\n\n安装 NuGet 包 [`OpenAI` v1.11](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0)。通过命令行安装方法如下：\n```powershell\nInstall-Package OpenAI -Version 1.11.0\n```\n\n### 身份验证\n提供 API 密钥的方式有三种，按优先级顺序排列：\n1. 直接将密钥传递给 `APIAuthentication(string key)` 构造函数\n2. 设置环境变量 `OPENAI_API_KEY`（或为兼容旧版而设置的 `OPENAI_KEY`）\n3. 在本地目录或用户目录下创建名为 `.openai` 的配置文件，内容如下：\n```shell\nOPENAI_API_KEY=sk-aaaabbbbbccccddddd\n```\n\n在初始化 API 时，您需要使用 `APIAuthentication` 类，例如：\n```csharp\n\u002F\u002F 示例\nOpenAIAPI api = new OpenAIAPI(\"YOUR_API_KEY\"); \u002F\u002F 简写\n\u002F\u002F 或\nOpenAIAPI api = new OpenAIAPI(new APIAuthentication(\"YOUR_API_KEY\")); \u002F\u002F 手动创建对象\n\u002F\u002F 或\nOpenAIAPI api = new OpenAIAPI(APIAuthentication LoadFromEnv()); \u002F\u002F 使用环境变量\n\u002F\u002F 或\nOpenAIAPI api = new OpenAIAPI(APIAuthentication LoadFromPath()); \u002F\u002F 使用配置文件（可指定查找路径）\n\u002F\u002F 或\nOpenAIAPI api = new OpenAIAPI(); \u002F\u002F 使用默认值、环境变量或配置文件\n```\n\n您还可以选择性地指定 `openAIOrganization`（通过环境变量或配置文件中的 `OPENAI_ORGANIZATION`），以明确此次 API 请求所属的组织。此类请求的使用量将计入指定组织的订阅配额。组织 ID 可在您的 [组织设置页面](https:\u002F\u002Fbeta.openai.com\u002Faccount\u002Forg-settings) 中找到。\n```csharp\n\u002F\u002F 示例\nOpenAIAPI api = new OpenAIAPI(new APIAuthentication(\"YOUR_API_KEY\",\"org-yourOrgHere\"));\n```\n\n### 聊天 API\n聊天 API 可通过 `OpenAIAPI.Chat` 访问。使用聊天端点有两种方式：一种是通过简化的对话模式，另一种则是使用完整的请求\u002F响应方法。\n\n#### 聊天对话\n`Conversation` 类允许您轻松地与 ChatGPT 交互，只需添加消息并让 ChatGPT 回答即可。\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.Model = Model.GPT4_Turbo;\nchat.RequestParameters.Temperature = 0;\n\n\u002F\u002F\u002F 作为系统给出指令\nchat.AppendSystemMessage(\"你是一位老师，帮助孩子们判断某物是否为动物。如果用户告诉你某物是动物，你就回答‘是’；如果用户告诉你某物不是动物，你就回答‘否’。你只回答‘是’或‘否’，绝不说其他内容。\");\n\n\u002F\u002F 添加一些用户和助手的示例\nchat.AppendUserInput(\"这是动物吗？猫\");\nchat.AppendExampleChatbotOutput(\"是\");\nchat.AppendUserInput(\"这是动物吗？房子\");\nchat.AppendExampleChatbotOutput(\"否\");\n\n\u002F\u002F 现在让我们问一个问题\nchat.AppendUserInput(\"这是动物吗？狗\");\n\u002F\u002F 并获取回复\nstring response = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"是\"\n\n\u002F\u002F 继续对话，再问一个问题\nchat.AppendUserInput(\"这是动物吗？椅子\");\n\u002F\u002F 再次获取回复\nresponse = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"否\"\n\n\u002F\u002F 整个聊天记录可在 chat.Messages 中查看\nforeach (ChatMessage msg in chat.Messages)\n{\n\tConsole.WriteLine($\"{msg.Role}: {msg.Content}\");\n}\n```\n\n#### 聊天流式传输\n\n流式传输允许您在结果生成时实时获取它们，从而使您的应用程序显得更加流畅和响应迅速。\n\n使用新的 C# 8.0 异步迭代器：\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.AppendUserInput(\"如何制作汉堡？\");\n\nawait foreach (var res in chat.StreamResponseEnumerableFromChatbotAsync())\n{\n\tConsole.Write(res);\n}\n```\n\n或者，如果您使用的是经典的 .NET Framework 或 C# \u003C8.0：\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.AppendUserInput(\"如何制作汉堡？\");\n\nawait chat.StreamResponseFromChatbotAsync(res =>\n{\n\tConsole.Write(res);\n});\n```\n\n#### GPT 视觉\n\n您可以向聊天发送图片，以使用新的 GPT-4 视觉模型。此功能仅适用于 `Model.GPT4_Vision` 模型。有关更多信息和限制，请参阅 https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fvision。\n\n```csharp\n\u002F\u002F 最简单的形式\nvar result = await api.Chat.CreateChatCompletionAsync(\"这个 로고의 주요한 비백색 색상은 무엇인가요?\", ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"));\n\n\u002F\u002F 또는 대화에서\nvar chat = api.Chat.CreateConversation();\nchat.Model = Model.GPT4_Vision;\nchat.AppendSystemMessage(\"당신은 색상을 식별하는 데 도움을 주는 그래픽 디자인 어시스턴트입니다.\");\nchat.AppendUserInput(\"이 로고의 주요한 비백색 색상은 무엇입니까?\", ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"));\nstring response = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"파란색과 보라색\"\nchat.AppendUserInput(\"이 로고의 주요한 비백색 색상은 무엇입니까?\", ImageInput.FromImageUrl(\"https:\u002F\u002Frogerpincombe.com\u002Ftemplates\u002Frp\u002Fcenter-aligned-no-shadow-small.png\"));\nresponse = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F \"파란색, 빨간색, 노란색\"\n\n\u002F\u002F 또는 챗메시지를 수동으로 생성할 때\nmessageWithImage = new ChatMessage(ChatMessageRole.User, \"이 로고들에는 어떤 색상이 공통적으로 있나요?\");\nmessageWithImage.images.Add(ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"));\nmessageWithImage.images.Add(ImageInput.FromImageUrl(\"https:\u002F\u002Frogerpincombe.com\u002Ftemplates\u002Frp\u002Fcenter-aligned-no-shadow-small.png\"));\n\n\u002F\u002F 한 번에 여러 장의 이미지를 지정할 수 있습니다\nchat.AppendUserInput(\"이 로고들에는 어떤 색상이 공통적으로 있나요?\", ImageInput.FromFile(\"path\u002Fto\u002Flogo.png\"), ImageInput.FromImageUrl(\"https:\u002F\u002Frogerpincombe.com\u002Ftemplates\u002Frp\u002Fcenter-aligned-no-shadow-small.png\"));\n```\n\n\n#### 대화 기록 컨텍스트 길이 관리\n채팅 대화 기록이 너무 길어지면 모델의 컨텍스트 길이에 맞지 않을 수 있습니다。 기본적으로 가장 오래된 시스템 메시지가 아닌 메시지부터 대화 기록에서 제거되고 API 호출이 다시 시도됩니다。 이 기능을 비활성화하려면 `chat.AutoTruncateOnContextLengthExceeded = false`로 설정하거나 다음과 같이 트렁케이션 알고리즘을 재정의할 수 있습니다：\n\n```csharp\nchat.OnTruncationNeeded += (sender, args) =>\n{\n\t\u002F\u002F args는 현재 대화 기록을 포함하는 ChatMessage 리스트입니다. 필요에 따라 제거하거나 수정하세요.\n\t\u002F\u002F 대화 기록 요약 등 사용 사례에 맞는 더 정교한 로직으로 대체하세요\n\tfor (int i = 0; i \u003C args.Count; i++)\n\t{\n\t\tif (args[i].Role != ChatMessageRole.System)\n\t\t{\n\t\t\targs.RemoveAt(i);\n\t\t\treturn;\n\t\t}\n\t}\n};\n```\n\n또한 더 큰 컨텍스트 길이를 가진 새로운 모델을 사용할 수도 있습니다。 이를 위해 `chat.Model = Model.GPT4_Turbo` 또는 `chat.Model = Model.ChatGPTTurbo_16k` 등을 설정하면 됩니다。\n\n토큰 사용량은 `chat.MostRecentApiResult.Usage.PromptTokens` 및 관련 속성을 통해 확인할 수 있습니다。\n\n#### 채팅 엔드포인트 요청\n`OpenAIAPI.Chat.CreateChatCompletionAsync()` 및 관련 메서드를 사용하면 채팅 API를 완전히 제어할 수 있습니다。\n\n```csharp\nasync Task\u003CChatResult> CreateChatCompletionAsync(ChatRequest request);\n\n\u002F\u002F 예를 들어\nvar result = await api.Chat.CreateChatCompletionAsync(new ChatRequest()\n\t{\n\t\tModel = Model.ChatGPTTurbo,\n\t\tTemperature = 0.1,\n\t\tMaxTokens = 50,\n\t\tMessages = new ChatMessage[] {\n\t\t\tnew ChatMessage(ChatMessageRole.User, \"안녕하세요!\")\n\t\t}\n\t})\n\u002F\u002F 또는\nvar result = api.Chat.CreateChatCompletionAsync(\"안녕하세요!\");\n\nvar reply = results.Choices[0].Message;\nConsole.WriteLine($\"{reply.Role}: {reply.Content.Trim()}\");\n\u002F\u002F 또는\nConsole.WriteLine(results);\n```\n\n이는 대부분 메타데이터로 구성된 `ChatResult`를 반환하므로, 단순히 어시스턴트의 응답 텍스트만 원한다면 `.ToString()` 메서드를 사용하세요.\n\n또한 [Completions 엔드포인트 스트리밍 결과](#streaming)와 유사하게 작동하는 비동기 스트리밍 API도 있습니다。\n\n#### JSON 모드\n\n새로운 `Model.GPT4_Turbo` 또는 `gpt-3.5-turbo-1106` 모델을 사용할 경우, `ChatRequest.ResponseFormat`을 `ChatRequest.ResponseFormats.JsonObject`로 설정하여 JSON 모드를 활성화할 수 있습니다。JSON 모드가 활성화되면 모델은 유효한 JSON 객체로 파싱될 수 있는 문자열만 생성하도록 제한됩니다。\n자세한 내용은 https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Ftext-generation\u002Fjson-mode를 참조하세요。\n\n```csharp\nChatRequest chatRequest = new ChatRequest()\n{\n\tModel = model,\n\tTemperature = 0.0,\n\tMaxTokens = 500,\n\tResponseFormat = ChatRequest.ResponseFormats.JsonObject,\n\tMessages = new ChatMessage[] {\n\t\tnew ChatMessage(ChatMessageRole.System, \"당신은 JSON을 출력하도록 설계된 유용한 어시스턴트입니다.\"),\n\t\tnew ChatMessage(ChatMessageRole.User, \"2020년 월드 시리즈 우승팀은 누구입니까? 연도를 숫자 키로, 우승팀을 문자열 값으로 하는 'wins' 딕셔너리를 JSON 형식으로 반환해 주세요.\")\n\t}\n};\n\nvar results = await api.Chat.CreateChatCompletionAsync(chatRequest);\nConsole.WriteLine(results);\n\u002F* 출력:\n{\n  \"wins\": {\n\t2020: \"Los Angeles Dodgers\"\n  }\n}\n*\u002F\n```\n\n\n\n\n\n### Completions API\nCompletions은 OpenAI에 의해 레거시로 간주됩니다。Completions API는 `OpenAIAPI.Completions`을 통해 접근합니다：\n\n```csharp\nasync Task\u003CCompletionResult> CreateCompletionAsync(CompletionRequest request);\n\n\u002F\u002F 예를 들어\nvar result = await api.Completions.CreateCompletionAsync(new CompletionRequest(\"One Two Three One Two\", model: Model.CurieText, temperature: 0.1));\n\u002F\u002F 또는\nvar result = await api.Completions.CreateCompletionAsync(\"One Two Three One Two\", temperature: 0.1);\n\u002F\u002F 기타 편의 오버로드\n```\n`CompletionRequest`를 미리 작성하거나 편의를 위해 제공되는 도우미 오버로드를 사용할 수 있습니다。이는 대부분 메타데이터로 구성된 `CompletionResult`를 반환하므로, 단순히 완료된 텍스트만 원한다면 `.ToString()` 메서드를 사용하세요。\n\n#### 스트리밍\n스트리밍은 결과가 생성되는 즉시 받아볼 수 있게 해주며, 이는 특히 Davinci와 같은 느린 모델에서 애플리케이션이 더 반응성이 있도록 도와줍니다。\n\n새로운 C# 8.0 비동기 이터레이터를 사용하면：\n```csharp\nIAsyncEnumerable\u003CCompletionResult> StreamCompletionEnumerableAsync(CompletionRequest request);\n\n\u002F\u002F 예를 들어\nawait foreach (var token in api.Completions.StreamCompletionEnumerableAsync(new CompletionRequest(\"제 이름은 Roger이고 Salesforce의 수석 소프트웨어 엔지니어입니다. 이것은 제 이력서입니다:\", Model.DavinciText, 200, 0.5, 존재 페널티: 0.1, 빈도 페널티: 0.1)))\n{\n\tConsole.Write(token);\n}\n```\n\n또는 클래식 .NET 프레임워크나 C# \u003C8.0을 사용하는 경우：\n```csharp\nasync Task StreamCompletionAsync(CompletionRequest request, Action\u003CCompletionResult> resultHandler);\n\n\u002F\u002F 예를 들어\nawait api.Completions.StreamCompletionAsync(\n\tnew CompletionRequest(\"제 이름은 Roger이고 Salesforce의 수석 소프트웨어 엔지니어입니다. 이것은 제 이력서입니다:\", Model.DavinciText, 200, 0.5, 존재 페널티: 0.1, 빈도 페널티: 0.1),\n\tres => ResumeTextbox.Text += res.ToString());\n```\n\n### 音频\n音频 API 包括文本转语音、转录（语音转文本）以及翻译（非英语语音转英语文本）。\n\n#### 文本转语音 (TTS)\nTTS API 可通过 `OpenAIAPI.TextToSpeech` 访问：\n\n```csharp\nawait api.TextToSpeech.SaveSpeechToFileAsync(\"你好，勇敢的新世界！这是一次测试。\", outputPath);\n\u002F\u002F 你可以用默认的音频播放器打开它，如下所示：\nProcess.Start(outputPath);\n```\n\n你也可以使用 `TextToSpeechRequest` 对象来指定所有请求参数：\n\n```csharp\nvar request = new TextToSpeechRequest()\n{\n\tInput = \"你好，勇敢的新世界！这是一次测试。\",\n\tResponseFormat = ResponseFormats.AAC,\n\tModel = Model.TTS_HD,\n\tVoice = Voices.Nova,\n\tSpeed = 0.9\n};\nawait api.TextToSpeech.SaveSpeechToFileAsync(request, \"test.aac\");\n```\n\n除了保存到文件，你还可以通过 `api.TextToSpeech.GetSpeechAsStreamAsync(request)` 获取音频字节流：\n\n```csharp\nusing (Stream result = await api.TextToSpeech.GetSpeechAsStreamAsync(\"你好，勇敢的新世界！\", Voices.Fable))\nusing (StreamReader reader = new StreamReader(result))\n{\n\t\u002F\u002F 在这里对音频流进行处理\n}\n```\n\n#### 转录（语音转文本）\n\n音频转录 API 允许你从音频中生成文本，支持所有受支持的语言。它可以通过 `OpenAIAPI.Transcriptions` 访问：\n\n```csharp\nstring resultText = await api.Transcriptions.GetTextAsync(\"path\u002Fto\u002Ffile.mp3\");\n```\n\n你可以请求详细结果，这样会提供分段和标记级别的信息，以及标准的 OpenAI 元数据，例如处理时间：\n\n```csharp\nAudioResultVerbose result = await api.Transcriptions.GetWithDetailsAsync(\"path\u002Fto\u002Ffile.m4a\");\nConsole.WriteLine(result.ProcessingTime.TotalMilliseconds); \u002F\u002F 496毫秒\nConsole.WriteLine(result.text); \u002F\u002F “你好，这是转录功能的测试。”\nConsole.WriteLine(result.language); \u002F\u002F “英语”\nConsole.WriteLine(result.segments[0].no_speech_prob); \u002F\u002F 0.03712\n\u002F\u002F 等等\n```\n\n你还可以请求 SRT 或 VTT 格式的结果，这对于为视频生成字幕非常有用：\n\n```csharp\nstring result = await api.Transcriptions.GetAsFormatAsync(\"path\u002Fto\u002Ffile.m4a\", AudioRequest.ResponseFormats.SRT);\n```\n\n额外的参数，如温度、提示、语言等，可以按每次请求指定，也可以设置为默认值：\n\n```csharp\n\u002F\u002F 内联指定\nresult = await api.Transcriptions.GetTextAsync(\"conversation.mp3\", \"en\", \"这是一份医生与其患者之间对话的转录：\", 0.3);\n\n\u002F\u002F 设置默认值\napi.Transcriptions.DefaultTranscriptionRequestArgs.Language = \"en\";\n```\n\n除了提供磁盘上的本地文件，你还可以提供音频字节流。这对于从麦克风或其他来源直接流式传输音频而无需先写入磁盘非常有用。请注意，你必须指定一个文件名，该文件名不必存在，但必须具有与所发送音频类型相符的准确扩展名。OpenAI 会根据文件扩展名来确定你的音频流格式。\n\n```csharp\nusing (var audioStream = File.OpenRead(\"path-here.mp3\"))\n{\n\treturn await api.Transcriptions.GetTextAsync(audioStream, \"file.mp3\");\n}\n```\n\n#### 翻译（非英语语音转英语文本）\n\n翻译功能允许你将任何受支持的语言的语音转录成英语。OpenAI 目前仅支持翻译成英语，不支持其他语言。它可以通过 `OpenAIAPI.Translations` 访问。\n\n它支持与转录功能完全相同的功能：\n\n```csharp\nstring result = await api.Translations.GetTextAsync(\"chinese-example.m4a\");\n```\n\n### 嵌入\n嵌入 API 可通过 `OpenAIAPI.Embeddings` 访问：\n\n```csharp\nasync Task\u003CEmbeddingResult> CreateEmbeddingAsync(EmbeddingRequest request);\n\n\u002F\u002F 例如\nvar result = await api.Embeddings.CreateEmbeddingAsync(new EmbeddingRequest(\"用于嵌入的测试文本\", 模型：Model.AdaTextEmbedding));\n\u002F\u002F 或\nvar result = await api.Embeddings.CreateEmbeddingAsync(\"用于嵌入的测试文本\");\n```\n\n嵌入结果包含大量元数据，实际的浮点向量位于 `result.Data[].Embedding` 中。\n\n为了简化操作，你可以直接请求浮点向量并忽略多余的元数据，方法是使用 `api.Embeddings.GetEmbeddingsAsync(\"test text here\")`。\n\n\n### 内容审核\n内容审核 API 可通过 `OpenAIAPI.Moderation` 访问：\n\n```csharp\nasync Task\u003CModerationResult> CreateEmbeddingAsync(ModerationRequest request);\n\n\u002F\u002F 例如\nvar result = await api.Moderation.CallModerationAsync(new ModerationRequest(\"用于审核的测试文本\", 模型：TextModerationLatest));\n\u002F\u002F 或\nvar result = await api.Moderation.CallModerationAsync(\"用于审核的测试文本\");\n\nConsole.WriteLine(result.results[0].MainContentFlag);\n```\n\n结果位于 `.results[0]` 中，并提供了诸如 `FlaggedCategories` 和 `MainContentFlag` 等便捷方法。\n\n\n### 文件（用于微调）\n文件 API 端点可通过 `OpenAIAPI.Files` 访问：\n\n```csharp\n\u002F\u002F 上传\nasync Task\u003CFile> UploadFileAsync(string filePath, string purpose = \"fine-tune\");\n\n\u002F\u002F 例如\nvar response = await api.Files.UploadFileAsync(\"fine-tuning-data.jsonl\");\nConsole.Write(response.Id); \u002F\u002F 上传文件的 ID\n\n\u002F\u002F 列出文件\nasync Task\u003CList\u003CFile>> GetFilesAsync();\n\n\u002F\u002F 例如\nvar response = await api.Files.GetFilesAsync();\nforeach (var file in response)\n{\n\tConsole.WriteLine(file.Name);\n}\n```\n\n此外，还有获取文件内容、删除文件等方法。\n\n用于微调的端点目前尚未实现，但很快就会添加。\n\n### 图像\nDALL-E 图像生成 API 可通过 `OpenAIAPI.ImageGenerations` 访问：\n\n```csharp\nasync Task\u003CImageResult> CreateImageAsync(ImageGenerationRequest request);\n\n\u002F\u002F 例如\nvar result = await api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest(\"一台正在写测试的电脑的绘画\", 1, ImageSize._512));\n\u002F\u002F 或\nvar result = await api.ImageGenerations.CreateImageAsync(\"一台正在写测试的电脑的绘画\");\n\nConsole.WriteLine(result.Data[0].Url);\n```\n\n图像结果包含在线图片的 URL 或 Base64 编码的图片，具体取决于 `ImageGenerationRequest.ResponseFormat`（默认为 URL）。\n\n#### DALL-E 3\n\n使用 DALL-E 3 的方式如下：\n\n```csharp\nasync Task\u003CImageResult> CreateImageAsync(ImageGenerationRequest request);\n\n\u002F\u002F 例如\nvar result = await api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest(\"一台正在写测试的电脑的绘画\", OpenAI_API.Models.Model.DALLE3, ImageSize._1024x1792, \"hd\"));\n\u002F\u002F 或\nvar result = await api.ImageGenerations.CreateImageAsync(\"一台正在写测试的电脑的绘画\", OpenAI_API.Models.Model.DALLE3);\n\nConsole.WriteLine(result.Data[0].Url);\n```\n\n## Azure\n\n要使用 Azure OpenAI 服务，您需要指定 Azure OpenAI 资源的名称以及模型部署 ID。\n\n_我无法访问 Microsoft Azure 的 OpenAI 服务，因此无法测试此功能。如果您有访问权限并能进行测试，请提交一个问题，描述您的测试结果。同时，也非常欢迎包含集成测试的拉取请求。特别是，目前尚不清楚在 Azure 上指定模型的方式是否与常规用法一致。_\n\n有关更多信息，请参阅 [Azure OpenAI 文档](https:\u002F\u002Flearn.microsoft.com\u002Fen-us\u002Fazure\u002Fcognitive-services\u002Fopenai\u002Freference) 和 [#64 中的详细截图](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fissues\u002F64#issuecomment-1479276020)。\n\n对于 Azure 服务，配置应类似于以下示例：\n\n```csharp\nOpenAIAPI api = OpenAIAPI.ForAzure(\"YourResourceName\", \"deploymentId\", \"api-key\");\napi.ApiVersion = \"2023-03-15-preview\"; \u002F\u002F 需要此版本才能访问 Azure 上的聊天端点\n```\n\n之后您可以像平常一样使用 `api` 对象。此外，您也可以按照上文 [身份验证](#authentication) 部分列出的其他方式来指定 `APIAuthentication`。目前，该库仅支持 API 密钥流，而不支持 AD 流。\n\n截至 2023 年 4 月 2 日，如需访问 Azure 上的聊天端点，您必须手动选择上述的 API 版本 `2023-03-15-preview`。待该版本脱离预览后，我会更新默认设置。\n\n## IHttpClientFactory\n您可以指定一个用于 HTTP 请求的 `IHttpClientFactory`，以便调整 HTTP 请求属性、连接池设置以及进行模拟测试。详情请参阅 [#103](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F103)。\n\n```csharp\nOpenAIAPI api = new OpenAIAPI();\napi.HttpClientFactory = myIHttpClientFactoryObject;\n```\n\n## 文档\n\n每个类、方法和属性都配有详尽的 XML 文档，因此它们应该会自动显示在 IntelliSense 中。结合官方 OpenAI 文档，这些内容足以帮助您快速上手。如果您有任何疑问，欢迎在此处提交问题。未来可能会提供更完善的文档。\n\n## 许可证\n\nCC-0 公有领域\n\n本库采用 CC-0 许可证，属于公有领域。您可以将其用于任何用途，无论是公开还是私密，无需担心许可或授权等问题。它只是 OpenAI API 的封装层，因此您仍然需要直接从 OpenAI 获取访问权限。我与 OpenAI 没有任何关联，本库也未获得他们的认可。我只是拥有 OpenAI 的测试版访问权限，并希望开发一个 C# 库来更便捷地调用该 API。希望其他人也能从中受益。如果您有任何贡献意愿，欢迎提交拉取请求。","# OpenAI-API-dotnet 快速上手指南\n\n## 环境准备\n\n本库基于 **.NET Standard 2.0** 构建，具有广泛的兼容性：\n*   **支持框架**：.NET Framework (>= 4.7.2), .NET Core (>= 3.0), 以及更新的 .NET 5\u002F6\u002F7\u002F8+。\n*   **适用场景**：控制台应用、WinForms、WPF、ASP.NET、Unity、Xamarin 等。\n*   **操作系统**：Windows、Linux、macOS。\n*   **前置依赖**：无特殊系统依赖，仅需安装 NuGet 包。\n\n> **注意**：自 v2.0.0-beta.3 起，微软已发布官方 C# OpenAI 库。本指南针对该仓库维护的 **v1.11.0**（原始非官方版本），该版本依然稳定可用且功能完整。\n\n## 安装步骤\n\n通过 NuGet 包管理器安装 `OpenAI` 版本 1.11.0。\n\n**使用 .NET CLI (推荐):**\n```bash\ndotnet add package OpenAI --version 1.11.0\n```\n\n**使用 Package Manager Console:**\n```powershell\nInstall-Package OpenAI -Version 1.11.0\n```\n\n*(注：国内开发者若遇到下载速度慢的问题，可配置国内 NuGet 镜像源，如阿里云或腾讯云镜像)*\n\n## 基本使用\n\n### 1. 认证配置\n\n在使用 API 前，需配置 `OPENAI_API_KEY`。库支持三种方式（优先级由高到低）：\n1.  **代码直接传入**：在初始化时直接传入 Key。\n2.  **环境变量**：设置系统环境变量 `OPENAI_API_KEY`。\n3.  **配置文件**：在项目根目录或用户目录下创建 `.openai` 文件，内容格式为 `OPENAI_API_KEY=sk-...`。\n\n### 2. 最简单的对话示例\n\n以下代码展示如何初始化 API 并发送一条简单的聊天请求：\n\n```csharp\nusing OpenAI_API;\nusing System;\nusing System.Threading.Tasks;\n\nclass Program\n{\n    static async Task Main(string[] args)\n    {\n        \u002F\u002F 方式 A: 直接在代码中传入 API Key (测试用，生产环境建议用环境变量)\n        var api = new OpenAIAPI(\"YOUR_API_KEY\");\n\n        \u002F\u002F 方式 B: 自动读取环境变量或配置文件\n        \u002F\u002F var api = new OpenAIAPI(); \n\n        \u002F\u002F 发送聊天请求\n        var result = await api.Chat.CreateChatCompletionAsync(\"Hello!\");\n        \n        \u002F\u002F 输出结果\n        Console.WriteLine(result); \n        \u002F\u002F 预期输出类似：\"Hi! How can I help you?\"\n    }\n}\n```\n\n### 3. 进阶：使用对话上下文 (Conversation)\n\n若需要多轮对话（保留历史记录），建议使用 `CreateConversation`：\n\n```csharp\nvar chat = api.Chat.CreateConversation();\nchat.Model = Model.GPT4_Turbo; \u002F\u002F 指定模型\n\n\u002F\u002F 添加系统指令\nchat.AppendSystemMessage(\"你是一个助手，只回答是或否。\");\n\n\u002F\u002F 添加用户输入\nchat.AppendUserInput(\"猫是动物吗？\");\n\n\u002F\u002F 获取回复\nstring response = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F 输出：\"是\"\n\n\u002F\u002F 继续对话（自动包含上文历史）\nchat.AppendUserInput(\"椅子是动物吗？\");\nresponse = await chat.GetResponseFromChatbotAsync();\nConsole.WriteLine(response); \u002F\u002F 输出：\"否\"\n```","一家电商企业的 .NET 开发团队需要在后台系统中集成智能客服功能，以自动回复用户关于订单状态和退货政策的咨询。\n\n### 没有 OpenAI-API-dotnet 时\n- 开发人员必须手动编写复杂的 HTTP 请求代码来处理 REST API 调用，包括设置 Header、序列化 JSON 负载以及处理网络异常，代码冗余且容易出错。\n- 缺乏原生的流式传输（Streaming）支持，用户只能等待模型生成完整回复后才能看到结果，导致交互体验延迟高、不流畅。\n- 管理多轮对话上下文极其繁琐，开发者需自行切割和计算 Token 长度以防止超出限制，极易引发运行时错误或截断关键信息。\n- 集成语音转文字或图片识别（GPT Vision）等多模态功能时，需要额外寻找第三方库或重复造轮子，大幅拉长开发周期。\n\n### 使用 OpenAI-API-dotnet 后\n- 通过简单的 `api.Chat.CreateChatCompletionAsync` 方法即可发起请求，底层网络通信与数据序列化完全自动化，代码量减少 70% 以上。\n- 原生支持流式结果输出，利用 C# 的异步枚举轻松实现打字机效果，显著提升了终端用户的实时交互体验。\n- 内置对话历史管理与上下文长度自动优化机制，开发者只需关注业务逻辑，无需担忧 Token 超限导致的程序崩溃。\n- 统一封装了文本、音频、图像及嵌入向量等全量 API 接口，团队能在一天内快速完成从纯文本到多模态智能客服的功能迭代。\n\nOpenAI-API-dotnet 将复杂的 API 交互转化为直观的 C# 对象操作，让 .NET 开发者能专注于业务创新而非底层通信细节。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FOkGoDoIt_OpenAI-API-dotnet_c55faae3.png","OkGoDoIt","Roger","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FOkGoDoIt_c408da1b.png","AI engineer by day, theater manager by night. Fan of hackathons, machine learning, and wearable computing. Creator of MindPrint.ai, AnswerMagic.ai, and more","Doppler","San Francisco, mostly","github@betechie.com",null,"https:\u002F\u002Frogerpincombe.com","https:\u002F\u002Fgithub.com\u002FOkGoDoIt",[84],{"name":85,"color":86,"percentage":87},"C#","#178600",100,1893,422,"2026-04-06T11:27:05","NOASSERTION","Windows, Linux, macOS","未说明",{"notes":95,"python":96,"dependencies":97},"这是一个 C#\u002F.NET SDK 库，用于调用 OpenAI API，本身不运行本地 AI 模型，因此无需 GPU、大内存或 Python 环境。它作为客户端库运行，支持所有符合 .NET Standard 2.0 的平台（包括控制台应用、WinForms、WPF、ASP.NET、Unity、Xamarin 等）。使用时需要配置 OpenAI API Key。","不适用 (基于 .NET)",[98,99,100],".NET Standard 2.0",".NET Framework >= 4.7.2",".NET Core >= 3.0",[14,35],[103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119],"openai","gpt-3","gpt3","ml","machine-learning","sdk","csharp","dotnet","chatgpt","dall-e","dalle2","dotnet-standard","gpt35","c-sharp","dotnet-core","gpt-4","gpt4","2026-03-27T02:49:30.150509","2026-04-08T22:06:18.031702",[],[124,129,134,139,144,149,154,159,164,169,174,179],{"id":125,"version":126,"summary_zh":127,"released_at":128},154537,"v1.11","自2024年3月起新增嵌入模型。同时增加了对确定性随机种子的支持。\n\n这是[OkGoDoIt的OpenAI封装库](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet)的最终版本。从[v2.0.0-beta](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F2.0.0-beta.3)开始，该库已被微软采纳。新的官方版本将提供全面的功能覆盖，并始终保持最新状态。更多详情请参阅此博客文章：https:\u002F\u002Fdevblogs.microsoft.com\u002Fdotnet\u002Fopenai-dotnet-library\u002F。本GitHub仓库将继续保留，用于记录我编写的原始版本库，直至[1.11版本，该版本目前仍可在NuGet上获取](https:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.11.0)。前往微软新封装库的迁移指南可访问：https:\u002F\u002Fgithub.com\u002Fopenai\u002Fopenai-dotnet\u002Fblob\u002Fmain\u002FMigrationGuide.md。\n\n过去的四年令人振奋。希望这个库能让大家在.NET平台上进行AI开发时更加轻松高效！\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.10...v1.11","2024-06-12T19:06:48",{"id":130,"version":131,"summary_zh":132,"released_at":133},154538,"v1.10","新增了[文本转语音](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet?tab=readme-ov-file#text-to-speech-tts)，以及[音频转录](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet?tab=readme-ov-file#transcription-speech-to-text)和[翻译](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet?tab=readme-ov-file#translations-non-english-speech-to-english-text)功能（基于 Whisper 模型）。\n\n过去一周的最新改进还包括：\n* 新增了截至2023年12月13日的更新模型，包括全新的[GPT-4 Vision](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet?tab=readme-ov-file#gpt-vision)、GPT-4 Turbo，以及[DALL-E 3](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet?tab=readme-ov-file#dall-e-3)。\n* 新增了[JSON 结果格式](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet?tab=readme-ov-file#json-mode)。\n* 修复了聊天结果流式传输的 bug。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.9...v1.10","2023-12-14T04:59:56",{"id":135,"version":136,"summary_zh":137,"released_at":138},154539,"v1.9","新增截至2023年12月11日的更新模型，包括全新的[GPT-4 Vision](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet#gpt-vision)、GPT-4 Turbo，以及[DALL-E 3](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet#dall-e-3)。新增[JSON 结果格式](https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet#json-mode)。修复了聊天结果流式传输的 bug #184。\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.8...v1.9","2023-12-12T06:23:54",{"id":140,"version":141,"summary_zh":142,"released_at":143},154540,"v1.8","## 变更内容\n* 添加并更新了截至 2023 年 12月 6 日的模型，包括全新的 GPT-4 Turbo 和 DALL-E 3。\n* 增加了在聊天对话历史超过上下文窗口时自动修剪的功能。\n\n（对视觉、文本转语音以及 OpenAI DevDay 上展示的所有新功能的支持即将推出，但目前尚未实现。）\n\n## 新贡献者\n* @lofcz 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F112 中完成了首次贡献。\n* @esp0 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F106 中完成了首次贡献。\n* @tomaustin700 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F113 中完成了首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.7.2...v1.8","2023-12-07T00:38:00",{"id":145,"version":146,"summary_zh":147,"released_at":148},154541,"v1.7.2","v1.7.2：修复 ChatMessageRole 中的栈溢出问题，并添加 NuGet 包图标。\n\nv1.7：新增对 GPT-4 的支持、与 ChatGPT 的流式对话功能、IHttpClientFactory 支持，以及多项错误修复。\n\n变更内容\n* @dex3r 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F85 中修复了 ChatMessageRole 中的栈溢出问题。\n* @babrekel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F103 中允许为 OpenAIAPI 指定 HttpClientFactory。\n* @babrekel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F104 中将 Endpoint 属性改用接口而非实现类。\n* @JasonWei512 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F74 中为 Conversation 类添加了流式方法。\n* @HongxuMeng 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F94 中修复了函数调用时参数顺序错误的问题。\n\n新贡献者\n* @dex3r 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F85 中完成了首次贡献。\n* @babrekel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F103 中完成了首次贡献。\n* @JasonWei512 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F74 中完成了首次贡献。\n* @HongxuMeng 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F94 中完成了首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.6...v1.7.2","2023-04-02T17:31:58",{"id":150,"version":151,"summary_zh":152,"released_at":153},154542,"v1.7","新增对 GPT-4 的支持、与 ChatGPT 的流式对话功能、IHttpClientFactory 支持，并修复了多项 bug。\n\n## 变更内容\n* 允许通过 HttpClientFactory 为 OpenAIAPI 分配 HTTP 客户端，由 @babrekel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F103 中实现。\n* 将 Endpoint 属性中的实现替换为接口，由 @babrekel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F104 中完成。\n* 为 Conversation 类添加流式方法，由 @JasonWei512 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F74 中实现。\n* 修复函数调用时参数顺序错误的 bug，由 @HongxuMeng 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F94 中完成。\n\n## 新贡献者\n* @babrekel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F103 中完成了首次贡献。\n* @JasonWei512 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F74 中完成了首次贡献。\n* @HongxuMeng 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F94 中完成了首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.6...v1.7","2023-04-02T09:28:32",{"id":155,"version":156,"summary_zh":157,"released_at":158},154543,"v1.6","新增对 ChatGPT、DALL-E 2 图像生成以及内容审核端点的支持\n\n## 变更内容\n* 基于项目结构添加图像 API（DALL-E），由 @stonelv 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F50 中完成  \n* 图像 API：修复图像 API 的命名问题，并使部分属性类型安全，由 @OkGoDoIt 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F65 中完成  \n* 添加内容审核端点，由 @megalon 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F55 中完成  \n* 功能：内容审核，由 @OkGoDoIt 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F66 中完成  \n* 添加聊天端点，由 @megalon 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F56 中完成  \n* 聊天端点的改进、测试及 README 更新等，由 @OkGoDoIt 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F67 中完成  \n* 为端点和 API 类实现接口，由 @pandapknaepel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F57 中完成  \n* 移除 Azure 端点中的冗余字符，由 @quangsi28 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F51 中完成  \n\n## 新贡献者\n* @quangsi28 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F51 中完成了首次贡献  \n* @stonelv 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F50 中完成了首次贡献  \n* @megalon 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F55 中完成了首次贡献  \n* @pandapknaepel 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F57 中完成了首次贡献  \n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.5...v1.6","2023-03-09T01:26:18",{"id":160,"version":161,"summary_zh":162,"released_at":163},154544,"v1.5","已于2023年2月16日更新，以兼容当前API。修复了若干 minor bug。\r\n现在也应该能与 Azure OpenAI 服务配合使用，不过这一点尚未经过测试。\n\n## 变更内容\n* @ncface 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F40 中实现了 Azure OpenAI 服务的支持。\n\n## 新贡献者\n* @ncface 在 https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F40 中完成了首次贡献。\n* @KeithHenry 贡献了多项 bug 修复和代码优化。\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.4...v1.5","2023-02-16T20:33:46",{"id":165,"version":166,"summary_zh":167,"released_at":168},154545,"v1.4","已更新，自2023年2月3日起与当前API兼容。新增了文件和嵌入端点。由于OpenAI已移除该API，因此移除了搜索端点。\n\nv1.4可能存在破坏性变更：各个端点（如Completions、Models等）及相关类现均已移至各自的命名空间，例如`OpenAI_API.Completions.CompletionRequest`和`OpenAI_API.Models.Model.DavinciText`。现有代码可能需要添加`using`语句或使用完全限定名。此外，搜索端点已被移除，尽管它此前已无法正常使用。\n\n感谢[@GotMike](https:\u002F\u002Fgithub.com\u002Fgotmike)、[@gmilano](https:\u002F\u002Fgithub.com\u002Fgmilano)、[@metjuperry](https:\u002F\u002Fgithub.com\u002Fmetjuperry)和[@Alexei000](https:\u002F\u002Fgithub.com\u002FAlexei000)的贡献！\n\n## 变更内容\n* @gotmike在https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F31中修正了注释中的几处小错别字。\n* @gmilano在https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F22中添加了FilesEndpoint（微调所需端点）。\n* @gotmike在https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F33中移除了未使用的`using`语句，并添加了缺失的属性。\n* @gotmike在https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F35中将Newtonsoft.Json升级至13.0.2。\n* @metjuperry在https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fpull\u002F38中添加了嵌入端点及相应的测试。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002FOkGoDoIt\u002FOpenAI-API-dotnet\u002Fcompare\u002Fv1.3...v1.4","2023-02-03T20:01:45",{"id":170,"version":171,"summary_zh":172,"released_at":173},154546,"v1.3","已更新，自2023年1月12日起与当前API兼容。由于OpenAI已移除Search端点，该端点已被弃用。此版本在指定模型方面进行了破坏性变更，以适配OpenAI API的最新调整。如果您有任何使用旧“engines”参数的代码，需将其更新为“models”。插入、编辑和嵌入功能的支持即将推出。","2023-02-03T01:20:28",{"id":175,"version":176,"summary_zh":177,"released_at":178},154547,"v1.2","Added support for \"echo\" parameter, which echos back the prompt in responses (thanks to @gotmike )  Removed support for publishable API keys (and renamed secret keys to simply API keys) since OpenAI no longer supports publishable keys.  Also fixed various typos in the documentation.","2020-12-23T00:06:46",{"id":180,"version":181,"summary_zh":182,"released_at":183},154548,"v1.1","Added additional API debugging metadata and improved the readme.\r\n\r\nhttps:\u002F\u002Fwww.nuget.org\u002Fpackages\u002FOpenAI\u002F1.1.0","2020-07-28T18:31:08"]