-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.lang3.StringEscapeUtils; | ||
import org.glassfish.jersey.media.multipart.FormDataParam; | ||
import org.java_websocket.util.Base64; | ||
|
||
import com.knuddels.jtokkit.Encodings; | ||
|
@@ -103,6 +104,7 @@ | |
title = "las2peer OpenAI Service", | ||
version = "1.0.0", | ||
description = "A las2peer wrapper service for the social-bot-manager service to make request to OpenAI API functions.", | ||
termsOfService = "https://tech4comp.de/", | ||
contact = @Contact( | ||
name = "Samuel Kwong", | ||
email = "[email protected]"), | ||
|
@@ -573,14 +575,14 @@ public Response chat(String body) { | |
@ApiOperation( | ||
value = "Get the chat response from biwibot", | ||
notes = "Returns the chat response from biwibot") | ||
public Response biwibot(String body) { | ||
System.out.println(body); | ||
public Response biwibot(String body, @FormDataParam("channel") String channel) { | ||
System.out.println("Input:" + body); | ||
System.out.println("Channel": + channel); | ||
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE); | ||
JSONObject json = null; | ||
JSONObject chatResponse = new JSONObject(); | ||
JSONObject newEvent = new JSONObject(); | ||
String question = null; | ||
String channel = null; | ||
|
||
try { | ||
json = (JSONObject) p.parse(body); | ||
|
@@ -606,19 +608,20 @@ public Response biwibot(String body) { | |
|
||
if (responseCode == HttpURLConnection.HTTP_OK) { | ||
System.out.print("Response from service: " + response.body()); | ||
|
||
// Update chatResponse with the result from the POST request | ||
chatResponse.put("text", response.body()); | ||
chatResponse.put("AIResponse", response.body()); | ||
} else if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) { | ||
// Handle unsuccessful response | ||
chatResponse.appendField("text", "An error has occurred."); | ||
chatResponse.appendField("AIResponse", "An error has occurred."); | ||
} | ||
|
||
System.out.println(chatResponse); | ||
} catch (ParseException | IOException | InterruptedException e) { | ||
e.printStackTrace(); | ||
chatResponse.appendField("text", "An error has occurred."); | ||
chatResponse.appendField("AIResponse", "An error has occurred."); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
chatResponse.appendField("text", "An unknown error has occurred."); | ||
chatResponse.appendField("AIResponse", "An unknown error has occurred."); | ||
} | ||
|
||
return Response.ok().entity(chatResponse).build(); | ||
|