Skip to content

Commit 2cb07de

Browse files
authored
fix(ChatGptController): Chinese encoding issue (#310)
Fixes an encoding issue in the AI component where Chinese responses returned from the OpenAI API were displayed as "??????????" in the WISE dialog.
1 parent 0d8efca commit 2cb07de

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/org/wise/portal/presentation/web/controllers/ChatGptcontroller.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.io.OutputStreamWriter;
77
import java.net.HttpURLConnection;
88
import java.net.URL;
9-
109
import org.springframework.beans.factory.annotation.Autowired;
1110
import org.springframework.core.env.Environment;
1211
import org.springframework.security.access.annotation.Secured;
@@ -36,13 +35,14 @@ protected String sendChatMessage(@RequestBody String body) {
3635
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
3736
connection.setRequestMethod("POST");
3837
connection.setRequestProperty("Authorization", "Bearer " + openaiApiKey);
39-
connection.setRequestProperty("Content-Type", "application/json");
38+
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
39+
connection.setRequestProperty("Accept-Charset", "UTF-8");
4040
connection.setDoOutput(true);
4141
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
4242
writer.write(body);
4343
writer.flush();
4444
writer.close();
45-
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
45+
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(),"ISO-8859-1"));
4646
String line;
4747
StringBuffer response = new StringBuffer();
4848
while ((line = br.readLine()) != null) {

0 commit comments

Comments
 (0)