gpt4 book ai didi

php - PHP : {'error' : "Missing ' inputs' or 'instances' key"} 中的休息 API

转载 作者:行者123 更新时间:2023-12-04 18:39:32 25 4
gpt4 key购买 nike

对于 中的此功能UBUNTU 终端 这适用于我的 dockerized 容器(使用 Tensorflow Serving 制作):

curl -d '{"instances": [[ 1.18730158, -0.70909592,  1.21082918, -0.15897608, -0.87693017],
[-0.3015204 , -0.44457891, 0.67090776, 1.1188499 , -0.87693017],
[-0.52579254, -0.05989349, 0.40094705, 1.62998029, 1.13982729],
[ 0.13322252, 0.58198159, -0.94885648, 1.1188499 , -0.87693017],
[ 0.77441082, -0.68638116, -0.13897436, 0.35215431, 1.13982729],
[ 0.69102759, 1.49057189, -0.13897436, -0.67010647, 1.13982729],
[-0.25436574, -0.58819479, 0.13098635, -0.15897608, 1.13982729],
[ 1.54671206, 2.58088026, 2.0207113 , -1.56458465, 1.13982729],
[-0.97261165, -0.6292279 , 0.40094705, -1.56458465, -0.87693017],
[-0.36190136, 0.14893573, 0.40094705, 0.09658912, 1.13982729]]}' -X POST http://localhost:8501/v1/models/model:predict
我在 中创建了一个 curl 函数PHP :
    <?php 
$endpoint = "http://localhost:8501/v1/models/model:predict";
$inputData = array(
"instances" =>
[[ 1.18730158, -0.70909592, 1.21082918, -0.15897608, -0.87693017],
[-0.3015204 , -0.44457891, 0.67090776, 1.1188499 , -0.87693017],
[-0.52579254, -0.05989349, 0.40094705, 1.62998029, 1.13982729],
[ 0.13322252, 0.58198159, -0.94885648, 1.1188499 , -0.87693017],
[ 0.77441082, -0.68638116, -0.13897436, 0.35215431, 1.13982729],
[ 0.69102759, 1.49057189, -0.13897436, -0.67010647, 1.13982729],
[-0.25436574, -0.58819479, 0.13098635, -0.15897608, 1.13982729],
[ 1.54671206, 2.58088026, 2.0207113 , -1.56458465, 1.13982729],
[-0.97261165, -0.6292279 , 0.40094705, -1.56458465, -0.87693017],
[-0.36190136, 0.14893573, 0.40094705, 0.09658912, 1.13982729]]
)

$jsonData = array(
"data" => $inputData,
);
$ch =

curl_init($endpoint);
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),


CURLOPT_POSTFIELDS => json_encode($jsonData)
));

$response = curl_exec($ch);
?>
但我不断收到错误:
{'error': "Missing 'inputs' or 'instances' key"}
我确定我不会给 输入正确但我不知道在哪里进行更改。任何帮助将不胜感激。

最佳答案

我认为你通过了额外的"data" => $inputData您的 $jsonData 中的 key .不使用 试试这种方式数据 ,

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8501/v1/models/model:predict');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"instances\": [[ 1.18730158, -0.70909592, 1.21082918, -0.15897608, -0.87693017],\n [-0.3015204 , -0.44457891, 0.67090776, 1.1188499 , -0.87693017],\n [-0.52579254, -0.05989349, 0.40094705, 1.62998029, 1.13982729],\n [ 0.13322252, 0.58198159, -0.94885648, 1.1188499 , -0.87693017],\n [ 0.77441082, -0.68638116, -0.13897436, 0.35215431, 1.13982729],\n [ 0.69102759, 1.49057189, -0.13897436, -0.67010647, 1.13982729],\n [-0.25436574, -0.58819479, 0.13098635, -0.15897608, 1.13982729],\n [ 1.54671206, 2.58088026, 2.0207113 , -1.56458465, 1.13982729],\n [-0.97261165, -0.6292279 , 0.40094705, -1.56458465, -0.87693017],\n [-0.36190136, 0.14893573, 0.40094705, 0.09658912, 1.13982729]]}");

$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
编辑 : 可以直接传 $inputData像下面
在哪里
$inputData = [
"instances" => [
[1.18730158, -0.70909592, 1.21082918, -0.15897608, -0.87693017],
[-0.3015204 , -0.44457891, 0.67090776, 1.1188499 , -0.87693017],
[-0.52579254, -0.05989349, 0.40094705, 1.62998029, 1.13982729],
[ 0.13322252, 0.58198159, -0.94885648, 1.1188499 , -0.87693017],
[ 0.77441082, -0.68638116, -0.13897436, 0.35215431, 1.13982729],
[ 0.69102759, 1.49057189, -0.13897436, -0.67010647, 1.13982729],
[-0.25436574, -0.58819479, 0.13098635, -0.15897608, 1.13982729],
[ 1.54671206, 2.58088026, 2.0207113 , -1.56458465, 1.13982729],
[-0.97261165, -0.6292279 , 0.40094705, -1.56458465, -0.87693017],
[-0.36190136, 0.14893573, 0.40094705, 0.09658912, 1.13982729]
]
];
然后 CURLOPT_POSTFIELDS => json_encode($inputData)

关于php - PHP : {'error' : "Missing ' inputs' or 'instances' key"} 中的休息 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62532704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com