saveConversationRecord
(ctx context.Context, chatcmplID string, conversationCtx *ConversationContext)
| 405 | |
| 406 | // saveConversationRecord |
| 407 | func (c *AIController) saveConversationRecord(ctx context.Context, chatcmplID string, conversationCtx *ConversationContext) { |
| 408 | if conversationCtx == nil || len(conversationCtx.Messages) == 0 { |
| 409 | return |
| 410 | } |
| 411 | |
| 412 | if conversationCtx.IsNewConversation { |
| 413 | topic := conversationCtx.UserQuestion |
| 414 | if topic == "" { |
| 415 | log.Warn("No user message found for new conversation") |
| 416 | return |
| 417 | } |
| 418 | |
| 419 | err := c.aiConversationService.CreateConversation(ctx, conversationCtx.UserID, conversationCtx.ConversationID, topic) |
| 420 | if err != nil { |
| 421 | log.Errorf("Failed to create conversation: %v", err) |
| 422 | return |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | err := c.aiConversationService.SaveConversationRecords(ctx, conversationCtx.ConversationID, chatcmplID, conversationCtx.Messages) |
| 427 | if err != nil { |
| 428 | log.Errorf("Failed to save conversation records: %v", err) |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | func (c *AIController) handleAIConversation(ctx *gin.Context, w http.ResponseWriter, id string, client *openai.Client, conversationCtx *ConversationContext) { |
| 433 | maxRounds := 10 |
no test coverage detected