iachat/enterprise/app/services/captain/copilot/chat_service.rb
Shivam Mishra 451c28a7a1
feat: add prompt suggestions and June events (#10726)
This PR adds the following two features

1. Prompt suggestions to get started with Copilot Chat
2. June events for each action

![CleanShot 2025-01-20 at 21 00
52@2x](https://github.com/user-attachments/assets/d73e7982-0f78-4d85-873e-da2c16762688)

---------

Co-authored-by: Pranav <pranavrajs@gmail.com>
2025-01-21 22:52:42 +05:30

40 lines
921 B
Ruby

require 'openai'
class Captain::Copilot::ChatService < Captain::Llm::BaseOpenAiService
include Captain::ChatHelper
def initialize(assistant, config)
super()
@assistant = assistant
@conversation_history = config[:conversation_history]
@previous_messages = config[:previous_messages] || []
@messages = [system_message, conversation_history_context] + @previous_messages
@response = ''
end
def generate_response(input)
@messages << { role: 'user', content: input } if input.present?
request_chat_completion
end
private
def system_message
{
role: 'system',
content: Captain::Llm::SystemPromptsService.copilot_response_generator(@assistant.config['product_name'])
}
end
def conversation_history_context
{
role: 'system',
content: "
Message History with the user is below:
#{@conversation_history}
"
}
end
end