gpt4 book ai didi

unity3d - OpenAI Unity - POST 请求无法正常工作(400 状态)

转载 作者:行者123 更新时间:2023-12-02 05:46:07 24 4
gpt4 key购买 nike

我正在连接 GPT3 OpenAI但我无法设法向它发出正确的 POST 请求(我正在遵循一些指南,但对他们来说它有效......)。

private IEnumerator Upload ( )
{
WWWForm form = new WWWForm();
form.AddField ( "prompt", prompt );
form.AddField ( "max_tokens", maxTokens );
form.AddField ( "model", model );
form.AddField ( "temperature", temperature );

using ( UnityWebRequest wR = UnityWebRequest.Post ( "https://api.openai.com/v1/completions", form ) )
{
wR.SetRequestHeader ( "Authorization", "Bearer " + apiKey );
wR.SetRequestHeader ( "Content-Type", "json" );
yield return wR.SendWebRequest ( );
if ( wR.result != UnityWebRequest.Result.Success )
{
Debug.Log ( "ERROR:\n" + wR.error );
}
else
{
Debug.Log ( "Success:\n" + wR.result + "\nUpload Completed!);
}
}
}

我的代码总是返回一个错误的请求(又名 400 Bad Request)。

最佳答案

从标题中删除“Content-Type”。内容不是 JSON,而是表单数据。

using ( UnityWebRequest wR = UnityWebRequest.Post ( "https://api.openai.com/v1/completions", form ) )
{
wR.SetRequestHeader ( "Authorization", "Bearer " + apiKey );
//wR.SetRequestHeader ( "Content-Type", "json" );
yield return wR.SendWebRequest ( );
if ( wR.result != UnityWebRequest.Result.Success )
{
Debug.Log ( "ERROR:\n" + wR.error );
}
else
{
Debug.Log ( "Success:\n" + wR.result + "\nUpload Completed!);
}
}

关于unity3d - OpenAI Unity - POST 请求无法正常工作(400 状态),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75091786/

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