OpenAi assistant run always fails when called from PHP

server/2024/9/23 23:21:46/
aidu_pl">

题意:从 PHP 调用时,OpenAI 助理运行总是失败。

问题背景:

The runs I create with the openai-php library fail direct in 100% of cases. What am I doing wrong? I do not have much experience with php but this is the test script.

我使用 openai-php 库创建的运行在 100% 的情况下直接失败。我哪里做错了?我对 PHP 没有太多经验,这是测试脚本。

php"><?php
require '../../../dev/vendor/autoload.php';$apiKey = getenv('ASSISTANT_API_KEY');@ini_set('zlib.output_compression',0);
@ini_set('implicit_flush',1);
@ob_end_clean();
set_time_limit(0);
ob_implicit_flush(1);$client = OpenAI::client($apiKey);echo "Creating thread...<br/>";
$response = $client->threads()->create([]);$array = $response->toArray(); 
$threadId = $response->id;echo "Thread created, id:" . $response->id . "<br/>";echo "Adding message Hello World...<br/>";$response = $client->threads()->messages()->create($threadId, ['role' => 'user','content' => 'Hello World!',]
);echo "Message created, id:" . $response->id . "<br/>";echo "Creating a run...<br/>";$response = $client->threads()->runs()->create(threadId: $threadId, parameters: ['assistant_id' => 'asst_wYzcGyBRwvpcKY3G4O0fEM5A',],
);echo "Run created, id:" . $response->id . "<br/>";
$runId = $response->id;echo "Waiting for run result...<br/>";for ($i=0; $i <= 20; $i++) {$response = $client->threads()->runs()->retrieve(threadId: $threadId,runId: $runId,);$runStatus = $response->status;if(strcmp($runStatus, "in_progress")==0){echo "In progres... <br/>";}if(strcmp($runStatus, "failed")==0){echo "Failed... <br/>";echo json_encode($response->toArray(), JSON_PRETTY_PRINT);echo "<br/>";break;}if(strcmp($runStatus, "completed") ==0){echo "In completed... <br/>";break;}sleep(1); 
}echo "Run complete<br/>";?>

The result:

php">Creating thread...
Thread created, id:thread_ZvHJYWZjoYXf04CR6BJbw67C
Adding message Hello World...
Message created, id:msg_Z1Y6Ei4j9b5EKI48BtSzHvot
Creating a run...
Run created, id:run_jR2oc8y3wLqWS8jwfcizK70I
Waiting for run result...
In progres...
Failed...
{"id": "run_jR2oc8y3wLqWS8jwfcizK70I","object": "thread.run","created_at": 1710458772,"assistant_id": "asst_wYzcGyBRwvpcKY3G4O0fEM5A","thread_id": "thread_ZvHJYWZjoYXf04CR6BJbw67C","status": "failed","started_at": 1710458772,"expires_at": null,"cancelled_at": null,"failed_at": 1710458773,"completed_at": null,"last_error": {"code": "server_error","message": "Sorry, something went wrong."},"model": "gpt-4-1106-preview","instructions": "You're helping debugging why the api calls to you are not working. Please share everything , all technical details you know about the interaction and the communication aspects. ","tools": [],"file_ids": [],"metadata": [],"usage": {"prompt_tokens": 0,"completion_tokens": 0,"total_tokens": 0}
}
Run complete

When I use the api to create the tread and message and use the platform.openai.com website the run completes fine. (I used an online json formatter to format it nicely as above.)

当我使用 API 创建对话和消息,并在 platform.openai.com 网站上运行时,它能够顺利完成。(我使用了在线 JSON 格式化工具,将其格式化得如上所示。)

The error message is: Sorry, something went wrong.

错误信息是:抱歉,出现了一些问题。

Thanks for any help!

问题解决:

The problem was with OpenAI and not with the code. I used an api key restricted to threads write access, thread write access and assistant read access and these did not work.

问题出在 OpenAI 而不是代码。我使用了一个仅限于对话写入访问、对话写入访问和助手读取访问的 API 密钥,但这些都不起作用。

I set the api key to full access and now it works.

我将 API 密钥设置为完全访问权限后,现在可以正常工作了。


http://www.ppmy.cn/server/121035.html

相关文章

【Python报错已解决】ModuleNotFoundError: No module named ‘paddle‘

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《C干货基地》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 专栏介绍 在软件开发和日常使用中&#xff0c;BUG是不可避免的。本专栏致力于为广大开发者和技术爱好者提供一个关于BUG解决的经…

Python中使用Redis布隆过滤器

Python中使用Redis布隆过滤器 在Python中使用Redis布隆过滤器,可以利用 redis-py 库和 redis-py-bloom 扩展。布隆过滤器是一种空间效率高的概率性数据结构,适合用于判断某个元素是否在集合中。 以下是如何在Python中设置和使用Redis布隆过滤器的步骤: 安装依赖 首先,确…

C++ 简介

目录 面向对象程序设计 标准库 ANSI 标准 学习 C C 的使用 标准化 C 是一种静态类型的、编译式的、通用的、大小写敏感的、不规则的编程语言&#xff0c;支持过程化编程、面向对象编程和泛型编程。 C 被认为是一种中级语言&#xff0c;它综合了高级语言和低级语言的特点…

WGAN算法

Wasserstein GAN (WGAN) 是一种改进的生成对抗网络&#xff08;GAN&#xff09;&#xff0c;由 Arjovsky 等人在 2017 年提出&#xff0c;用于解决原始 GAN 中的训练不稳定性和模式崩溃&#xff08;Mode Collapse&#xff09;问题。WGAN 的核心思想是使用Wasserstein 距离&…

深度学习:卷积神经网络CNN

目录 一、什么是卷积&#xff1f; 二、卷积神经网络的组成 1. 卷积层 2. 池化层 3. 激活函数 4. 全连接层 三、卷积神经网络的构造 四、代码实现 1.数据预处理 2.创建卷积神经网络 3.创建训练集和测试集函数 4.创建损失函数和优化器并进行训练 一、什么是卷积&…

【数字组合】

题目 思路 状态表示&#xff1a; f [ i ] [ j ] f[i][j] f[i][j] 对应考虑1到 i 号数字&#xff0c;和为 j 的方法&#xff0c;表示方法数 目标表示&#xff1a; f [ n ] [ m ] f[n][m] f[n][m] 状态转移&#xff1a; f [ i ] [ j ] f [ i − 1 ] [ j ] f [ i − 1 ] [ j …

OpenGL 着色器类的源码

编写、编译、管理着色器是件麻烦事。在着色器主题的最后&#xff0c;我们会写一个类来让我们的生活轻松一点&#xff0c;它可以从硬盘读取着色器&#xff0c;然后编译并链接它们&#xff0c;并对它们进行错误检测&#xff0c;这就变得很好用了。这也会让你了解该如何封装目前所…

Vue学习文档

文章目录 一、Vue 简介1、官网2、作者和版本3、定义4、特点5、Vue 的周边库二、Vue 安装使用1、CDN 引入2、下载后引入3、命令行工具 (CLI)三、入门案例四、MVVM模型1、MVVM 模型2、Vue 与 MVVM 模型五、Vue 基本使用1、文本插值(掌握)-text2、属性插值(掌握 )-bind3、Clas…