|
@@ -1,28 +1,32 @@
|
|
|
package com.sxtvs.chatgpt.api.chatgpt.controller;
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.apache.hc.client5.http.fluent.Request;
|
|
|
+import org.apache.hc.core5.http.ContentType;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
@RestController
|
|
|
public class ChatGptController {
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
@RequestMapping("hello")
|
|
|
public void hello() {
|
|
|
- var response = HttpUtil.createGet("https://api.openai.com/v1/completions")
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .header("Authorization", "Bearer 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")
|
|
|
- .body("""
|
|
|
+ var response = Request.post("https://api.openai.com/v1/completions")
|
|
|
+ .setHeader("Authorization", "Bearer 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")
|
|
|
+ .bodyString("""
|
|
|
{
|
|
|
"model": "text-davinci-003",
|
|
|
"prompt": "Say this is a test",
|
|
|
"max_tokens": 7,
|
|
|
"temperature": 0
|
|
|
}
|
|
|
- """)
|
|
|
- .execute();
|
|
|
- System.out.println(response.body());
|
|
|
- response.close();
|
|
|
+ """, ContentType.APPLICATION_JSON)
|
|
|
+ .execute()
|
|
|
+ .returnContent()
|
|
|
+ .toString();
|
|
|
+ System.out.println(response);
|
|
|
}
|
|
|
|
|
|
}
|