feat(captain): align playground fallback
This commit is contained in:
@@ -301,8 +301,13 @@ func (h *CaptainAssistantHandler) Tools(c *gin.Context) {
|
||||
}
|
||||
|
||||
// GenerateResponse generates an AI response via RAG.
|
||||
// POST /api/v1/accounts/:account_id/captain_assistants/:id/generate_response
|
||||
// POST /api/v1/accounts/:account_id/captain/assistants/:assistant_id/playground
|
||||
func (h *CaptainAssistantHandler) GenerateResponse(c *gin.Context) {
|
||||
accountID := parseAccountIDParam(c)
|
||||
if accountID == 0 {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account_id")
|
||||
return
|
||||
}
|
||||
id, err := parseUintAnyParam(c, "assistant_id", "id")
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
|
||||
@@ -311,39 +316,52 @@ func (h *CaptainAssistantHandler) GenerateResponse(c *gin.Context) {
|
||||
|
||||
var req struct {
|
||||
Assistant struct {
|
||||
MessageContent string `json:"message_content"`
|
||||
Query string `json:"query"`
|
||||
MessageContent string `json:"message_content"`
|
||||
Query string `json:"query"`
|
||||
MessageHistory []service.PlaygroundMessage `json:"message_history"`
|
||||
} `json:"assistant"`
|
||||
MessageContent string `json:"message_content"`
|
||||
Query string `json:"query"`
|
||||
MessageContent string `json:"message_content"`
|
||||
Query string `json:"query"`
|
||||
MessageHistory []service.PlaygroundMessage `json:"message_history"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
return
|
||||
}
|
||||
query := req.Query
|
||||
if query == "" {
|
||||
query = req.MessageContent
|
||||
messageContent := req.MessageContent
|
||||
if messageContent == "" {
|
||||
messageContent = req.Query
|
||||
}
|
||||
if query == "" {
|
||||
query = req.Assistant.Query
|
||||
if messageContent == "" {
|
||||
messageContent = req.Assistant.MessageContent
|
||||
}
|
||||
if query == "" {
|
||||
query = req.Assistant.MessageContent
|
||||
if messageContent == "" {
|
||||
messageContent = req.Assistant.Query
|
||||
}
|
||||
if query == "" {
|
||||
if messageContent == "" {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, "message_content is required")
|
||||
return
|
||||
}
|
||||
messageHistory := req.MessageHistory
|
||||
if len(messageHistory) == 0 && len(req.Assistant.MessageHistory) > 0 {
|
||||
messageHistory = req.Assistant.MessageHistory
|
||||
}
|
||||
|
||||
result, err := h.svc.GenerateResponse(c.Request.Context(), id, query)
|
||||
result, err := h.svc.GeneratePlaygroundResponse(c.Request.Context(), accountID, id, service.PlaygroundRequest{
|
||||
MessageContent: messageContent,
|
||||
MessageHistory: messageHistory,
|
||||
})
|
||||
if err != nil {
|
||||
applogger.L().Errorf("GenerateResponse: %v", err)
|
||||
if captainAssistantErrorStatus(err) == http.StatusNotFound {
|
||||
response.AbortWithStatusError(c, http.StatusNotFound, response.ErrNotFound, "assistant not found")
|
||||
return
|
||||
}
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to generate response")
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"response": result})
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func bindCaptainAssistantPayload(c *gin.Context, dst any) error {
|
||||
|
||||
Reference in New Issue
Block a user