I have been trying to call openapi but i am getting hit with this error,I'm not sure what is wrong with my payload.
I have tried to rewrite my code but I'm still not sure why this occurs
Error: HTTP/1.1 415 Unsupported Media Type
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class GPT3API : MonoBehaviour
{
private string openaiApiKey = "MYKEY;
private string model = "text-davinci-002";
public string prompt = "Hello";
public int maxTokens = 100;
public void Start()
{
}
public void callGPT3()
{
StartCoroutine(GetGPT3Response());
}
private IEnumerator GetGPT3Response()
{
string url = "https://api.openai.com/v1/engines/" + model + "/completions";
// Create a JSON payload with the desired API parameters
string payload = "{\"prompt\":\"" + prompt + "\", \"max_tokens\": " + maxTokens + "}";
using (UnityWebRequest www = UnityWebRequest.Post(url, payload))
{
// Set the API authorization header using your API key
www.SetRequestHeader("Authorization", "Bearer " + openaiApiKey);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log("Error: " + www.error);
}
else
{
string response = www.downloadHandler.text;
Debug.Log("Response: " + response);
}
}
}
}