# Pull Request Template ## Description Playground now uses v2. It was only wired to use v1. Traces get `source: playground` on langfuse when playground has been used. ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. locally and specs <img width="1806" height="1276" alt="image" src="https://github.com/user-attachments/assets/41ef4eb3-52b1-4b8e-9a4f-e8510c90cb39" /> ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
class Captain::Llm::AssistantChatService < Llm::BaseAiService
|
|
include Captain::ChatHelper
|
|
|
|
def initialize(assistant: nil, conversation_id: nil, source: nil)
|
|
super()
|
|
|
|
@assistant = assistant
|
|
@conversation_id = conversation_id
|
|
@source = source
|
|
|
|
@messages = [system_message]
|
|
@response = ''
|
|
@tools = build_tools
|
|
end
|
|
|
|
# additional_message: A single message (String) from the user that should be appended to the chat.
|
|
# It can be an empty String or nil when you only want to supply historical messages.
|
|
# message_history: An Array of already formatted messages that provide the previous context.
|
|
# role: The role for the additional_message (defaults to `user`).
|
|
#
|
|
# NOTE: Parameters are provided as keyword arguments to improve clarity and avoid relying on
|
|
# positional ordering.
|
|
def generate_response(additional_message: nil, message_history: [], role: 'user')
|
|
@messages += message_history
|
|
@messages << { role: role, content: additional_message } if additional_message.present?
|
|
request_chat_completion
|
|
end
|
|
|
|
private
|
|
|
|
def build_tools
|
|
[Captain::Tools::SearchDocumentationService.new(@assistant, user: nil)]
|
|
end
|
|
|
|
def system_message
|
|
{
|
|
role: 'system',
|
|
content: Captain::Llm::SystemPromptsService.assistant_response_generator(@assistant.name, @assistant.config['product_name'], @assistant.config)
|
|
}
|
|
end
|
|
|
|
def persist_message(message, message_type = 'assistant')
|
|
# No need to implement
|
|
end
|
|
|
|
def feature_name
|
|
'assistant'
|
|
end
|
|
end
|