Package org.codelibs.fess.api.chat
Class ChatApiManager
java.lang.Object
org.codelibs.fess.api.BaseApiManager
org.codelibs.fess.api.chat.ChatApiManager
- All Implemented Interfaces:
WebApiManager
API Manager for RAG chat endpoints with SSE streaming support.
- Author:
- FessProject
-
Nested Class Summary
Nested classes/interfaces inherited from class org.codelibs.fess.api.BaseApiManager
BaseApiManager.FormatType -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateErrorResponse(String message) Creates an error response map.createSuccessResponse(String sessionId, String content, List<ChatMessage.ChatSource> sources) Creates a success response map.protected intgetMaxMessageLength(org.codelibs.fess.mylasta.direction.FessConfig fessConfig) Returns the maximum message length for chat messages.protected StringgetUserId(jakarta.servlet.http.HttpServletRequest request) Gets the user ID from the request.booleanmatches(jakarta.servlet.http.HttpServletRequest request) Checks if the request matches this API manager.protected String[]parseExtraQueries(jakarta.servlet.http.HttpServletRequest request) Parses and validates extra query parameters from the request.parseFieldFilters(jakarta.servlet.http.HttpServletRequest request) Parses and validates field filter parameters from the request.voidprocess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) Processes the request through this API manager.protected voidprocessChatRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Processes a non-streaming chat request.protected voidprocessStreamRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Processes a streaming chat request using Server-Sent Events (SSE).voidregister()Registers this API manager with the WebApiManagerFactory.protected voidsendSseEvent(PrintWriter writer, String event, Map<String, Object> data) Sends a Server-Sent Event (SSE) to the client.protected voidwriteHeaders(jakarta.servlet.http.HttpServletResponse response) Writes custom headers to the HTTP response.protected voidwriteJsonResponse(jakarta.servlet.http.HttpServletResponse response, int status, Map<String, Object> data) Writes a JSON response to the HTTP response.Methods inherited from class org.codelibs.fess.api.BaseApiManager
detectFormatType, getFormatType, getPathPrefix, setPathPrefix, write
-
Field Details
-
pathPrefix
The path prefix for the chat API endpoints.
-
-
Constructor Details
-
ChatApiManager
public ChatApiManager()Default constructor.
-
-
Method Details
-
register
@PostConstruct public void register()Registers this API manager with the WebApiManagerFactory. -
matches
public boolean matches(jakarta.servlet.http.HttpServletRequest request) Description copied from interface:WebApiManagerChecks if the request matches this API manager.- Parameters:
request- The HTTP servlet request.- Returns:
- True if the request matches, false otherwise.
-
process
public void process(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException Description copied from interface:WebApiManagerProcesses the request through this API manager.- Parameters:
request- The HTTP servlet request.response- The HTTP servlet response.chain- The filter chain.- Throws:
IOException- If an input/output error occurs.jakarta.servlet.ServletException- If a servlet error occurs.
-
processChatRequest
protected void processChatRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Processes a non-streaming chat request.- Parameters:
request- the HTTP requestresponse- the HTTP response- Throws:
IOException- if an I/O error occurs
-
processStreamRequest
protected void processStreamRequest(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException Processes a streaming chat request using Server-Sent Events (SSE). Uses the enhanced multi-phase RAG flow with intent detection and result evaluation.- Parameters:
request- the HTTP requestresponse- the HTTP response- Throws:
IOException- if an I/O error occurs
-
sendSseEvent
Sends a Server-Sent Event (SSE) to the client.- Parameters:
writer- the print writer to write the event toevent- the event namedata- the event data to serialize as JSON
-
writeJsonResponse
protected void writeJsonResponse(jakarta.servlet.http.HttpServletResponse response, int status, Map<String, Object> data) throws IOExceptionWrites a JSON response to the HTTP response.- Parameters:
response- the HTTP responsestatus- the HTTP status codedata- the data to serialize as JSON- Throws:
IOException- if an I/O error occurs
-
createSuccessResponse
protected Map<String,Object> createSuccessResponse(String sessionId, String content, List<ChatMessage.ChatSource> sources) Creates a success response map.- Parameters:
sessionId- the session IDcontent- the response contentsources- the list of chat sources- Returns:
- a map containing the success response data
-
createErrorResponse
Creates an error response map.- Parameters:
message- the error message- Returns:
- a map containing the error response data
-
getUserId
Gets the user ID from the request.- Parameters:
request- the HTTP request- Returns:
- the user ID, or null if the user is a guest
-
getMaxMessageLength
protected int getMaxMessageLength(org.codelibs.fess.mylasta.direction.FessConfig fessConfig) Returns the maximum message length for chat messages.- Parameters:
fessConfig- the Fess configuration- Returns:
- the maximum message length
-
parseFieldFilters
Parses and validates field filter parameters from the request. Only configured label values are accepted to prevent query injection.- Parameters:
request- the HTTP request- Returns:
- a map of field names to their validated filter values
-
parseExtraQueries
Parses and validates extra query parameters from the request. Only configured facet query values are accepted to prevent query injection.- Parameters:
request- the HTTP request- Returns:
- an array of validated extra query strings
-
writeHeaders
protected void writeHeaders(jakarta.servlet.http.HttpServletResponse response) Description copied from class:BaseApiManagerWrites custom headers to the HTTP response.- Specified by:
writeHeadersin classBaseApiManager- Parameters:
response- The HTTP servlet response.
-