MCPcopy Index your code
hub / github.com/apache/answer / saveConversationRecord

Method saveConversationRecord

internal/controller/ai_controller.go:407–430  ·  view source on GitHub ↗

saveConversationRecord

(ctx context.Context, chatcmplID string, conversationCtx *ConversationContext)

Source from the content-addressed store, hash-verified

405
406// saveConversationRecord
407func (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
432func (c *AIController) handleAIConversation(ctx *gin.Context, w http.ResponseWriter, id string, client *openai.Client, conversationCtx *ConversationContext) {
433 maxRounds := 10

Callers 1

ChatCompletionsMethod · 0.95

Calls 2

CreateConversationMethod · 0.65

Tested by

no test coverage detected