| 85 | } |
| 86 | |
| 87 | func (s *ChatServiceV2) GetPrompt(ctx context.Context, content string, selectedText string, surrounding string, conversationType chatv2.ConversationType) (string, error) { |
| 88 | var tmpl *template.Template |
| 89 | switch conversationType { |
| 90 | case chatv2.ConversationType_CONVERSATION_TYPE_DEBUG: |
| 91 | tmpl = userPromptDebugTmplV2 |
| 92 | default: |
| 93 | tmpl = userPromptDefaultTmplV2 |
| 94 | } |
| 95 | |
| 96 | var userPromptBuffer bytes.Buffer |
| 97 | if err := tmpl.Execute(&userPromptBuffer, map[string]string{ |
| 98 | "UserInput": content, |
| 99 | "SelectedText": selectedText, |
| 100 | "Surrounding": surrounding, |
| 101 | }); err != nil { |
| 102 | return "", err |
| 103 | } |
| 104 | return strings.TrimSpace(userPromptBuffer.String()), nil |
| 105 | } |
| 106 | |
| 107 | func (s *ChatServiceV2) InsertConversationToDBV2(ctx context.Context, userID bson.ObjectID, projectID string, modelSlug string, inappChatHistory []*chatv2.Message, openaiChatHistory []openai.ChatCompletionMessageParamUnion) (*models.Conversation, error) { |
| 108 | // Convert protobuf messages to BSON |