zyx 2 éve
szülő
commit
9f72834290
1 módosított fájl, 22 hozzáadás és 0 törlés
  1. 22 0
      src/main/java/com/sxtvs/NetTest.java

+ 22 - 0
src/main/java/com/sxtvs/NetTest.java

@@ -0,0 +1,22 @@
+package com.sxtvs;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sxtvs.api.chatgpt.dto.CompletionsParamsDto;
+import lombok.SneakyThrows;
+import org.apache.hc.client5.http.fluent.Request;
+import org.apache.hc.core5.http.ContentType;
+
+public class NetTest {
+    @SneakyThrows
+    public static void main(String[] args) {
+        var objectMapper = new ObjectMapper();
+        var paramsDto = new CompletionsParamsDto("今天天气怎么样");
+        var response = Request.post("https://api.openai.com/v1/completions")
+                .setHeader("Authorization", "Bearer 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")
+                .bodyString(objectMapper.writeValueAsString(paramsDto), ContentType.APPLICATION_JSON)
+                .execute()
+                .returnContent()
+                .toString();
+        System.out.println(response);
+    }
+}