Class OpenaiServlet

java.lang.Object
com.qubitpi.chatbotws.web.endpoints.OpenaiServlet

@Singleton @Immutable @ThreadSafe @Path("/openai") @Produces("application/json") public class OpenaiServlet extends Object
Endpoint that delegates chatbot to OpenAI API.
  • Constructor Details

    • OpenaiServlet

      @Inject public OpenaiServlet()
      Constructor for dependency injection.
  • Method Details

    • chat

      @POST @Path("/chat") @Consumes("application/json") @Produces("application/json") public jakarta.ws.rs.core.Response chat(@NotNull @NotNull Map<String,String> payload) throws IOException, InterruptedException
      Chatbot endpoint.
      Parameters:
      payload - A JSON object containing a message field which contains the message sent to ask the bot.
      Returns:
      200 OK response with the chatbot's response message
      Throws:
      IOException - if an I/ O error occurs when sending or receiving from the OpenAI
      InterruptedException - if the OpenAI request is interrupted