# Pull Request Template ## Linear links: - https://linear.app/chatwoot/issue/CW-4479/if-image-is-sent-by-the-customer-send-it-to-openai ## Description This pull request adds “Captain image support” to Chatwoot. It introduces multimodal message handling so that when a customer sends an image, Captain can forward the file to OpenAI’s vision endpoint, generate a caption/analysis ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? <img width="891" alt="image" src="https://github.com/user-attachments/assets/c7cc98ed-cc44-4865-a53a-83d129e2fe2c" /> ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Pranav <pranav@chatwoot.com>
62 lines
1.7 KiB
Ruby
62 lines
1.7 KiB
Ruby
class Api::V1::Accounts::Captain::AssistantsController < Api::V1::Accounts::BaseController
|
|
before_action :current_account
|
|
before_action -> { check_authorization(Captain::Assistant) }
|
|
|
|
before_action :set_assistant, only: [:show, :update, :destroy, :playground]
|
|
|
|
def index
|
|
@assistants = account_assistants.ordered
|
|
end
|
|
|
|
def show; end
|
|
|
|
def create
|
|
@assistant = account_assistants.create!(assistant_params)
|
|
end
|
|
|
|
def update
|
|
@assistant.update!(assistant_params)
|
|
end
|
|
|
|
def destroy
|
|
@assistant.destroy
|
|
head :no_content
|
|
end
|
|
|
|
def playground
|
|
response = Captain::Llm::AssistantChatService.new(assistant: @assistant).generate_response(
|
|
additional_message: params[:message_content],
|
|
message_history: message_history
|
|
)
|
|
|
|
render json: response
|
|
end
|
|
|
|
private
|
|
|
|
def set_assistant
|
|
@assistant = account_assistants.find(params[:id])
|
|
end
|
|
|
|
def account_assistants
|
|
@account_assistants ||= Captain::Assistant.for_account(Current.account.id)
|
|
end
|
|
|
|
def assistant_params
|
|
params.require(:assistant).permit(:name, :description,
|
|
config: [
|
|
:product_name, :feature_faq, :feature_memory,
|
|
:welcome_message, :handoff_message, :resolution_message,
|
|
:instructions, :temperature
|
|
])
|
|
end
|
|
|
|
def playground_params
|
|
params.require(:assistant).permit(:message_content, message_history: [:role, :content])
|
|
end
|
|
|
|
def message_history
|
|
(playground_params[:message_history] || []).map { |message| { role: message[:role], content: message[:content] } }
|
|
end
|
|
end
|