Код: Выделить всё
String url = "https://api.openai.com/v1/completions";
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer sk-omitted");
String jsonMsg="{\"max_tokens\":4000,\"temperature\":1,\"model\":\"gpt-3.5-turbo\",\"prompt\":\"hello world\"}";
System.out.println('"' + jsonMsg + '"');
con.setDoOutput(true);
con.getOutputStream().write(jsonMsg.getBytes());
String output = "";
try {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
output = br.lines().reduce((a, b) -> a + b).get();
br.close();
} catch (Exception ex) {
System.out.println(ex.toString());
return output;
}
p>
Я попытался отправить запрос в OpenAI, и он сообщил мне, что файл не найден, несмотря на то, что это ссылка, к которой ранее успешно обращались много раз и заранее в коде.
Подробнее здесь: https://stackoverflow.com/questions/785 ... geting-url
Мобильная версия