|
| 1 | +diff --git a/src/main/java/org/wise/portal/presentation/web/controllers/ChatGptcontroller.java b/src/main/java/org/wise/portal/presentation/web/controllers/ChatGptcontroller.java |
| 2 | +index 9cfbd86..9cbc0bc 100644 |
| 3 | +--- a/src/main/java/org/wise/portal/presentation/web/controllers/ChatGptcontroller.java |
| 4 | ++++ b/src/main/java/org/wise/portal/presentation/web/controllers/ChatGptcontroller.java |
| 5 | +@@ -6,7 +6,10 @@ import java.io.InputStreamReader; |
| 6 | + import java.io.OutputStreamWriter; |
| 7 | + import java.net.HttpURLConnection; |
| 8 | + import java.net.URL; |
| 9 | +- |
| 10 | ++import org.json.JSONObject; |
| 11 | ++import org.json.JSONException; |
| 12 | ++import org.json.JSONArray; |
| 13 | ++import org.wise.portal.dao.ObjectNotFoundException; |
| 14 | + import org.springframework.beans.factory.annotation.Autowired; |
| 15 | + import org.springframework.core.env.Environment; |
| 16 | + import org.springframework.security.access.annotation.Secured; |
| 17 | +@@ -32,17 +35,19 @@ public class ChatGptcontroller { |
| 18 | + throw new RuntimeException("OPENAI_API_KEY is not set"); |
| 19 | + } |
| 20 | + try { |
| 21 | ++ System.out.println("sendChatMessage from wise api server"); |
| 22 | + URL url = new URL("https://api.openai.com/v1/chat/completions"); |
| 23 | + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| 24 | + connection.setRequestMethod("POST"); |
| 25 | + connection.setRequestProperty("Authorization", "Bearer " + openaiApiKey); |
| 26 | +- connection.setRequestProperty("Content-Type", "application/json"); |
| 27 | ++ connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); |
| 28 | ++ connection.setRequestProperty("Accept-Charset", "UTF-8"); |
| 29 | + connection.setDoOutput(true); |
| 30 | + OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); |
| 31 | + writer.write(body); |
| 32 | + writer.flush(); |
| 33 | + writer.close(); |
| 34 | +- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
| 35 | ++ BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(),"ISO-8859-1")); |
| 36 | + String line; |
| 37 | + StringBuffer response = new StringBuffer(); |
| 38 | + while ((line = br.readLine()) != null) { |
0 commit comments