[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-orhanerday--open-ai":3,"tool-orhanerday--open-ai":64},[4,17,25,39,48,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",140436,2,"2026-04-05T23:32:43",[13,14,15],"开发框架","Agent","语言模型","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":10,"last_commit_at":23,"category_tags":24,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,15],{"id":26,"name":27,"github_repo":28,"description_zh":29,"stars":30,"difficulty_score":10,"last_commit_at":31,"category_tags":32,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[33,34,35,36,14,37,15,13,38],"图像","数据工具","视频","插件","其他","音频",{"id":40,"name":41,"github_repo":42,"description_zh":43,"stars":44,"difficulty_score":45,"last_commit_at":46,"category_tags":47,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,3,"2026-04-04T04:44:48",[14,33,13,15,37],{"id":49,"name":50,"github_repo":51,"description_zh":52,"stars":53,"difficulty_score":45,"last_commit_at":54,"category_tags":55,"status":16},519,"PaddleOCR","PaddlePaddle\u002FPaddleOCR","PaddleOCR 是一款基于百度飞桨框架开发的高性能开源光学字符识别工具包。它的核心能力是将图片、PDF 等文档中的文字提取出来，转换成计算机可读取的结构化数据，让机器真正“看懂”图文内容。\n\n面对海量纸质或电子文档，PaddleOCR 解决了人工录入效率低、数字化成本高的问题。尤其在人工智能领域，它扮演着连接图像与大型语言模型（LLM）的桥梁角色，能将视觉信息直接转化为文本输入，助力智能问答、文档分析等应用场景落地。\n\nPaddleOCR 适合开发者、算法研究人员以及有文档自动化需求的普通用户。其技术优势十分明显：不仅支持全球 100 多种语言的识别，还能在 Windows、Linux、macOS 等多个系统上运行，并灵活适配 CPU、GPU、NPU 等各类硬件。作为一个轻量级且社区活跃的开源项目，PaddleOCR 既能满足快速集成的需求，也能支撑前沿的视觉语言研究，是处理文字识别任务的理想选择。",74939,"2026-04-05T23:16:38",[15,33,13,37],{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":45,"last_commit_at":62,"category_tags":63,"status":16},2181,"OpenHands","OpenHands\u002FOpenHands","OpenHands 是一个专注于 AI 驱动开发的开源平台，旨在让智能体（Agent）像人类开发者一样理解、编写和调试代码。它解决了传统编程中重复性劳动多、环境配置复杂以及人机协作效率低等痛点，通过自动化流程显著提升开发速度。\n\n无论是希望提升编码效率的软件工程师、探索智能体技术的研究人员，还是需要快速原型验证的技术团队，都能从中受益。OpenHands 提供了灵活多样的使用方式：既可以通过命令行（CLI）或本地图形界面在个人电脑上轻松上手，体验类似 Devin 的流畅交互；也能利用其强大的 Python SDK 自定义智能体逻辑，甚至在云端大规模部署上千个智能体并行工作。\n\n其核心技术亮点在于模块化的软件智能体 SDK，这不仅构成了平台的引擎，还支持高度可组合的开发模式。此外，OpenHands 在 SWE-bench 基准测试中取得了 77.6% 的优异成绩，证明了其解决真实世界软件工程问题的能力。平台还具备完善的企业级功能，支持与 Slack、Jira 等工具集成，并提供细粒度的权限管理，适合从个人开发者到大型企业的各类用户场景。",70626,"2026-04-05T22:51:36",[15,14,13,36],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":80,"owner_twitter":81,"owner_website":80,"owner_url":82,"languages":83,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":10,"env_os":92,"env_gpu":93,"env_ram":93,"env_deps":94,"category_tags":100,"github_topics":101,"view_count":10,"oss_zip_url":80,"oss_zip_packed_at":80,"status":16,"created_at":112,"updated_at":113,"faqs":114,"releases":144},4205,"orhanerday\u002Fopen-ai","open-ai","OpenAI PHP SDK : Most downloaded, forked, contributed, huge community supported, and used PHP (Laravel , Symfony, Yii, Cake PHP or any PHP framework) SDK for OpenAI GPT-3 and DALL-E. It also supports chatGPT-like streaming. (ChatGPT AI is supported)","open-ai 是一个专为 PHP 开发者打造的开源工具包，旨在让各类 PHP 项目（如 Laravel、Symfony、Yii 等）能够轻松接入 OpenAI 的强大能力。它主要解决了开发者在集成 GPT-3、DALL-E 以及 ChatGPT API 时面临的配置复杂和兼容性问题，提供了一套简洁、安全且稳定的调用方案。\n\n这款工具特别适合熟悉 PHP 语言的软件工程师和技术团队使用，无论是构建智能客服、内容生成应用，还是进行 AI 功能原型开发，都能快速上手。其核心亮点在于极低的运行门槛，仅需 PHP 7.4 及以上版本即可运行，比许多同类库更兼容老旧环境。此外，open-ai 完整支持类似 ChatGPT 的流式响应（Streaming），能让用户实时看到 AI 生成的内容，显著提升交互体验。\n\n作为社区驱动的项目，open-ai 拥有庞大的下载量和活跃的维护团队，并获得了 JetBrains 和 Laravel News 等权威技术媒体的推荐。如果你希望在 PHP 生态中高效利用大模型能力，这是一个值得信赖的选择。","# OpenAI API Client in PHP\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n\n## If you want to ensure this project stays alive and continues to faster improve, please please consider supporting it. Your help means a lot. Thank you!\n* [Buy me a coffee](https:\u002F\u002Fwww.buymeacoffee.com\u002Forhane)\n* [Patreon](https:\u002F\u002Fpatreon.com\u002Forhann)\n> ### ChatGPT API is currently supported, [click here](#chat-as-known-as-chatgpt-api) for the implementation introductions.\n\n\u003Cbr \u002F>\n\n*A message from creator,\u003Cbr \u002F>Thank you for visiting the __@orhanerday\u002Fopen-ai__ repository! If you find this repository helpful or useful, we encourage you to **star** it\non GitHub. Starring a repository is a way to show your support for the project. It also helps to increase the visibility\nof the project and to let the community know that it is valuable. Thanks again for your support and we hope you find the\nrepository useful! \u003Cbr \u002F>\u003Cbr \u002F> Orhan*\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n\n[![Latest Version on Packagist](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fv\u002Forhanerday\u002Fopen-ai.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Forhanerday\u002Fopen-ai)\n[![Total Downloads](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fdt\u002Forhanerday\u002Fopen-ai.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Forhanerday\u002Fopen-ai)\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n\u003Cimg src=\".\u002Fopenai-elephpant.svg\" width=\"1250\" height=\"300\" alt=\"orhanerday-open-ai-logo\">\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n# Featured in\n\n\n[![Jetbrains Blog](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_dd6ddaeb1512.png)](https:\u002F\u002Fblog.jetbrains.com\u002Fphpstorm\u002F2022\u002F12\u002Fphp-annotated-december-2022\u002F#:~:text=orhanerday\u002Fopen%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API)\n\n[![Laravel News](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_cb4db8296bc7.png)](https:\u002F\u002Flaravel-news.com\u002Fopenai-sdk-for-php)\n\n[![日思录](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_241f12b54e3d.png)](http:\u002F\u002Ftubring.cn\u002Farticles\u002F59)\n\n[![logo_new](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_e8a64b79ae6c.png)](https:\u002F\u002Fsite-analyzer.ru\u002Farticles\u002Fopenai-gpt-3-first-samples\u002F)\n\n\n\n# Comparison With Other Packages\n\n| Project Name           | Required PHP Version (Lower is better) | Description                                                                                                                                                | Type (Official \u002F Community) | Support                                                                                                                                  |\n|------------------------|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| **orhanerday\u002Fopen-ai** | **PHP 7.4+**                           | **Most downloaded, forked, contributed, huge community supported, and used PHP SDK for OpenAI GPT-3 and DALL-E. It also supports chatGPT-like streaming.** | Community                   | Available, ([Community driven Discord Server](https:\u002F\u002Fdiscord.gg\u002FxpGUD528XJ) or personal mail [orhann@duck.com](mailto:orhann@duck.com)) |\n| openai-** *\u002Fc****t     | PHP 8.1+                               | OpenAI PHP API client.                                                                                                                                     | Community                   | -                                                                                                                                        |\n\n\n\u003Cbr \u002F>\n\n## About this package\n\nFully open-source and secure community-maintained, PHP SDK for accessing the OpenAI GPT-3 API.\n\n> #### For more information, you can read laravel news [blog post](https:\u002F\u002Flaravel-news.com\u002Fopenai-sdk-for-php).\n> #### Free support is available. [Join our discord server](#join-our-discord-server)\n> #### To get started with this package, you'll first want to be familiar with the [OpenAI API documentation](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Foverview) and [examples](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fexamples). Also you can get help from our discord channel that called [#api-support](https:\u002F\u002Fdiscord.gg\u002FR9CpVUdqQR)\n\n## News\n\n- orhanerday\u002Fopen-ai added to community libraries php [section](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Flibraries\u002Fphp).\n- orhanerday\u002Fopen-ai featured\n  on [PHPStorm blog post](https:\u002F\u002Fblog.jetbrains.com\u002Fphpstorm\u002F2022\u002F12\u002Fphp-annotated-december-2022\u002F#:~:text=orhanerday\u002Fopen%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API),\n  thanks JetBrains!\n\n> Requires PHP 7.4+\n\n## Join our discord server\n\n![Discord Banner 2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_274574048283.png)\n\n[Click here to join the Discord server](https:\u002F\u002Fdiscord.gg\u002FxpGUD528XJ)\n\n## Support this project\n\nAs you may know, OpenAI PHP is an open-source project wrapping tool for OpenAI. We rely on the support of our community\nto continue developing and maintaining the project, and one way that you can help is by making a donation.\n\nDonations allow us to cover expenses such as hosting costs(for testing), development tools, and other resources that are\nnecessary to keep the project running smoothly. Every contribution, no matter how small, helps us to continue improving\nOpenAI PHP for everyone.\n\nIf you have benefited from using OpenAI PHP and would like to support its continued development, we would greatly\nappreciate a donation of any amount. You can make a donation through;\n\n* [Buy me a coffee](https:\u002F\u002Fwww.buymeacoffee.com\u002Forhane)\n* [Patreon](https:\u002F\u002Fpatreon.com\u002Forhann)\n\nThank you for considering a donation to Orhanerday\u002FOpenAI PHP SDK. Your support is greatly appreciated and helps to\nensure that the project can continue to grow and improve.\n\n*Sincerely,*\n\n**Orhan Erday** \u002F Creator.\n\n# Documentation\nPlease visit https:\u002F\u002Forhanerday.gitbook.io\u002Fopenai-php-api-1\u002F\n\n# Endpoint Support\n\n- Chat\n    - [x] [ChatGPT API](#chat-as-known-as-chatgpt-api)\n- Models\n    - [x] [List models](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmodels\u002Flist)\n    - [x] [Retrieve model](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmodels\u002Fretrieve)\n- Completions\n    - [x] [Create completion](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fcompletions\u002Fcreate)\n- Edits\n    - [x] [Create edits](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fedits\u002Fcreate)\n- Images\n    - [x] [Create image](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fimages\u002Fcreate)\n    - [x] [Create image edit](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fimages\u002Fcreate-edit)\n    - [x] [Create image variation](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fimages\u002Fcreate-variation)\n- Embeddings\n    - [x] [Create embeddings](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fembeddings\u002Fcreate)\n- Audio\n    - [x] [Text to Speech (TTS)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Ftext-to-speech)\n    - [x] [Create transcription](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Faudio\u002Fcreate)\n    - [x] [Create translation](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Faudio\u002Fcreate)\n- Files\n    - [x] [List files](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Flist)\n    - [x] [Upload file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fupload)\n    - [x] [Delete file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fdelete)\n    - [x] [Retrieve file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fretrieve)\n    - [x] [Retrieve file content](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fretrieve-content)\n- Fine-tunes\n    - [x] [Create fine-tune (beta)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fcreate)\n    - [x] [List fine-tunes (beta)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Flist)\n    - [x] [Retrieve fine-tune (beta)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fretrieve)\n    - [x] [Cancel fine-tune (beta)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fcancel)\n    - [x] [List fine-tune events (beta)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fevents)\n    - [x] [Delete fine-tune model (beta)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fdelete-model)\n- Moderation\n    - [x] [Create moderation](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmoderations\u002Fcreate)\n- ~~Engines~~ *(deprecated)*\n    - ~~[List engines](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fengines\u002Flist)~~\n    - ~~[Retrieve engine](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fengines\u002Fretrieve)~~\n- Assistants (beta)\n    - [x] [Create assistant](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FcreateAssistant)\n    - [x] [Retrieve assistant](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FgetAssistant)\n    - [x] [Modify assistant](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FmodifyAssistant)\n    - [x] [Delete assistant](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FdeleteAssistant)\n    - [x] [Lists assistants](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FlistAssistants)\n    - [x] [Create assistant file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FcreateAssistantFile)\n    - [x] [Retrieve assistant file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FgetAssistantFile)\n    - [x] [Delete assistant file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FdeleteAssistantFile)\n    - [x] [List assistant files](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FlistAssistantFiles)\n- Threads (beta)\n    - [x] [Create thread](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FcreateThread)\n    - [x] [Retrieve thread](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FgetThread)\n    - [x] [Modify thread](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FmodifyThread)\n    - [x] [Delete thread](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FdeleteThread)\n- Messages (beta)\n    - [x] [Create message](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FcreateMessage)\n    - [x] [Retrieve message](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FgetMessage)\n    - [x] [Modify message](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FmodifyMessage)\n    - [x] [Lists messages](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FlistMessages)\n    - [x] [Retrieve message file](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FgetMessageFile)\n    - [x] [List message files](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FlistMessageFiles)\n- Runs (beta)\n    - [x] [Create run](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FcreateRun)\n    - [x] [Retrieve run](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FgetRun)\n    - [x] [Modify run](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FmodifyRun)\n    - [x] [Lists runs](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FlistRuns)\n    - [x] [Submit tool outputs](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FsubmitToolOutputs)\n    - [x] [Cancel run](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FcancelRun)\n    - [x] [Create thread and run](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FcreateThreadAndRun)\n    - [x] [Retrieve run step](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FgetRunStep)\n    - [x] [List run steps](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FlistRunSteps)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require orhanerday\u002Fopen-ai\n```\n\n## Quick Start ⚡\n\nBefore you get starting, you should set OPENAI_API_KEY as ENV key, and set OpenAI key as env value with the following\ncommands;\n\n_Powershell_\n\n```powershell\n$Env:OPENAI_API_KEY = \"sk-gjtv.....\"\n```\n\n_Cmd_\n\n```cmd\nset OPENAI_API_KEY=sk-gjtv.....\n```\n\n_Linux or macOS_\n\n```shell\nexport OPENAI_API_KEY=sk-gjtv.....\n```\n\n> Getting issues while setting up env? Please read\n> the [article](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F5112595-best-practices-for-api-key-safety) or you can check\n> my [StackOverflow answer](https:\u002F\u002Fstackoverflow.com\u002Fa\u002F73904271\u002F15196622) for the Windows® ENV setup.\n\nCreate your `index.php` file and paste the following code part into the file.\n\n```php\n\u003C?php\n\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php'; \u002F\u002F remove this line if you use a PHP Framework.\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$open_ai_key = getenv('OPENAI_API_KEY');\n$open_ai = new OpenAi($open_ai_key);\n\n$chat = $open_ai->chat([\n   'model' => 'gpt-3.5-turbo',\n   'messages' => [\n       [\n           \"role\" => \"system\",\n           \"content\" => \"You are a helpful assistant.\"\n       ],\n       [\n           \"role\" => \"user\",\n           \"content\" => \"Who won the world series in 2020?\"\n       ],\n       [\n           \"role\" => \"assistant\",\n           \"content\" => \"The Los Angeles Dodgers won the World Series in 2020.\"\n       ],\n       [\n           \"role\" => \"user\",\n           \"content\" => \"Where was it played?\"\n       ],\n   ],\n   'temperature' => 1.0,\n   'max_tokens' => 4000,\n   'frequency_penalty' => 0,\n   'presence_penalty' => 0,\n]);\n\n\nvar_dump($chat);\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\n\u002F\u002F decode response\n$d = json_decode($chat);\n\u002F\u002F Get Content\necho($d->choices[0]->message->content);\n```\n\n_Run the server with the following command_\n\n```shell\nphp -S localhost:8000 -t .\n```\n\n## NVIDIA NIM INTEGRATION\n\norhanerday\u002Fopen-ai supports Nvidia NIM. The below example is MixtralAI. Check https:\u002F\u002Fbuild.nvidia.com\u002Fexplore\u002Fdiscover for more examples.\n\n```php\n\u003C?php\n\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php'; \u002F\u002F remove this line if you use a PHP Framework.\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$nvidia_ai_key = getenv('NVIDIA_AI_API_KEY');\nerror_log($open_ai_key);\n$open_ai = new OpenAi($nvidia_ai_key);\n$open_ai->setBaseURL(\"https:\u002F\u002Fintegrate.api.nvidia.com\");\n$chat = $open_ai->chat([\n    'model' => 'mistralai\u002Fmixtral-8x7b-instruct-v0.1',\n    'messages' => [[\"role\" => \"user\", \"content\" => \"Write a limmerick about the wonders of GPU computing.\"]],\n    'temperature' => 0.5,\n    'max_tokens' => 1024,\n    'top_p' => 1,\n]);\n\nvar_dump($chat);\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\n\u002F\u002F decode response\n$d = json_decode($chat);\n\u002F\u002F Get Content\necho ($d->choices[0]->message->content);\n\n```\n\n\n## Usage\n\n### Load your key from an environment variable.\n\n> According to the following code `$open_ai` is the base variable for all open-ai operations.\n\n```php\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$open_ai = new OpenAi(env('OPEN_AI_API_KEY'));\n```\n\n## Requesting organization\n\nFor users who belong to multiple organizations, you can pass a header to specify which organization is used for an API\nrequest.\nUsage from these API requests will count against the specified organization's subscription quota.\n\n````php\n$open_ai_key = getenv('OPENAI_API_KEY');\n$open_ai = new OpenAi($open_ai_key);\n$open_ai->setORG(\"org-IKN2E1nI3kFYU8ywaqgFRKqi\");\n````\n\n## Base URL\n\nYou can specify Origin URL with `setBaseURL()` method;\n\n````php\n$open_ai_key = getenv('OPENAI_API_KEY');\n$open_ai = new OpenAi($open_ai_key,$originURL);\n$open_ai->setBaseURL(\"https:\u002F\u002Fai.example.com\u002F\");\n````\n\n## Use Proxy\n\nYou can use some proxy servers for your requests api;\n\n````php\n$open_ai->setProxy(\"http:\u002F\u002F127.0.0.1:1086\");\n````\n\n## Set header\n\n ```php\n$open_ai->setHeader([\"Connection\"=>\"keep-alive\"]);\n```\n\n## Get cURL request info\n\n> ### !!! WARNING:Your API key will expose if you add this method to your code, therefore remove the method before deployment. Be careful !\nYou can get cURL info after the request.\n\n````php\n$open_ai = new OpenAi($open_ai_key);\necho $open_ai->listModels(); \u002F\u002F you should execute the request FIRST!\nvar_dump($open_ai->getCURLInfo()); \u002F\u002F You can call the request\n````\n\n## Chat (as known as ChatGPT API)\n\nGiven a chat conversation, the model will return a chat completion response.\n\n ```php\n$complete = $open_ai->chat([\n    'model' => 'gpt-3.5-turbo',\n    'messages' => [\n        [\n            \"role\" => \"system\",\n            \"content\" => \"You are a helpful assistant.\"\n        ],\n        [\n            \"role\" => \"user\",\n            \"content\" => \"Who won the world series in 2020?\"\n        ],\n        [\n            \"role\" => \"assistant\",\n            \"content\" => \"The Los Angeles Dodgers won the World Series in 2020.\"\n        ],\n        [\n            \"role\" => \"user\",\n            \"content\" => \"Where was it played?\"\n        ],\n    ],\n    'temperature' => 1.0,\n    'max_tokens' => 4000,\n    'frequency_penalty' => 0,\n    'presence_penalty' => 0,\n]);\n```\n\n## Accessing the Element\n\n```php\n\u003C?php\n\u002F\u002F Dummy Response For Chat API\n$j = '\n{\n   \"id\":\"chatcmpl-*****\",\n   \"object\":\"chat.completion\",\n   \"created\":1679748856,\n   \"model\":\"gpt-3.5-turbo-0301\",\n   \"usage\":{\n      \"prompt_tokens\":9,\n      \"completion_tokens\":10,\n      \"total_tokens\":19\n   },\n   \"choices\":[\n      {\n         \"message\":{\n            \"role\":\"assistant\",\n            \"content\":\"This is a test of the AI language model.\"\n         },\n         \"finish_reason\":\"length\",\n         \"index\":0\n      }\n   ]\n}\n';\n\n\u002F\u002F decode response\n$d = json_decode($j);\n\n\u002F\u002F Get Content\necho($d->choices[0]->message->content);\n```\n\n> ### Related: [ChatGPT Clone Project](#chatgpt-clone-project)\n\n## Completions\n\nGiven a prompt, the model will return one or more predicted completions, and can also return the probabilities of\nalternative tokens at each position.\n\n ```php\n$complete = $open_ai->completion([\n    'model' => 'gpt-3.5-turbo-instruct',\n    'prompt' => 'Hello',\n    'temperature' => 0.9,\n    'max_tokens' => 150,\n    'frequency_penalty' => 0,\n    'presence_penalty' => 0.6,\n]);\n```\n\n### Stream Example\n\nThis feature might sound familiar from [ChatGPT](https:\u002F\u002Fchat.openai.com\u002Fchat).\n\n\u003Chr>\n\n#### ChatGPT Clone Project\n\nVideo of demo:\n\nhttps:\u002F\u002Fuser-images.githubusercontent.com\u002F22305274\u002F219878695-c76a58c0-5081-402c-a1b5-2b1fd971735a.mp4\n\nChatGPT clone is a simple web application powered by the OpenAI library and built with PHP. It allows users to chat with\nan AI language model that responds in real-time. Chat history is saved using cookies, and the project requires the use\nof an API key and enabled SQLite3.\n\nUrl of The ChatGPT-Clone Repo https:\u002F\u002Fgithub.com\u002Forhanerday\u002FChatGPT\n\n\u003Chr>\n\nWhether to stream back partial progress. If set, tokens will be sent as\ndata-only [server-sent events](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FServer-sent_events\u002FUsing_server-sent_events#event_stream_format)\nas they become available, with the stream terminated by a data: [DONE] message.\n\n ````php\n$open_ai = new OpenAi(env('OPEN_AI_API_KEY'));\n\n$opts = [\n    'prompt' => \"Hello\",\n    'temperature' => 0.9,\n    \"max_tokens\" => 150,\n    \"frequency_penalty\" => 0,\n    \"presence_penalty\" => 0.6,\n    \"stream\" => true,\n];\n\nheader('Content-type: text\u002Fevent-stream');\nheader('Cache-Control: no-cache');\n\n$open_ai->completion($opts, function ($curl_info, $data) {\n    echo $data . \"\u003Cbr>\u003Cbr>\";\n    echo PHP_EOL;\n    ob_flush();\n    flush();\n    return strlen($data);\n});\n\n````\n\nAdd this part inside `\u003Cbody>` of the HTML\n\n ````php\n\n\u003Cdiv id=\"divID\">Hello\u003C\u002Fdiv>\n\u003Cscript>\n    var eventSource = new EventSource(\"\u002F\");\n    var div = document.getElementById('divID');\n\n\n    eventSource.onmessage = function (e) {\n       if(e.data == \"[DONE]\")\n       {\n           div.innerHTML += \"\u003Cbr>\u003Cbr>Hello\";\n       }\n        div.innerHTML += JSON.parse(e.data).choices[0].text;\n    };\n    eventSource.onerror = function (e) {\n        console.log(e);\n    };\n\u003C\u002Fscript>\n````\n\nYou should see a response like the in video;\n\nhttps:\u002F\u002Fuser-images.githubusercontent.com\u002F22305274\u002F209847128-f72c9345-dd34-46f0-bbc5-daf1d7b6121f.mp4\n\n## Edits\n\nCreates a new edit for the provided input, instruction, and parameters\n\n ```php\n    $result = $open_ai->createEdit([\n        \"model\" => \"text-davinci-edit-001\",\n        \"input\" => \"What day of the wek is it?\",\n        \"instruction\" => \"Fix the spelling mistakes\",\n    ]);\n```\n\n## Images (DALL·E)\n\n> All DALL·E Examples available in this [repo](https:\u002F\u002Fgithub.com\u002Forhanerday\u002FDALLE-Examples).\n\nGiven a prompt, the model will return one or more generated images as urls or base64 encoded.\n\n### Create image\n\nCreates an image given a prompt.\n\n ```php\n$complete = $open_ai->image([\n    \"prompt\" => \"A cat drinking milk\",\n    \"n\" => 1,\n    \"size\" => \"256x256\",\n    \"response_format\" => \"url\",\n]);\n```\n\n### Create image edit\n\nCreates an edited or extended image given an original image and a prompt.\n> You need HTML upload for image edit or variation? Please\n> check [DALL·E Examples](https:\u002F\u002Fgithub.com\u002Forhanerday\u002FDALLE-Examples)\n\n````php\n$otter = curl_file_create(__DIR__ . '.\u002Ffiles\u002Fotter.png');\n$mask = curl_file_create(__DIR__ . '.\u002Ffiles\u002Fmask.jpg');\n\n$result = $open_ai->imageEdit([\n    \"image\" => $otter,\n    \"mask\" => $mask,\n    \"prompt\" => \"A cute baby sea otter wearing a beret\",\n    \"n\" => 2,\n    \"size\" => \"1024x1024\",\n]);\n````\n\n### Create image variation\n\nCreates a variation of a given image.\n\n````php\n$otter = curl_file_create(__DIR__ . '.\u002Ffiles\u002Fotter.png');\n\n$result = $open_ai->createImageVariation([\n    \"image\" => $otter,\n    \"n\" => 2,\n    \"size\" => \"256x256\",\n]);\n````\n\n## Searches\n\n**_(Deprecated)_**\n> This endpoint is deprecated and will be removed on December 3rd, 2022\n> OpenAI developed new methods with better\n> performance. [Learn more.](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F6272952-search-transition-guide)\n\nGiven a query and a set of documents or labels, the model ranks each document based on its semantic similarity to the\nprovided query.\n\n```php\n$search = $open_ai->search([\n    'engine' => 'ada',\n    'documents' => ['White House', 'hospital', 'school'],\n    'query' => 'the president',\n]);\n```\n\n## Embeddings\n\nGet a vector representation of a given input that can be easily consumed by machine learning models and algorithms.\n\nRelated guide: [Embeddings](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fembeddings)\n\n### Create embeddings\n\n```php\n$result = $open_ai->embeddings([\n    \"model\" => \"text-similarity-babbage-001\",\n    \"input\" => \"The food was delicious and the waiter...\"\n]);\n```\n\n## Answers\n\n**_(Deprecated)_**\n\n> This endpoint is deprecated and will be removed on December 3rd, 2022\n> We’ve developed new methods with better\n> performance. [Learn more](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F6233728-answers-transition-guide).\n\nGiven a question, a set of documents, and some examples, the API generates an answer to the question based on the\ninformation in the set of documents. This is useful for question-answering applications on sources of truth, like\ncompany documentation or a knowledge base.\n\n  ```php\n$answer = $open_ai->answer([\n    'documents' => ['Puppy A is happy.', 'Puppy B is sad.'],\n    'question' => 'which puppy is happy?',\n    'search_model' => 'ada',\n    'model' => 'curie',\n    'examples_context' => 'In 2017, U.S. life expectancy was 78.6 years.',\n    'examples' => [['What is human life expectancy in the United States?', '78 years.']],\n    'max_tokens' => 5,\n    'stop' => [\"\\n\", '\u003C|endoftext|>'],\n]);\n```\n\n## Classifications\n\n**_(Deprecated)_**\n> This endpoint is deprecated and will be removed on December 3rd, 2022\n> OpenAI developed new methods with better\n> performance. [Learn more.](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F6272941-classifications-transition-guide)\n\nGiven a query and a set of labeled examples, the model will predict the most likely label for the query. Useful as a\ndrop-in replacement for any ML classification or text-to-label task.\n\n ```php\n$classification = $open_ai->classification([\n    'examples' => [\n        ['A happy moment', 'Positive'],\n        ['I am sad.', 'Negative'],\n        ['I am feeling awesome', 'Positive'],\n    ],\n    'labels' => ['Positive', 'Negative', 'Neutral'],\n    'query' => 'It is a raining day =>(',\n    'search_model' => 'ada',\n    'model' => 'curie',\n]);\n```\n\n## Content Moderations\n\nGiven a input text, outputs if the model classifies it as violating OpenAI's content policy.\n\n```php\n$flags = $open_ai->moderation([\n    'input' => 'I want to kill them.'\n]);\n```\n\nKnow more about Content Moderations here: [OpenAI Moderations](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmoderations)\n\n## List engines\n\n**_(Deprecated)_**\n\n> The Engines endpoints are deprecated.\n> Please use their replacement, [Models](#list-models), instead. [Learn more](TODO?).\n\nLists the currently available engines, and provides basic information about each one such as the owner and availability.\n\n ```php\n$engines = $open_ai->engines();\n```\n\n## Audio\n\n### Text To Speech (TTS)\n\n```php\n\n$result = $open_ai->tts([\n    \"model\" => \"tts-1\", \u002F\u002F tts-1-hd\n    \"input\" => \"I'm going to use the stones again. Hey, we'd be going in short-handed, you know\",\n    \"voice\" => \"alloy\", \u002F\u002F echo, fable, onyx, nova, and shimmer\n]);\n\n\u002F\u002F Save audio file\nfile_put_contents('tts-result.mp3', $result);\n```\n\n### Create Transcription\n\nTranscribes audio into the input language.\n\n```php\n$c_file = curl_file_create(__DIR__ . '\u002Ffiles\u002Fen-marvel-endgame.m4a');\n\n$result = $open_ai->transcribe([\n    \"model\" => \"whisper-1\",\n    \"file\" => $c_file,\n]);\n```\n#### Response\n\n```json\n{\n  \"text\": \"I'm going to use the stones again. Hey, we'd be going in short-handed, you know. Look, he's still got the stones, so... So let's get them. Use them to bring everyone back. Just like that? Yeah, just like that. Even if there's a small chance that we can undo this, I mean, we owe it to everyone who's not in this room to try. If we do this, how do we know it's going to end any differently than it did before? Because before you didn't have me. Hey, little girl, everybody in this room is about that superhero life. And if you don't mind my asking, where the hell have you been all this time? There are a lot of other planets in the universe. But unfortunately, they didn't have you guys. I like this one. Let's go get this son of a bitch.\"\n}\n```\n\n### Create Translation\n\nTranslates audio into English.\n\n_I use Turkish voice for translation thanks to famous science YouTuber [Barış Özcan](https:\u002F\u002Fyoutu.be\u002Fr2dQgdktUJg?t=90)_\n\n```php\n$c_file = curl_file_create(__DIR__ . '\u002Ffiles\u002Ftr-baris-ozcan-youtuber.m4a');\n\n$result = $open_ai->translate([\n    \"model\" => \"whisper-1\",\n    \"file\" => $c_file,\n]);\n```\n#### Response\n\n```json\n{\n  \"text\": \"GPT-3. Last month, the biggest leap in the world of artificial intelligence in recent years happened silently. Maybe the biggest leap of all time. GPT-3's beta version was released by OpenAI. When you hear such a sentence, you may think, what kind of leap is this? But be sure, this is the most advanced language model with the most advanced language model with the most advanced language ability. It can answer these artificial intelligence questions, it can translate and even write poetry. Those who have gained access to the API or API of GPT-3 have already started to make very interesting experiments. Let's look at a few examples together. Let's start with an example of aphorism. This site produces beautiful words that you can tweet. Start to actually do things with your words instead of just thinking about them.\"\n}\n```\n\n #### Need HTML upload for audio? Check [this](#upload-file-with-html-form) section and change api references. Example :\n\n```php\n...\n    echo $open_ai->translate(\n        [\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n        ]\n    );\n...\n\u002F\u002F OR\n...\n    echo $open_ai->transcribe(\n        [\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n        ]\n    );\n...\n```\n\n## Files\n\nFiles are used to upload documents that can be used across features like Answers, Search, and Classifications\n\n### List files\n\nReturns a list of files that belong to the user's organization.\n\n```php\n$files = $open_ai->listFiles();\n```\n\n### Upload file\n\nUpload a file that contains document(s) to be used across various endpoints\u002Ffeatures. Currently, the size of all the\nfiles uploaded by one organization can be up to 1 GB. Please contact OpenAI if you need to increase the storage limit.\n\n```php\n$c_file = curl_file_create(__DIR__ . 'files\u002Fsample_file_1.jsonl');\n$result = $open_ai->uploadFile([\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n]);\n```\n\n### Upload file with HTML Form\n\n```php\n\u003Cform action=\"index.php\" method=\"post\" enctype=\"multipart\u002Fform-data\">\n    Select file to upload:\n    \u003Cinput type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\">\n    \u003Cinput type=\"submit\" value=\"Upload File\" name=\"submit\">\n\u003C\u002Fform>\n\u003C?php\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php';\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\nif ($_SERVER['REQUEST_METHOD'] == 'POST') {\n    ob_clean();\n    $open_ai = new OpenAi(env('OPEN_AI_API_KEY'));\n    $tmp_file = $_FILES['fileToUpload']['tmp_name'];\n    $file_name = basename($_FILES['fileToUpload']['name']);\n    $c_file = curl_file_create($tmp_file, $_FILES['fileToUpload']['type'], $file_name);\n\n    echo \"[\";\n    echo $open_ai->uploadFile(\n        [\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n        ]\n    );\n    echo \",\";\n    echo $open_ai->listFiles();\n    echo \"]\";\n\n}\n\n```\n\n### Delete file\n\n ```php\n$result = $open_ai->deleteFile('file-xxxxxxxx');\n```\n\n### Retrieve file\n\n ```php\n$file = $open_ai->retrieveFile('file-xxxxxxxx');\n```\n\n### Retrieve file content\n\n ```php\n$file = $open_ai->retrieveFileContent('file-xxxxxxxx');\n```\n\n## Fine-tunes\n\nManage fine-tuning jobs to tailor a model to your specific training data.\n\n### Create fine-tune\n\n ```php\n$result = $open_ai->createFineTune([\n        \"model\" => \"gpt-3.5-turbo-1106\",\n        \"training_file\" => \"file-U3KoAAtGsjUKSPXwEUDdtw86\",\n]);\n```\n\n### List fine-tune\n\n ```php\n$fine_tunes = $open_ai->listFineTunes();\n```\n\n### Retrieve fine-tune\n\n ```php\n$fine_tune = $open_ai->retrieveFineTune('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n```\n\n### Cancel fine-tune\n\n ```php\n$result = $open_ai->cancelFineTune('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n```\n\n### List fine-tune events\n\n ```php\n$fine_tune_events = $open_ai->listFineTuneEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n```\n\n### Delete fine-tune model\n\n ```php\n$result = $open_ai->deleteFineTune('curie:ft-acmeco-2021-03-03-21-44-20');\n```\n\n## Retrieve engine\n\n**_(Deprecated)_**\n\nRetrieves an engine instance, providing basic information about the engine such as the owner and availability.\n\n ```php\n$engine = $open_ai->engine('davinci');\n```\n\n## Models\n\nList and describe the various models available in the API.\n\n### List models\n\nLists the currently available models, and provides basic information about each one such as the owner and availability.\n\n ```php\n$result = $open_ai->listModels();\n```\n\n### Retrieve model\n\nRetrieves a model instance, providing basic information about the model such as the owner and permissioning.\n\n ```php\n$result = $open_ai->retrieveModel(\"text-ada-001\");\n```\n\n## Printing results *i.e.* `$search`\n\n ```php\necho $search;\n```\n## Assistants (beta)\n\nAllows you to build AI assistants within your own applications.\n\n### Create assistant\n\nCreate an assistant with a model and instructions.\n\n```php\n$data = [\n    'model' => 'gpt-3.5-turbo',\n    'name' => 'my assistant',\n    'description' => 'my assistant description',\n    'instructions' => 'you should cordially help me',\n    'tools' => [],\n    'file_ids' => [],\n];\n\n$assistant = $open_ai->createAssistant($data);\n```\n\n### Retrieve assistant\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n\n$assistant = $open_ai->retrieveAssistant($assistantId);\n```\n\n### Modify assistant\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$data = [\n    'name' => 'my modified assistant',\n    'instructions' => 'you should cordially help me again',\n];\n\n$assistant = $open_ai->modifyAssistant($assistantId, $data);\n```\n\n### Delete assistant\n\n```php\n$assistantId = 'asst_DgiOnXK7nRfyvqoXWpFlwESc';\n\n$assistant = $open_ai->deleteAssistant($assistantId);\n```\n\n### Lists assistants\n\nReturns a list of assistants.\n\n```php\n$query = ['limit' => 10];\n\n$assistants = $open_ai->listAssistants($query);\n```\n\n### Create assistant file\n\nCreate an assistant file by attaching a File to an assistant.\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$fileId = 'file-jrNZZZBAPGnhYUKma7CblGoR';\n\n$file = $open_ai->createAssistantFile($assistantId, $fileId);\n```\n\n### Retrieve assistant file\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$fileId = 'file-jrNZZZBAPGnhYUKma7CblGoR';\n\n$file = $open_ai->retrieveAssistantFile($assistantId, $fileId);\n```\n\n### Delete assistant file\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$fileId = 'file-jrNZZZBAPGnhYUKma7CblGoR';\n\n$file = $open_ai->deleteAssistantFile($assistantId, $fileId);\n```\n\n### List assistant files\n\nReturns a list of assistant files.\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$query = ['limit' => 10];\n\n$files = $open_ai->listAssistantFiles($assistantId, $query);\n```\n\n## Threads (beta)\n\nCreate threads that assistants can interact with.\n\n### Create thread\n\n```php\n$data = [\n    'messages' => [\n        [\n            'role' => 'user',\n            'content' => 'Hello, what is AI?',\n            'file_ids' => [],\n        ],\n    ],\n];\n\n$thread = $open_ai->createThread($data);\n```\n\n### Retrieve thread\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n\n$thread = $open_ai->retrieveThread($threadId);\n```\n\n### Modify thread\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n$data = [\n    'metadata' => ['test' => '1234abcd'],\n];\n\n$thread = $open_ai->modifyThread($threadId, $data);\n```\n\n### Delete thread\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n\n$thread = $open_ai->deleteThread($threadId);\n```\n\n## Messages (beta)\n\nCreate messages within threads.\n\n### Create message\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n$data = [\n    'role' => 'user',\n    'content' => 'How does AI work? Explain it in simple terms.',\n];\n\n$message = $open_ai->createThreadMessage($threadId, $data);\n```\n\n### Retrieve message\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$messageId = 'msg_d37P5XgREsm6BItOcppnBO1b';\n\n$message = $open_ai->retrieveThreadMessage($threadId, $messageId);\n```\n\n### Modify message\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$messageId = 'msg_d37P5XgREsm6BItOcppnBO1b';\n$data = [\n    'metadata' => ['test' => '1234abcd'],\n];\n\n$message = $open_ai->modifyThreadMessage($threadId, $messageId, $data);\n```\n\n### Lists messages\n\nReturns a list of messages for a given thread.\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$query = ['limit' => 10];\n\n$messages = $open_ai->listThreadMessages($threadId, $query);\n```\n\n### Retrieve message file\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$messageId = 'msg_CZ47kAGZugAfeHMX6bmJIukP';\n$fileId = 'file-CRLcY63DiHphWuBrmDWZVCgA';\n\n$file = $open_ai->retrieveMessageFile($threadId, $messageId, $fileId);\n```\n\n### List message files\n\nReturns a list of message files.\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$messageId = 'msg_CZ47kAGZugAfeHMX6bmJIukP';\n$query = ['limit' => 10];\n\n$files = $open_ai->listMessageFiles($threadId, $messageId, $query);\n```\n\n## Runs (beta)\n\nRepresents an execution run on a thread.\n\n### Create run\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$data = ['assistant_id' => 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz'];\n\n$run = $open_ai->createRun($threadId, $data);\n```\n\n### Retrieve run\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n\n$run = $open_ai->retrieveRun($threadId, $runId);\n```\n\n### Modify run\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n$data = [\n    'metadata' => ['test' => 'abcd1234'],\n];\n\n$run = $open_ai->modifyRun($threadId, $runId, $data);\n```\n\n### Lists runs\n\nReturns a list of runs belonging to a thread.\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$query = ['limit' => 10];\n\n$runs = $open_ai->listRuns($threadId, $query);\n```\n\n### Submit tool outputs\n\nWhen a run has the status: \"requires_action\" and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n$outputs = [\n    'tool_outputs' => [\n        ['tool_call_id' => 'call_abc123', 'output' => '28C'],\n    ],\n];\n\n$run = $open_ai->submitToolOutputs($threadId, $runId, $outputs);\n```\n\n### Cancel run\n\nCancels a run that is \"in_progress\".\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n\n$run = $open_ai->cancelRun($threadId, $runId);\n```\n\n### Create thread and run\n\nCreate a thread and run it in one request.\n\n```php\n$data = [\n    'assistant_id' => 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz',\n    'thread' => [\n        'messages' => [\n            [\n                'role' => 'user',\n                'content' => 'Hello, what is AI?',\n                'file_ids' => [],\n            ],\n        ],\n    ],\n];\n\n$run = $open_ai->createThreadAndRun($data);\n```\n\n### Retrieve run step\n\nRetrieves a step in execution of a run.\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n$stepId = 'step_kwLG0vPQjqVyQHVoL7GVK3aG';\n\n$step = $open_ai->retrieveRunStep($threadId, $runId, $stepId);\n```\n\n### List run steps\n\nReturns a list of run steps belonging to a run.\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n$runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n$query = ['limit' => 10];\n\n$steps = $open_ai->listRunSteps($threadId, $runId, $query);\n```\n\n## Testing\n\nTo run all tests:\n\n```bash\ncomposer test\n```\n\nTo run only those tests that work for most user (exclude those that require a missing folder or that hit deprecated\nendpoints no longer available to most users):\n\n```bash\n.\u002Fvendor\u002Fbin\u002Fpest --group=working\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github\u002FCONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease report security vulnerabilities to [orhanerday@gmail.com](mailto:orhanerday@gmail.com)\n\n## Credits\n\n- [Orhan Erday](https:\u002F\u002Fgithub.com\u002Forhanerday)\n- [All Contributors](..\u002F..\u002Fcontributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Donation\n\n\u003Ca href=\"https:\u002F\u002Fwww.buymeacoffee.com\u002Forhane\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fwww.buymeacoffee.com\u002Fassets\u002Fimg\u002Fcustom_images\u002Forange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" >\u003C\u002Fa>\n\n## Star History\n\n[![Star History Chart](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_69f1c14e754b.png)](https:\u002F\u002Fstar-history.com\u002F#orhanerday\u002Fopen-ai&Date)\n","# PHP 中的 OpenAI API 客户端\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n\n## 如果您希望确保该项目持续发展并不断改进，请务必考虑给予支持。您的帮助对我们意义重大。感谢！\n* [请我喝杯咖啡](https:\u002F\u002Fwww.buymeacoffee.com\u002Forhane)\n* [Patreon](https:\u002F\u002Fpatreon.com\u002Forhann)\n> ### 目前已支持 ChatGPT API，有关实现的介绍，请[点击此处](#chat-as-known-as-chatgpt-api)。\n\n\u003Cbr \u002F>\n\n*来自创建者的一则信息：\u003Cbr \u002F>感谢您访问 __@orhanerday\u002Fopen-ai__ 仓库！如果您觉得这个仓库对您有帮助或有用，我们鼓励您在 GitHub 上为它**加星标**。给仓库加星标是表达您对项目支持的一种方式。同时，这也能够提高项目的可见度，并让社区知道它具有价值。再次感谢您的支持，希望您能从这个仓库中受益！\u003Cbr \u002F>\u003Cbr \u002F>Orhan*\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n\n[![Packagist 上的最新版本](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fv\u002Forhanerday\u002Fopen-ai.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Forhanerday\u002Fopen-ai)\n[![总下载量](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fdt\u002Forhanerday\u002Fopen-ai.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Forhanerday\u002Fopen-ai)\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n\u003Cimg src=\".\u002Fopenai-elephpant.svg\" width=\"1250\" height=\"300\" alt=\"orhanerday-open-ai-logo\">\n\n\u003Cbr \u002F>\n\n\u003Cbr \u002F>\n\n# 被以下媒体推荐\n\n\n[![Jetbrains 博客](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_dd6ddaeb1512.png)](https:\u002F\u002Fblog.jetbrains.com\u002Fphpstorm\u002F2022\u002F12\u002Fphp-annotated-december-2022\u002F#:~:text=orhanerday\u002Fopen%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API)\n\n[![Laravel News](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_cb4db8296bc7.png)](https:\u002F\u002Flaravel-news.com\u002Fopenai-sdk-for-php)\n\n[![日思录](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_241f12b54e3d.png)](http:\u002F\u002Ftubring.cn\u002Farticles\u002F59)\n\n[![logo_new](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_e8a64b79ae6c.png)](https:\u002F\u002Fsite-analyzer.ru\u002Farticles\u002Fopenai-gpt-3-first-samples\u002F)\n\n\n\n# 与其他包的比较\n\n| 项目名称           | 所需 PHP 版本（越低越好） | 描述                                                                                                                                                | 类型（官方 \u002F 社区） | 支持                                                                                                                                  |\n|------------------------|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| **orhanerday\u002Fopen-ai** | **PHP 7.4+**                           | **下载量最多、被大量 fork 和贡献、拥有庞大社区支持，是用于访问 OpenAI GPT-3 和 DALL-E 的 PHP SDK。同时也支持类似 ChatGPT 的流式响应。** | 社区                   | 提供支持，([社区驱动的 Discord 服务器](https:\u002F\u002Fdiscord.gg\u002FxpGUD528XJ) 或个人邮件 [orhann@duck.com](mailto:orhann@duck.com)) |\n| openai-** *\u002Fc****t     | PHP 8.1+                               | OpenAI 的 PHP API 客户端。                                                                                                                                     | 社区                   | -                                                                                                                                        |\n\n\n\u003Cbr \u002F>\n\n## 关于本包\n\n完全开源且安全的社区维护版 PHP SDK，用于访问 OpenAI GPT-3 API。\n\n> #### 欲了解更多信息，可阅读 Laravel News 的 [博客文章](https:\u002F\u002Flaravel-news.com\u002Fopenai-sdk-for-php)。\n> #### 提供免费支持。[加入我们的 Discord 服务器](#join-our-discord-server)\n> #### 要开始使用本包，您首先需要熟悉 [OpenAI API 文档](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Foverview) 和 [示例](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fexamples)。此外，您也可以通过名为 [#api-support](https:\u002F\u002Fdiscord.gg\u002FR9CpVUdqQR) 的 Discord 频道获得帮助。\n\n## 最新消息\n\n- orhanerday\u002Fopen-ai 已被添加到 OpenAI 平台的 PHP 社区库 [部分](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Flibraries\u002Fphp)。\n- orhanerday\u002Fopen-ai 被 [PHPStorm 博客文章](https:\u002F\u002Fblog.jetbrains.com\u002Fphpstorm\u002F2022\u002F12\u002Fphp-annotated-december-2022\u002F#:~:text=orhanerday\u002Fopen%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API) 推荐，感谢 JetBrains！\n\n> 需要 PHP 7.4+\n\n## 加入我们的 Discord 服务器\n\n![Discord 横幅 2](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_274574048283.png)\n\n[点击此处加入 Discord 服务器](https:\u002F\u002Fdiscord.gg\u002FxpGUD528XJ)\n\n## 支持本项目\n\n正如您所知，OpenAI PHP 是一个用于封装 OpenAI API 的开源项目。我们依靠社区的支持来继续开发和维护该项目，而您可以通过捐款来提供帮助。\n\n捐款使我们能够支付诸如托管费用（用于测试）、开发工具以及其他维持项目顺利运行所需的资源。无论金额大小，每一份贡献都有助于我们不断改进 OpenAI PHP，使其惠及更多人。\n\n如果您曾受益于使用 OpenAI PHP，并希望支持其持续发展，我们将非常感激您捐赠任意金额。您可以通过以下方式捐款：\n\n* [请我喝杯咖啡](https:\u002F\u002Fwww.buymeacoffee.com\u002Forhane)\n* [Patreon](https:\u002F\u002Fpatreon.com\u002Forhann)\n\n感谢您考虑向 Orhanerday\u002FOpenAI PHP SDK 捐款。您的支持备受珍视，并有助于确保该项目能够持续成长与进步。\n\n*此致，*\n\n**Orhan Erday** \u002F 创建者。\n\n# 文档\n请访问 https:\u002F\u002Forhanerday.gitbook.io\u002Fopenai-php-api-1\u002F\n\n# 终端支持\n\n- 聊天\n    - [x] [ChatGPT API](#chat-as-known-as-chatgpt-api)\n- 模型\n    - [x] [列出模型](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmodels\u002Flist)\n    - [x] [获取模型](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmodels\u002Fretrieve)\n- 完成\n    - [x] [创建完成](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fcompletions\u002Fcreate)\n- 编辑\n    - [x] [创建编辑](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fedits\u002Fcreate)\n- 图片\n    - [x] [创建图片](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fimages\u002Fcreate)\n    - [x] [创建图片编辑](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fimages\u002Fcreate-edit)\n    - [x] [创建图片变体](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fimages\u002Fcreate-variation)\n- 嵌入\n    - [x] [创建嵌入](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fembeddings\u002Fcreate)\n- 音频\n    - [x] [文本转语音 (TTS)](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Ftext-to-speech)\n    - [x] [创建转录](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Faudio\u002Fcreate)\n    - [x] [创建翻译](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Faudio\u002Fcreate)\n- 文件\n    - [x] [列出文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Flist)\n    - [x] [上传文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fupload)\n    - [x] [删除文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fdelete)\n    - [x] [获取文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fretrieve)\n    - [x] [获取文件内容](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffiles\u002Fretrieve-content)\n- 微调\n    - [x] [创建微调（测试版）](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fcreate)\n    - [x] [列出微调（测试版）](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Flist)\n    - [x] [获取微调（测试版）](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fretrieve)\n    - [x] [取消微调（测试版）](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fcancel)\n    - [x] [列出微调事件（测试版）](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fevents)\n    - [x] [删除微调模型（测试版）](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Ffine-tunes\u002Fdelete-model)\n- 内容审核\n    - [x] [创建内容审核](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmoderations\u002Fcreate)\n- ~~引擎~~ *(已弃用)*\n    - ~~[列出引擎](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fengines\u002Flist)~~\n    - ~~[获取引擎](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fengines\u002Fretrieve)~~\n- 助手（测试版）\n    - [x] [创建助手](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FcreateAssistant)\n    - [x] [获取助手](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FgetAssistant)\n    - [x] [修改助手](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FmodifyAssistant)\n    - [x] [删除助手](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FdeleteAssistant)\n    - [x] [列出助手](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FlistAssistants)\n    - [x] [创建助手文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FcreateAssistantFile)\n    - [x] [获取助手文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FgetAssistantFile)\n    - [x] [删除助手文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FdeleteAssistantFile)\n    - [x] [列出助手文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fassistants\u002FlistAssistantFiles)\n- 线程（测试版）\n    - [x] [创建线程](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FcreateThread)\n    - [x] [获取线程](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FgetThread)\n    - [x] [修改线程](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FmodifyThread)\n    - [x] [删除线程](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fthreads\u002FdeleteThread)\n- 消息（测试版）\n    - [x] [创建消息](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FcreateMessage)\n    - [x] [获取消息](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FgetMessage)\n    - [x] [修改消息](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FmodifyMessage)\n    - [x] [列出消息](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FlistMessages)\n    - [x] [获取消息文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FgetMessageFile)\n    - [x] [列出消息文件](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmessages\u002FlistMessageFiles)\n- 运行（测试版）\n    - [x] [创建运行](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FcreateRun)\n    - [x] [获取运行](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FgetRun)\n    - [x] [修改运行](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FmodifyRun)\n    - [x] [列出运行](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FlistRuns)\n    - [x] [提交工具输出](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FsubmitToolOutputs)\n    - [x] [取消运行](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FcancelRun)\n    - [x] [创建线程和运行](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FcreateThreadAndRun)\n    - [x] [获取运行步骤](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FgetRunStep)\n    - [x] [列出运行步骤](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fruns\u002FlistRunSteps)\n\n## 安装\n\n您可以通过 Composer 安装该包：\n\n```bash\ncomposer require orhanerday\u002Fopen-ai\n```\n\n## 快速入门 ⚡\n\n在开始之前，您需要将 `OPENAI_API_KEY` 设置为环境变量，并使用以下命令将其值设置为您的 OpenAI API 密钥：\n\n_PowerShell_\n\n```powershell\n$Env:OPENAI_API_KEY = \"sk-gjtv.....\"\n```\n\n_Cmd_\n\n```cmd\nset OPENAI_API_KEY=sk-gjtv.....\n```\n\n_Linux 或 macOS_\n\n```shell\nexport OPENAI_API_KEY=sk-gjtv.....\n```\n\n> 在设置环境变量时遇到问题？请阅读\n> [这篇文章](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F5112595-best-practices-for-api-key-safety)，或者您可以查看\n> 我的 [StackOverflow 回答](https:\u002F\u002Fstackoverflow.com\u002Fa\u002F73904271\u002F15196622)，了解 Windows® 环境变量的设置方法。\n\n创建您的 `index.php` 文件，并将以下代码粘贴到文件中。\n\n```php\n\u003C?php\n\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php'; \u002F\u002F 如果您使用 PHP 框架，请移除此行。\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$open_ai_key = getenv('OPENAI_API_KEY');\n$open_ai = new OpenAi($open_ai_key);\n\n$chat = $open_ai->chat([\n   'model' => 'gpt-3.5-turbo',\n   'messages' => [\n       [\n           \"role\" => \"system\",\n           \"content\" => \"You are a helpful assistant.\"\n       ],\n       [\n           \"role\" => \"user\",\n           \"content\" => \"Who won the world series in 2020?\"\n       ],\n       [\n           \"role\" => \"assistant\",\n           \"content\" => \"The Los Angeles Dodgers won the World Series in 2020.\"\n       ],\n       [\n           \"role\" => \"user\",\n           \"content\" => \"Where was it played?\"\n       ],\n   ],\n   'temperature' => 1.0,\n   'max_tokens' => 4000,\n   'frequency_penalty' => 0,\n   'presence_penalty' => 0,\n]);\n\n\nvar_dump($chat);\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\n\u002F\u002F 解码响应\n$d = json_decode($chat);\n\u002F\u002F 获取内容\necho($d->choices[0]->message->content);\n```\n\n## 使用以下命令运行服务器\n\n```shell\nphp -S localhost:8000 -t .\n```\n\n## NVIDIA NIM 集成\n\norhanerday\u002Fopen-ai 支持 NVIDIA NIM。以下示例使用的是 MixtralAI。更多示例请访问 https:\u002F\u002Fbuild.nvidia.com\u002Fexplore\u002Fdiscover。\n\n```php\n\u003C?php\n\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php'; \u002F\u002F 如果您使用 PHP 框架，请移除此行。\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$nvidia_ai_key = getenv('NVIDIA_AI_API_KEY');\nerror_log($nvidia_ai_key);\n$open_ai = new OpenAi($nvidia_ai_key);\n$open_ai->setBaseURL(\"https:\u002F\u002Fintegrate.api.nvidia.com\");\n$chat = $open_ai->chat([\n    'model' => 'mistralai\u002Fmixtral-8x7b-instruct-v0.1',\n    'messages' => [[\"role\" => \"user\", \"content\" => \"Write a limmerick about the wonders of GPU computing.\"]],\n    'temperature' => 0.5,\n    'max_tokens' => 1024,\n    'top_p' => 1,\n]);\n\nvar_dump($chat);\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\necho \"\u003Cbr>\";\n\u002F\u002F 解码响应\n$d = json_decode($chat);\n\u002F\u002F 获取内容\necho ($d->choices[0]->message->content);\n\n```\n\n\n## 使用方法\n\n### 从环境变量加载您的密钥。\n\n> 根据以下代码，`$open_ai` 是所有 OpenAI 操作的基础变量。\n\n```php\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$open_ai = new OpenAi(env('OPEN_AI_API_KEY'));\n```\n\n## 请求组织\n\n对于属于多个组织的用户，您可以传递一个头部来指定用于 API 请求的组织。\n这些 API 请求的使用量将计入指定组织的订阅配额。\n\n````php\n$open_ai_key = getenv('OPENAI_API_KEY');\n$open_ai = new OpenAi($open_ai_key);\n$open_ai->setORG(\"org-IKN2E1nI3kFYU8ywaqgFRKqi\");\n````\n\n## 基础 URL\n\n您可以通过 `setBaseURL()` 方法指定基础 URL；\n\n````php\n$open_ai_key = getenv('OPENAI_API_KEY');\n$open_ai = new OpenAi($open_ai_key, $originURL);\n$open_ai->setBaseURL(\"https:\u002F\u002Fai.example.com\u002F\");\n````\n\n## 使用代理\n\n您可以为您的 API 请求使用一些代理服务器；\n\n````php\n$open_ai->setProxy(\"http:\u002F\u002F127.0.0.1:1086\");\n````\n\n## 设置头部\n\n ```php\n$open_ai->setHeader([\"Connection\"=>\"keep-alive\"]);\n```\n\n## 获取 cURL 请求信息\n\n> ### !!! 警告：如果您将此方法添加到您的代码中，您的 API 密钥将会暴露，因此请在部署前移除此方法。请务必小心！\n您可以在请求之后获取 cURL 信息。\n\n````php\n$open_ai = new OpenAi($open_ai_key);\necho $open_ai->listModels(); \u002F\u002F 您必须先执行请求！\nvar_dump($open_ai->getCURLInfo()); \u002F\u002F 您可以调用该请求\n````\n\n## 聊天（也称为 ChatGPT API）\n\n给定一段聊天对话，模型会返回一个聊天完成的响应。\n\n ```php\n$complete = $open_ai->chat([\n    'model' => 'gpt-3.5-turbo',\n    'messages' => [\n        [\n            \"role\" => \"system\",\n            \"content\" => \"You are a helpful assistant.\"\n        ],\n        [\n            \"role\" => \"user\",\n            \"content\" => \"Who won the world series in 2020?\"\n        ],\n        [\n            \"role\" => \"assistant\",\n            \"content\" => \"The Los Angeles Dodgers won the World Series in 2020.\"\n        ],\n        [\n            \"role\" => \"user\",\n            \"content\" => \"Where was it played?\"\n        ],\n    ],\n    'temperature' => 1.0,\n    'max_tokens' => 4000,\n    'frequency_penalty' => 0,\n    'presence_penalty' => 0,\n]);\n```\n\n## 访问元素\n\n```php\n\u003C?php\n\u002F\u002F 聊天 API 的模拟响应\n$j = '\n{\n   \"id\":\"chatcmpl-*****\",\n   \"object\":\"chat.completion\",\n   \"created\":1679748856,\n   \"model\":\"gpt-3.5-turbo-0301\",\n   \"usage\":{\n      \"prompt_tokens\":9,\n      \"completion_tokens\":10,\n      \"total_tokens\":19\n   },\n   \"choices\":[\n      {\n         \"message\":{\n            \"role\":\"assistant\",\n            \"content\":\"This is a test of the AI language model.\"\n         },\n         \"finish_reason\":\"length\",\n         \"index\":0\n      }\n   ]\n}\n';\n\n\u002F\u002F 解码响应\n$d = json_decode($j);\n\n\u002F\u002F 获取内容\necho($d->choices[0]->message->content);\n```\n\n> ### 相关：[ChatGPT 克隆项目](#chatgpt-clone-project)\n\n## 完成\n\n给定一个提示，模型会返回一个或多个预测的完成结果，同时也可以返回每个位置上替代标记的概率。\n\n ```php\n$complete = $open_ai->completion([\n    'model' => 'gpt-3.5-turbo-instruct',\n    'prompt' => 'Hello',\n    'temperature' => 0.9,\n    'max_tokens' => 150,\n    'frequency_penalty' => 0,\n    'presence_penalty' => 0.6,\n]);\n```\n\n### 流式示例\n\n此功能听起来可能与 [ChatGPT](https:\u002F\u002Fchat.openai.com\u002Fchat) 中的功能相似。\n\n\u003Chr>\n\n#### ChatGPT 克隆项目\n\n演示视频：\n\nhttps:\u002F\u002Fuser-images.githubusercontent.com\u002F22305274\u002F219878695-c76a58c0-5081-402c-a1b5-2b1fd971735a.mp4\n\nChatGPT 克隆是一个简单的 Web 应用程序，由 OpenAI 库提供支持，并使用 PHP 构建。它允许用户与一个实时响应的 AI 语言模型进行对话。聊天历史通过 Cookie 保存，该项目需要使用 API 密钥和启用 SQLite3。\n\nChatGPT 克隆仓库地址：https:\u002F\u002Fgithub.com\u002Forhanerday\u002FChatGPT\n\n\u003Chr>\n\n是否流式返回部分进度。如果设置为 true，当标记可用时，它们将作为仅包含数据的 [服务器发送事件](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FServer-sent_events\u002FUsing_server-sent_events#event_stream_format) 发送，流将以 data: [DONE] 消息终止。\n\n ````php\n$open_ai = new OpenAi(env('OPEN_AI_API_KEY'));\n\n$opts = [\n    'prompt' => \"Hello\",\n    'temperature' => 0.9,\n    \"max_tokens\" => 150,\n    \"frequency_penalty\" => 0,\n    \"presence_penalty\" => 0.6,\n    \"stream\" => true,\n];\n\nheader('Content-type: text\u002Fevent-stream');\nheader('Cache-Control: no-cache');\n\n$open_ai->completion($opts, function ($curl_info, $data) {\n    echo $data . \"\u003Cbr>\u003Cbr>\";\n    echo PHP_EOL;\n    ob_flush();\n    flush();\n    return strlen($data);\n});\n\n````\n\n将这部分添加到 HTML 的 `\u003Cbody>` 内\n\n ````php\n\n\u003Cdiv id=\"divID\">Hello\u003C\u002Fdiv>\n\u003Cscript>\n    var eventSource = new EventSource(\"\u002F\");\n    var div = document.getElementById('divID');\n\n\n    eventSource.onmessage = function (e) {\n       if(e.data == \"[DONE]\")\n       {\n           div.innerHTML += \"\u003Cbr>\u003Cbr>Hello\";\n       }\n        div.innerHTML += JSON.parse(e.data).choices[0].text;\n    };\n    eventSource.onerror = function (e) {\n        console.log(e);\n    };\n\u003C\u002Fscript>\n````\n\n你应该会看到像视频中那样的响应；\n\nhttps:\u002F\u002Fuser-images.githubusercontent.com\u002F22305274\u002F209847128-f72c9345-dd34-46f0-bbc5-daf1d7b6121f.mp4\n\n## 编辑\n\n根据提供的输入、指令和参数创建新的编辑内容\n\n ```php\n    $result = $open_ai->createEdit([\n        \"model\" => \"text-davinci-edit-001\",\n        \"input\" => \"What day of the wek is it?\",\n        \"instruction\" => \"Fix the spelling mistakes\",\n    ]);\n```\n\n## 图片（DALL·E）\n\n> 所有 DALL·E 示例都可在该 [仓库](https:\u002F\u002Fgithub.com\u002Forhanerday\u002FDALLE-Examples) 中找到。\n\n给定一个提示，该模型将返回一个或多个生成的图片，以 URL 或 Base64 编码的形式呈现。\n\n### 创建图片\n\n根据提示创建一张图片。\n\n ```php\n$complete = $open_ai->image([\n    \"prompt\" => \"A cat drinking milk\",\n    \"n\" => 1,\n    \"size\" => \"256x256\",\n    \"response_format\" => \"url\",\n]);\n```\n\n### 创建图片编辑\n\n根据原始图片和提示创建编辑或扩展后的图片。\n> 需要用于图片编辑或变体的 HTML 上传吗？请查看 [DALL·E 示例](https:\u002F\u002Fgithub.com\u002Forhanerday\u002FDALLE-Examples)\n\n````php\n$otter = curl_file_create(__DIR__ . '.\u002Ffiles\u002Fotter.png');\n$mask = curl_file_create(__DIR__ . '.\u002Ffiles\u002Fmask.jpg');\n\n$result = $open_ai->imageEdit([\n    \"image\" => $otter,\n    \"mask\" => $mask,\n    \"prompt\" => \"A cute baby sea otter wearing a beret\",\n    \"n\" => 2,\n    \"size\" => \"1024x1024\",\n]);\n````\n\n### 创建图片变体\n\n创建给定图片的变体。\n\n````php\n$otter = curl_file_create(__DIR__ . '.\u002Ffiles\u002Fotter.png');\n\n$result = $open_ai->createImageVariation([\n    \"image\" => $otter,\n    \"n\" => 2,\n    \"size\" => \"256x256\",\n]);\n````\n\n## 搜索\n\n**_(已弃用)_**\n> 此端点已弃用，将于 2022 年 12 月 3 日删除\n> OpenAI 已开发出性能更好的新方法。[了解更多信息。](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F6272952-search-transition-guide)\n\n给定一个查询和一组文档或标签，该模型会根据其语义相似性对每个文档进行排名。\n\n```php\n$search = $open_ai->search([\n    'engine' => 'ada',\n    'documents' => ['White House', 'hospital', 'school'],\n    'query' => 'the president',\n]);\n```\n\n## 嵌入\n\n获取给定输入的向量表示，该表示可以被机器学习模型和算法轻松消费。\n\n相关指南：[嵌入](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Fembeddings)\n\n### 创建嵌入\n\n```php\n$result = $open_ai->embeddings([\n    \"model\" => \"text-similarity-babbage-001\",\n    \"input\" => \"The food was delicious and the waiter...\"\n]);\n```\n\n## 回答\n\n**_(已弃用)_**\n\n> 此端点已弃用，将于 2022 年 12 月 3 日删除\n> 我们已经开发出性能更好的新方法。[了解更多信息](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F6233728-answers-transition-guide)。\n\n给定一个问题、一组文档和一些示例，API 会根据文档中的信息生成问题的答案。这对于基于事实来源（如公司文档或知识库）的问题回答应用非常有用。\n\n  ```php\n$answer = $open_ai->answer([\n    'documents' => ['Puppy A is happy.', 'Puppy B is sad.'],\n    'question' => 'which puppy is happy?',\n    'search_model' => 'ada',\n    'model' => 'curie',\n    'examples_context' => 'In 2017, U.S. life expectancy was 78.6 years.',\n    'examples' => [['What is human life expectancy in the United States?', '78 years.']],\n    'max_tokens' => 5,\n    'stop' => [\"\\n\", '\u003C|endoftext|>'],\n]);\n```\n\n## 分类\n\n**_(已弃用)_**\n> 此端点已弃用，将于 2022 年 12 月 3 日删除\n> OpenAI 已开发出性能更好的新方法。[了解更多信息。](https:\u002F\u002Fhelp.openai.com\u002Fen\u002Farticles\u002F6272941-classifications-transition-guide)\n\n给定一个查询和一组带标签的示例，模型将预测查询最可能的标签。这可以用作任何 ML 分类或文本到标签任务的直接替代品。\n\n ```php\n$classification = $open_ai->classification([\n    'examples' => [\n        ['A happy moment', 'Positive'],\n        ['I am sad.', 'Negative'],\n        ['I am feeling awesome', 'Positive'],\n    ],\n    'labels' => ['Positive', 'Negative', 'Neutral'],\n    'query' => 'It is a raining day =>(',\n    'search_model' => 'ada',\n    'model' => 'curie',\n]);\n```\n\n## 内容审核\n\n给定一段文本输入，输出该模型是否将其分类为违反 OpenAI 的内容政策。\n\n```php\n$flags = $open_ai->moderation([\n    'input' => 'I want to kill them.'\n]);\n```\n\n有关内容审核的更多信息，请参阅：[OpenAI 审核](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fapi-reference\u002Fmoderations)\n\n## 列举引擎\n\n**_(已弃用)_**\n\n> 引擎端点已弃用。\n> 请改用其替代方案，[模型](#list-models]，代替。[了解更多信息](待定?)。\n\n列出当前可用的引擎，并提供关于每个引擎的基本信息，例如所有者和可用性。\n\n ```php\n$engines = $open_ai->engines();\n```\n\n## 音频\n\n### 文本转语音 (TTS)\n\n```php\n\n$result = $open_ai->tts([\n    \"model\" => \"tts-1\", \u002F\u002F tts-1-hd\n    \"input\" => \"我要再次使用无限宝石。嘿，那样我们人手就不够了，你知道的\",\n    \"voice\" => \"alloy\", \u002F\u002F echo, fable, onyx, nova, 和 shimmer\n]);\n\n\u002F\u002F 保存音频文件\nfile_put_contents('tts-result.mp3', $result);\n```\n\n### 创建转录\n\n将音频转录为输入语言。\n\n```php\n$c_file = curl_file_create(__DIR__ . '\u002Ffiles\u002Fen-marvel-endgame.m4a');\n\n$result = $open_ai->transcribe([\n    \"model\" => \"whisper-1\",\n    \"file\" => $c_file,\n]);\n```\n#### 响应\n\n```json\n{\n  \"text\": \"我要再次使用无限宝石。嘿，那样我们人手就不够了，你知道的。你看，他手里还有那些宝石呢，所以……所以我们去把它们拿回来吧。用它们把所有人都救回来。就这么简单吗？是的，就这么简单。就算只有一线希望可以挽回这一切，我觉得我们也应该为那些不在这个房间里的所有人试一试。如果我们这么做，怎么知道结果会和之前不一样呢？因为以前你可没有我啊。喂，小姑娘，这屋子里的人都在追求超级英雄的生活呢。不过冒昧问一句，你这段时间到底跑哪儿去了？宇宙里还有很多其他的星球。可惜那些地方都没有你们这些人。我就喜欢这里。走，咱们去收拾那个混蛋吧。\"\n}\n```\n\n### 创建翻译\n\n将音频翻译成英语。\n\n_我使用土耳其语语音进行翻译，感谢著名科学博主 [Barış Özcan](https:\u002F\u002Fyoutu.be\u002Fr2dQgdktUJg?t=90)_\n\n```php\n$c_file = curl_file_create(__DIR__ . '\u002Ffiles\u002Ftr-baris-ozcan-youtuber.m4a');\n\n$result = $open_ai->translate([\n    \"model\" => \"whisper-1\",\n    \"file\" => $c_file,\n]);\n```\n#### 响应\n\n```json\n{\n  \"text\": \"GPT-3。上个月，人工智能领域近年来最大的飞跃悄然发生。也许是有史以来最大的一次飞跃。OpenAI发布了GPT-3的测试版。听到这样的消息，你可能会想：这到底是什么样的飞跃呢？但请相信，这是目前最先进的语言模型，拥有最强大的语言能力。它可以回答关于人工智能的问题，还能进行翻译，甚至写诗。那些已经获得GPT-3 API访问权限的人，已经开始做一些非常有趣的实验了。让我们一起来看看几个例子。先从格言警句开始。这个网站能生成一些很美的句子，你可以直接发到推特上。与其只是空想，不如真正行动起来，用你的语言去做点什么吧。\"\n}\n```\n\n #### 需要通过 HTML 上传音频文件吗？请查看[此处](#upload-file-with-html-form)的部分，并修改 API 引用。示例：\n\n```php\n...\n    echo $open_ai->translate(\n        [\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n        ]\n    );\n...\n\u002F\u002F 或者\n...\n    echo $open_ai->transcribe(\n        [\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n        ]\n    );\n...\n```\n\n## 文件\n\n文件用于上传可在“答案”、“搜索”和“分类”等功能中使用的文档。\n\n### 列出文件\n\n返回属于用户所在组织的文件列表。\n\n```php\n$files = $open_ai->listFiles();\n```\n\n### 上传文件\n\n上传包含文档的文件，以便在各个端点\u002F功能中使用。目前，一个组织上传的所有文件总大小不得超过 1 GB。如需提高存储限制，请联系 OpenAI。\n\n```php\n$c_file = curl_file_create(__DIR__ . 'files\u002Fsample_file_1.jsonl');\n$result = $open_ai->uploadFile([\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n]);\n```\n\n### 使用 HTML 表单上传文件\n\n```php\n\u003Cform action=\"index.php\" method=\"post\" enctype=\"multipart\u002Fform-data\">\n    选择要上传的文件：\n    \u003Cinput type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\">\n    \u003Cinput type=\"submit\" value=\"上传文件\" name=\"submit\">\n\u003C\u002Fform>\n\u003C?php\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php';\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\nif ($_SERVER['REQUEST_METHOD'] == 'POST') {\n    ob_clean();\n    $open_ai = new OpenAi(env('OPEN_AI_API_KEY'));\n    $tmp_file = $_FILES['fileToUpload']['tmp_name'];\n    $file_name = basename($_FILES['fileToUpload']['name']);\n    $c_file = curl_file_create($tmp_file, $_FILES['fileToUpload']['type'], $file_name);\n\n    echo \"[\";\n    echo $open_ai->uploadFile(\n        [\n            \"purpose\" => \"answers\",\n            \"file\" => $c_file,\n        ]\n    );\n    echo \",\";\n    echo $open_ai->listFiles();\n    echo \"]\";\n\n}\n\n```\n\n### 删除文件\n\n ```php\n$result = $open_ai->deleteFile('file-xxxxxxxx');\n```\n\n### 获取文件\n\n ```php\n$file = $open_ai->retrieveFile('file-xxxxxxxx');\n```\n\n### 获取文件内容\n\n ```php\n$file = $open_ai->retrieveFileContent('file-xxxxxxxx');\n```\n\n## 微调\n\n管理微调任务，以根据您的特定训练数据定制模型。\n\n### 创建微调\n\n ```php\n$result = $open_ai->createFineTune([\n        \"model\" => \"gpt-3.5-turbo-1106\",\n        \"training_file\" => \"file-U3KoAAtGsjUKSPXwEUDdtw86\",\n]);\n```\n\n### 列举微调\n\n ```php\n$fine_tunes = $open_ai->listFineTunes();\n```\n\n### 获取微调\n\n ```php\n$fine_tune = $open_ai->retrieveFineTune('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n```\n\n### 取消微调\n\n ```php\n$result = $open_ai->cancelFineTune('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n```\n\n### 列举微调事件\n\n ```php\n$fine_tune_events = $open_ai->listFineTuneEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F');\n```\n\n### 删除微调模型\n\n ```php\n$result = $open_ai->deleteFineTune('curie:ft-acmeco-2021-03-03-21-44-20');\n```\n\n## 获取引擎\n\n**_(已弃用)_**\n\n获取引擎实例，提供有关引擎的基本信息，例如所有者和可用性。\n\n ```php\n$engine = $open_ai->engine('davinci');\n```\n\n## 模型\n\n列出并描述 API 中可用的各种模型。\n\n### 列出模型\n\n列出当前可用的模型，并提供每个模型的基本信息，例如所有者和可用性。\n\n ```php\n$result = $open_ai->listModels();\n```\n\n### 获取模型\n\n获取模型实例，提供有关模型的基本信息，例如所有者和权限设置。\n\n ```php\n$result = $open_ai->retrieveModel(\"text-ada-001\");\n```\n\n## 打印结果 *即* `$search`\n\n ```php\necho $search;\n```\n\n## 助手（测试版）\n\n允许您在自己的应用程序中构建 AI 助手。\n\n### 创建助手\n\n使用模型和指令创建助手。\n\n```php\n$data = [\n    'model' => 'gpt-3.5-turbo',\n    'name' => '我的助手',\n    'description' => '我的助手描述',\n    'instructions' => '你应该热情地帮助我',\n    'tools' => [],\n    'file_ids' => [],\n];\n\n$assistant = $open_ai->createAssistant($data);\n```\n\n### 获取助手\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n\n$assistant = $open_ai->retrieveAssistant($assistantId);\n```\n\n### 修改助手\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$data = [\n    'name' => '我的修改后的助手',\n    'instructions' => '你应该再次热情地帮助我',\n];\n\n$assistant = $open_ai->modifyAssistant($assistantId, $data);\n```\n\n### 删除助手\n\n```php\n$assistantId = 'asst_DgiOnXK7nRfyvqoXWpFlwESc';\n\n$assistant = $open_ai->deleteAssistant($assistantId);\n```\n\n### 列出助手\n\n返回助手列表。\n\n```php\n$query = ['limit' => 10];\n\n$assistants = $open_ai->listAssistants($query);\n```\n\n### 创建助手文件\n\n通过将文件附加到助手来创建助手文件。\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$fileId = 'file-jrNZZZBAPGnhYUKma7CblGoR';\n\n$file = $open_ai->createAssistantFile($assistantId, $fileId);\n```\n\n### 获取助手文件\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$fileId = 'file-jrNZZZBAPGnhYUKma7CblGoR';\n\n$file = $open_ai->retrieveAssistantFile($assistantId, $fileId);\n```\n\n### 删除助手文件\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$fileId = 'file-jrNZZZBAPGnhYUKma7CblGoR';\n\n$file = $open_ai->deleteAssistantFile($assistantId, $fileId);\n```\n\n### 列出助手文件\n\n返回助手文件列表。\n\n```php\n$assistantId = 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz';\n$query = ['limit' => 10];\n\n$files = $open_ai->listAssistantFiles($assistantId, $query);\n```\n\n## 线程（测试版）\n\n创建助手可以与之交互的线程。\n\n### 创建线程\n\n```php\n$data = [\n    'messages' => [\n        [\n            'role' => 'user',\n            'content' => '你好，什么是AI？',\n            'file_ids' => [],\n        ],\n    ],\n];\n\n$thread = $open_ai->createThread($data);\n```\n\n### 获取线程\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n\n$thread = $open_ai->retrieveThread($threadId);\n```\n\n### 修改线程\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n$data = [\n    'metadata' => ['test' => '1234abcd'],\n];\n\n$thread = $open_ai->modifyThread($threadId, $data);\n```\n\n### 删除线程\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n\n$thread = $open_ai->deleteThread($threadId);\n```\n\n## 消息（测试版）\n\n在线程中创建消息。\n\n### 创建消息\n\n```php\n$threadId = 'thread_YKDArENVWFDO2Xz3POifFYlp';\n$data = [\n    'role' => 'user',\n    'content' => 'AI是如何工作的？用简单的语言解释一下。',\n];\n\n$message = $open_ai->createThreadMessage($threadId, $data);\n```\n\n### 获取消息\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n$messageId = 'msg_d37P5XgREsm6BItOcppnBO1b';\n\n$message = $open_ai->retrieveThreadMessage($threadId, $messageId);\n```\n\n### 修改消息\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n,messageId = 'msg_d37P5XgREsm6BItOcppnBO1b';\n,data = [\n    'metadata' => ['test' => '1234abcd'],\n];\n\n,message = $open_ai->modifyThreadMessage($threadId, $messageId, $data);\n```\n\n### 列出消息\n\n返回给定线程的消息列表。\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n,query = ['limit' => 10];\n\n$messages = $open_ai->listThreadMessages($threadId, $query);\n```\n\n### 获取消息文件\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n,messageId = 'msg_CZ47kAGZugAfeHMX6bmJIukP';\n,fileId = 'file-CRLcY63DiHphWuBrmDWZVCgA';\n\n,file = $open_ai->retrieveMessageFile($threadId, $messageId, $fileId);\n```\n\n### 列出消息文件\n\n返回消息文件列表。\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n,messageId = 'msg_CZ47kAGZugAfeHMX6bmJIukP';\n,query = ['limit' => 10];\n\n$files = $open_ai->listMessageFiles($threadId, $messageId, $query);\n```\n\n## 运行（测试版）\n\n表示在线程上执行的一次运行。\n\n### 创建运行\n\n```php\n$threadId = 'thread_d86alfR2rfF7rASyV4V7hicz';\n,data = ['assistant_id' => 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz'];\n\n$run = $open_ai->createRun($threadId, $data);\n```\n\n### 获取运行\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n\n$run = $open_ai->retrieveRun($threadId, $runId);\n```\n\n### 修改运行\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n,data = [\n    'metadata' => ['test' => 'abcd1234'],\n];\n\n$run = $open_ai->modifyRun($threadId, $runId, $data);\n```\n\n### 列出运行\n\n返回属于某个线程的运行列表。\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,query = ['limit' => 10];\n\n$runs = $open_ai->listRuns($threadId, $query);\n```\n\n### 提交工具输出\n\n当运行状态为“requires_action”且required_action.type为submit_tool_outputs时，可以在所有工具调用完成后使用此端点提交工具输出。所有输出必须在单个请求中提交。\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n,outputss = [\n    'tool_outputs' => [\n        ['tool_call_id' => 'call_abc123', 'output' => '28C'],\n    ],\n];\n\n$run = $open_ai->submitToolOutputs($threadId, $runId, $outputs);\n```\n\n### 取消运行\n\n取消正在“in_progress”中的运行。\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n\n$run = $open_ai->cancelRun($threadId, $runId);\n```\n\n### 创建线程并运行\n\n在一个请求中创建线程并运行它。\n\n```php\n$data = [\n    'assistant_id' => 'asst_zT1LLZ8dWnuFCrMFzqxFOhzz',\n    'thread' => [\n        'messages' => [\n            [\n                'role' => 'user',\n                'content' => '你好，什么是AI？',\n                'file_ids' => [],\n            ],\n        ],\n    ],\n];\n\n$run = $open_ai->createThreadAndRun($data);\n```\n\n### 获取运行步骤\n\n获取运行执行过程中的一个步骤。\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n,stepId = 'step_kwLG0vPQjqVyQHVoL7GVK3aG';\n\n$step = $open_ai->retrieveRunStep($threadId, $runId, $stepId);\n```\n\n### 列出运行步骤\n\n返回属于某个运行的运行步骤列表。\n\n```php\n$threadId = 'thread_JZbzCYpYgpNb79FNeneO3cGI';\n,runId = 'run_xBKYFcD2Jg3gnfrje6fhiyXj';\n,query = ['limit' => 10];\n\n$steps = $open_ai->listRunSteps($threadId, $runId, $query);\n```\n\n## 测试\n\n运行所有测试：\n\n```bash\ncomposer test\n```\n\n仅运行对大多数用户有效的测试（排除那些需要缺失文件夹或调用已弃用且大多数用户不再可用的端点的测试）：\n\n```bash\n.\u002Fvendor\u002Fbin\u002Fpest --group=working\n```\n\n## 更改记录\n\n请参阅 [CHANGELOG](CHANGELOG.md) 以了解最近的更改内容。\n\n## 贡献\n\n详情请参阅 [.github\u002FCONTRIBUTING.md](.github\u002FCONTRIBUTING.md)。\n\n## 安全漏洞\n\n如有安全漏洞，请向 [orhanerday@gmail.com](mailto:orhanerday@gmail.com) 报告。\n\n## 致谢\n\n- [Orhan Erday](https:\u002F\u002Fgithub.com\u002Forhanerday)\n- [所有贡献者](..\u002F..\u002Fcontributors)\n\n## 许可证\n\nMIT 许可证 (MIT)。更多信息请参阅 [许可证文件](LICENSE.md)。\n\n## 捐赠\n\n\u003Ca href=\"https:\u002F\u002Fwww.buymeacoffee.com\u002Forhane\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fwww.buymeacoffee.com\u002Fassets\u002Fimg\u002Fcustom_images\u002Forange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" >\u003C\u002Fa>\n\n## 星标历史\n\n[![星标历史图表](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_readme_69f1c14e754b.png)](https:\u002F\u002Fstar-history.com\u002F#orhanerday\u002Fopen-ai&Date)","# OpenAI PHP SDK 快速上手指南\n\n本指南帮助中国开发者快速集成 `orhanerday\u002Fopen-ai`，这是一个社区维护的、功能全面的 OpenAI API PHP 客户端。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **PHP 版本**：PHP 7.4 或更高版本（推荐 PHP 8.0+）。\n*   **包管理器**：已安装 [Composer](https:\u002F\u002Fgetcomposer.org\u002F)。\n*   **API 密钥**：拥有有效的 OpenAI API Key (`sk-...`)。\n*   **网络环境**：由于 OpenAI 服务在中国大陆无法直接访问，请确保您的服务器或开发环境已配置好代理（HTTP_PROXY\u002FHTTPS_PROXY），或使用能够访问 OpenAI 接口的网络环境。\n\n## 安装步骤\n\n使用 Composer 将包安装到您的项目中。\n\n### 1. 基础安装\n在项目根目录下运行以下命令：\n\n```bash\ncomposer require orhanerday\u002Fopen-ai\n```\n\n### 2. 国内加速安装（推荐）\n如果您在国内遇到下载速度慢或超时的问题，建议先配置阿里云或腾讯云镜像源，然后再执行安装：\n\n```bash\n# 配置阿里云 Composer 全量镜像\ncomposer config -g repo.packagist composer https:\u002F\u002Fmirrors.aliyun.com\u002Fcomposer\u002F\n\n# 执行安装\ncomposer require orhanerday\u002Fopen-ai\n```\n\n## 基本使用\n\n### 1. 配置 API Key\n\n在使用 SDK 之前，您需要将 OpenAI API Key 设置为环境变量。根据您的操作系统选择对应的命令：\n\n**Linux \u002F macOS:**\n```shell\nexport OPENAI_API_KEY=\"sk-gjtv.....\"\n```\n\n**Windows (PowerShell):**\n```powershell\n$Env:OPENAI_API_KEY = \"sk-gjtv.....\"\n```\n\n**Windows (CMD):**\n```cmd\nset OPENAI_API_KEY=sk-gjtv.....\n```\n\n> **注意**：如果在生产环境中，建议将 Key 写入 `.env` 文件并通过框架（如 Laravel）读取，或在代码初始化时直接传入。\n\n### 2. 代码示例\n\n以下是一个最简单的调用示例，用于发送消息给 ChatGPT 并获取回复：\n\n```php\n\u003C?php\n\nrequire 'vendor\u002Fautoload.php';\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\n\u002F\u002F 初始化客户端\n\u002F\u002F 如果已设置环境变量 OPENAI_API_KEY，可以不传参数；否则请在构造函数中传入 key\n$open_ai = new OpenAi(); \n\n\u002F\u002F 或者显式传入 Key\n\u002F\u002F $open_ai = new OpenAi('sk-gjtv.....');\n\n\u002F\u002F 构建请求数据\n$data = [\n    \"model\" => \"gpt-3.5-turbo\",\n    \"messages\" => [\n        [\n            \"role\" => \"user\",\n            \"content\" => \"你好，请用中文介绍一下什么是人工智能？\"\n        ]\n    ],\n    \"temperature\" => 0.9,\n    \"max_tokens\" => 150,\n    \"frequency_penalty\" => 0,\n    \"presence_penalty\" => 0,\n];\n\n\u002F\u002F 发送请求\n$response = $open_ai->chat($data);\n\n\u002F\u002F 处理响应\n$result = json_decode($response, true);\n\nif (isset($result['choices'][0]['message']['content'])) {\n    echo \"AI 回复：\" . $result['choices'][0]['message']['content'];\n} else {\n    echo \"请求失败或返回格式异常：\" . $response;\n}\n```\n\n### 3. 流式输出（Stream）示例\n\n该 SDK 支持类似 ChatGPT 网页版的流式输出效果：\n\n```php\n\u003C?php\n\nrequire 'vendor\u002Fautoload.php';\n\nuse Orhanerday\\OpenAi\\OpenAi;\n\n$open_ai = new OpenAi();\n\n$data = [\n    \"model\" => \"gpt-3.5-turbo\",\n    \"messages\" => [[\"role\" => \"user\", \"content\" => \"讲一个短笑话\"]],\n    \"stream\" => true, \u002F\u002F 开启流式模式\n];\n\n\u002F\u002F 第二个参数为回调函数，实时处理返回的数据块\n$open_ai->chat($data, function ($curl_info, $data) {\n    echo $data; \u002F\u002F 直接输出增量内容\n    return strlen($data);\n});\n```\n\n更多高级用法（如图片生成、语音转录、Fine-tuning 等）请参考官方文档或 SDK 源码中的方法列表。","一家电商公司的后端团队正在为其基于 Laravel 构建的客服系统中集成智能自动回复功能，需要快速对接 OpenAI 的 GPT-3.5 和 DALL-E 模型。\n\n### 没有 open-ai 时\n- 开发人员必须手动编写复杂的 HTTP 请求代码来处理 API 认证、参数序列化及错误重试机制，极易出错且难以维护。\n- 想要实现类似 ChatGPT 的流式输出（Streaming）体验，需要底层处理 SSE 事件流，技术门槛高且耗时漫长。\n- 团队需在多个 PHP 版本间反复测试兼容性，若遇到 API 变更，整个自定义封装层需推倒重来，升级成本极高。\n- 缺乏社区支持，遇到鉴权失败或响应解析异常时，只能独自排查文档，严重拖慢项目上线进度。\n\n### 使用 open-ai 后\n- 通过简洁的链式调用即可完成复杂交互，open-ai 内部已完美封装了认证与请求逻辑，代码量减少 80% 以上。\n- 原生支持流式传输接口，仅需几行配置即可在网页端实现打字机效果的实时回复，显著提升用户体验。\n- 兼容 PHP 7.4 及以上版本，无缝适配 Laravel、Symfony 等主流框架，社区持续跟进官方 API 变更，升级只需更新依赖。\n- 拥有活跃的 Discord 社区和海量的实战案例参考，遇到技术问题能迅速获得解决方案，开发效率大幅提升。\n\nopen-ai 将繁琐的底层通信细节转化为优雅的 PHP 语法，让开发者能专注于业务逻辑而非重复造轮子。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Forhanerday_open-ai_e5ce8caa.png","orhanerday","Orhan erday","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Forhanerday_3cfe093f.jpg","Software Engineer at @Honeywell | @Bumble | via Orion Innovation","Orion Innovation | @Honeywell | @Bumble",null,"orhan_erday","https:\u002F\u002Fgithub.com\u002Forhanerday",[84],{"name":85,"color":86,"percentage":87},"PHP","#4F5D95",100,2368,296,"2026-04-05T18:31:03","MIT","Linux, macOS, Windows","未说明",{"notes":95,"python":96,"dependencies":97},"这是一个用于访问 OpenAI API 的 PHP SDK，并非本地运行的 AI 模型，因此无需 GPU 或大量内存。主要依赖是 PHP 7.4 及以上版本和 Composer 包管理器。使用前需配置 OPENAI_API_KEY 环境变量。","不适用 (本项目为 PHP 库)",[98,99],"PHP >= 7.4","Composer",[15,36],[102,103,104,105,106,107,108,109,110,111],"openai","gpt-3","laravel","php","dall-e","dalle2","openai-api","cakephp","symfony","yii","2026-03-27T02:49:30.150509","2026-04-06T14:04:00.546317",[115,120,125,130,135,140],{"id":116,"question_zh":117,"answer_zh":118,"source_url":119},19155,"为什么模型调用返回 false、null 或不打印任何结果？","这通常与 SSL 证书验证问题有关。可以通过在 `open-ai\u002Fsrc\u002FOpenAi.php` 文件中的 `$curl_info` 变量末尾添加以下配置来绕过该问题：\n```php\nCURLOPT_SSL_VERIFYPEER => false,\nCURLOPT_SSL_VERIFYHOST => false,\n```\n注意：禁用 SSL 验证仅适用于开发环境，生产环境请确保证书配置正确。","https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fissues\u002F12",{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},19156,"v4.5 版本调用任何发送 curl 请求的函数时抛出异常怎么办？","这是 v4.5 版本的一个 Bug，原因是 `curl_getinfo()` 在 `curl_close()` 之后被调用，导致资源无效。该问题已在 v4.6 版本中修复。请执行以下命令升级版本：\n```bash\ncomposer update\n```\n或者手动将版本升级到 4.6 及以上。","https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fissues\u002F62",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},19157,"是否支持新的 Assistants API（助手 API）？","是的，从 5.0 版本开始已支持 Assistants API。请运行以下命令更新依赖：\n```bash\ncomposer update\n```\n更新后即可使用包含持久线程和文件处理功能的新 API。","https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fissues\u002F115",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},19158,"使用 stream（流式传输）时返回的数据格式混乱或难以解析怎么办？","流式返回的数据是 Server-Sent Events (SSE) 格式，每一行以 `data: ` 开头。需要在回调函数中对数据进行清洗和解析。建议去除 `data: ` 前缀并忽略 `[DONE]` 标记，然后对剩余的 JSON 字符串进行 `json_decode` 处理。如果问题持续，可能需要检查 OpenAI 社区论坛或自行编写解析逻辑来处理分块数据。","https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fissues\u002F109",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},19159,"为什么开启 stream 模式后无法捕获错误（如 API Key 错误）？","这是一个已知限制，流式模式下库本身难以直接捕获某些 HTTP 层面的错误。建议在实现流式接收时，增加对返回内容的检查逻辑。如果返回的数据中包含错误信息（通常是非 JSON 格式或特定的错误字段），需要在客户端代码中进行额外判断和处理，而不能完全依赖库的异常抛出机制。","https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fissues\u002F42",{"id":141,"question_zh":142,"answer_zh":143,"source_url":119},19160,"在 Symfony 或其他框架中使用该库遇到相同连接问题如何解决？","如果在 Symfony 或其他框架中遇到连接失败或返回 false 的问题，通常也是 SSL 配置导致的。解决方案与 Laravel 类似：修改库源码 `open-ai\u002Fsrc\u002FOpenAi.php`，在 curl 初始化配置数组中加入：\n```php\nCURLOPT_SSL_VERIFYPEER => false,\nCURLOPT_SSL_VERIFYHOST => false,\n```\n此外，有时问题可能是暂时的网络波动，等待一段时间（如 24 小时）后可能会自动恢复。",[145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240],{"id":146,"version":147,"summary_zh":148,"released_at":149},117167,"5.3","## 变更内容\n* 由 @orhanerday 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F154 中更新了 README.md\n* :package: 由 @andrew-demb 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F158 中将 beta.openai.com 替换为 platform.openai.com\n\n## 新贡献者\n* @andrew-demb 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F158 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F5.2...5.3","2025-03-12T12:05:15",{"id":151,"version":152,"summary_zh":153,"released_at":154},117168,"5.2","## 变更内容\n* 支持 OpenAI-Beta 助手 v2 版本及流式传输。由 @thomasdv 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F141 中实现。\n\n## 新贡献者\n* @thomasdv 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F141 中完成了首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F5.1...5.2","2024-05-30T12:22:10",{"id":156,"version":157,"summary_zh":158,"released_at":159},117169,"5.1","## 变更内容\n* 文本转语音功能，由 @yakupseymen 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F133 中实现\n\n## 新贡献者\n* @yakupseymen 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F133 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F5.0...5.1","2024-01-25T06:43:56",{"id":161,"version":162,"summary_zh":163,"released_at":164},117170,"5.0","感谢 @joacir 的贡献，新增了若干 API 端点。\n非常感激他付出的时间和努力。再次表示衷心的感谢。\n\n\n## 变更内容\n* 由 @orhanerday 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F122 中更新了 README.md 文件\n* 由 @joacir 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F130 中新增了用于 Assistants 的 API 端点\n\n## 新贡献者\n* @joacir 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F130 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.9.1...5.0","2023-11-30T06:53:09",{"id":166,"version":167,"summary_zh":168,"released_at":169},117171,"4.9.1","## 变更内容\n* 由 @dependabot 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F111 中将 stefanzweifel\u002Fgit-auto-commit-action 从 4 升级到 5。\n* 由 @fireqong 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F117 中修改了 createFineTune 端点，并更新了 README 示例。\n\n## 新贡献者\n* @fireqong 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F117 中完成了首次贡献。\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.9...4.9.1","2023-11-13T04:08:00",{"id":171,"version":172,"summary_zh":173,"released_at":174},117172,"4.9","## 变更内容\n* @dependabot 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F106 中将 actions\u002Fcheckout 从 3 升级到 4\n* @dependabot 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F99 中将 dependabot\u002Ffetch-metadata 从 1.5.1 升级到 1.6.0\n* @dougkulak 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F102 中修改 sendRequest，使其在响应为 false 时抛出包含 curl_error 的异常\n\n## 新贡献者\n* @dougkulak 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F102 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.8...4.9","2023-10-28T17:36:42",{"id":176,"version":177,"summary_zh":178,"released_at":179},117173,"4.8","## 变更内容\n* @orhanerday 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F94 中更新了 README.md\n* @dependabot 将 dependabot\u002Ffetch-metadata 从 1.4.0 升级到 1.5.1，在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F95 中完成\n* @reply2future 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F85 中修复了流检查条件\n\n## 新贡献者\n* @reply2future 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F85 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.7.2...4.8","2023-06-11T09:29:23",{"id":181,"version":182,"summary_zh":183,"released_at":184},117174,"4.7.2","## 变更内容\n* @slaFFik 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F74 中修复了 README.md 文件中库名称的拼写错误。\n* @dependabot 将 dependabot\u002Ffetch-metadata 从 1.3.6 升级到 1.4.0，详情见 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F88。\n\n## 新贡献者\n* @slaFFik 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F74 中完成了首次贡献。\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.7.1...4.7.2","2023-05-15T07:52:51",{"id":186,"version":187,"summary_zh":188,"released_at":189},117175,"4.7.1","## 变更内容\n* 由 @gouguoyin 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F68 中修复了一个 bug\n* 由 @gouguoyin 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F69 中修复了描述顺序错误的问题\n\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.7...4.7.1","2023-03-08T08:04:39",{"id":191,"version":192,"summary_zh":193,"released_at":194},117176,"4.7","## 变更内容\n* @gouguoyin 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F67 中添加了 `setBaseURL` 和 `setHeader` 方法\n\n## 新贡献者\n* @gouguoyin 在 https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F67 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.6...4.7","2023-03-08T07:25:18",{"id":196,"version":197,"summary_zh":198,"released_at":199},117177,"4.6","## What's Changed\r\n* Fix calling curl_getinfo after curl_close() in sendRequest by @mahadsprouttech in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F63\r\n\r\n## New Contributors\r\n* @mahadsprouttech made their first contribution in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F63\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.5...4.6","2023-03-04T19:10:24",{"id":201,"version":202,"summary_zh":203,"released_at":204},117178,"4.5","Audio Feature added\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.1...4.5","2023-03-04T15:12:59",{"id":206,"version":207,"summary_zh":208,"released_at":209},117179,"4.1","Proxy support\r\n\r\n## What's Changed\r\n* feat: support set proxy  by @djunny in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F61\r\n\r\n## New Contributors\r\n* @djunny made their first contribution in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F61\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F4.0...4.1","2023-03-04T10:41:21",{"id":211,"version":212,"summary_zh":213,"released_at":214},117180,"4.0","## What's Changed\r\n* Update CHANGELOG.md by @marcosegato in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F55\r\n* Added ChatGPT (chat-completions) API by @bashar94 in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F57\r\n\r\n## New Contributors\r\n* @marcosegato made their first contribution at https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F55\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.5...4.0","2023-03-02T05:40:30",{"id":216,"version":217,"summary_zh":218,"released_at":219},117181,"3.5","## What's Changed\r\n* Fix \"export-ignore\" does not work by @assert6 in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F43\r\n* Update README.md by @ali-wells in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F45\r\n* Bump dependabot\u002Ffetch-metadata from 1.3.5 to 1.3.6 by @dependabot in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F47\r\n* Add customURL support. by @orhanerday in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F49\r\n\r\n## New Contributors\r\n* @assert6 made their first contribution in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F43\r\n* @ali-wells made their first contribution in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F45\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.4...3.5","2023-02-10T09:16:12",{"id":221,"version":222,"summary_zh":223,"released_at":224},117182,"3.4","## What's Changed\r\n* Add organization support. by @orhanerday in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F40\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.3...3.4","2023-01-03T07:45:50",{"id":226,"version":227,"summary_zh":228,"released_at":229},117183,"3.3","# **Server-Sent Events**\r\n\r\n## What's Changed\r\n* 36 feature request support stream by @orhanerday in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F37\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.2.1...3.3","2022-12-28T16:18:55",{"id":231,"version":232,"summary_zh":233,"released_at":234},117184,"3.2.1","**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.2...3.2.1","2022-12-07T15:55:46",{"id":236,"version":237,"summary_zh":238,"released_at":239},117185,"3.2","## What's Changed\r\n* Ability to set a timeout value in seconds by @dsampaolo in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F31\r\n\r\n## New Contributors\r\n* @dsampaolo made their first contribution in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F31\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.1...3.2","2022-12-06T10:04:09",{"id":241,"version":242,"summary_zh":243,"released_at":244},117186,"3.1","## What's Changed\r\n* Bump dependabot\u002Ffetch-metadata from 1.3.4 to 1.3.5 by @dependabot in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F28\r\n* Fix tests by @adetch in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F29\r\n* Add current completion endpoint by @adetch in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F30\r\n\r\n## New Contributors\r\n* @adetch made their first contribution in https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fpull\u002F29\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Forhanerday\u002Fopen-ai\u002Fcompare\u002F3.0...3.1","2022-11-22T05:10:36"]