Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dashboard/app/controllers/aidiff_threads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def chat_completion
# Add user message to thread
begin
log_messages(response_body)
if response_body[:is_artifact_candidate]
response_body[:chat_message_text] = AidiffArtifact.to_markdown(
response_body[:chat_message_text],
response_body[:artifact_type]
)
end
response_body[:message_id] = @assistant_message.id
response_body[:thread_id] = @aidiff_thread.id
if session_id.nil?
Expand All @@ -127,7 +133,7 @@ def chat_completion
end
end

return_body = response_body.slice(:role, :status, :chat_message_text, :message_id, :thread_id)
return_body = response_body.slice(:role, :status, :chat_message_text, :message_id, :thread_id, :is_artifact_candidate, :artifact_type)

render(json: return_body)
end
Expand Down
9 changes: 9 additions & 0 deletions dashboard/app/models/aidiff_artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class AidiffArtifact < ApplicationRecord

accepts_nested_attributes_for :aidiff_artifact_associations, allow_destroy: true

def self.to_markdown(text, type)
# Put spaces at the end of the line for Markdown newlines
new_text = text.gsub('\n', ' \n')

Kernel.const_get(type).to_markdown(JSON::Validator.parse(new_text))
rescue
text
end

def summarize
{
id: id,
Expand Down
7 changes: 7 additions & 0 deletions dashboard/app/models/aidiff_exit_ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
# index_aidiff_artifacts_on_user_id (user_id)
#
class AidiffExitTicket < AidiffArtifact
def self.to_markdown(json)
json['comment'] + "\n\n***\n\n" +
json['exit_ticket_items'].map.with_index do |item, i|
"**Question #{i+1}:** #{item['question']}\n\n**Answer:** #{item['answer']}\n"
end.join("\n\n***\n\n")
end

def summarize
super.merge(
url: "/aidiff_exit_tickets/#{id}"
Expand Down
7 changes: 7 additions & 0 deletions dashboard/app/models/aidiff_lesson_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
# index_aidiff_artifacts_on_user_id (user_id)
#
class AidiffLessonHook < AidiffArtifact
def self.to_markdown(json)
"#{json['comment']}\n\n***\n\n" \
"**Introduction:** #{json['lesson_hook']['introduction']} \n***\n" \
"**Activity:** \n#{json['lesson_hook']['activity']} \n***\n" \
"**Wrap Up:** #{json['lesson_hook']['wrap_up']}"
end

def summarize
super.merge(
url: "/aidiff_lesson_hooks/#{id}"
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/models/aidiff_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def summarize
{
id: id,
role: role,
content: content,
content: AidiffArtifact.to_markdown(content, artifact_candidate_type),
updated_at: updated_at,
is_preset: is_preset,
preset_chip_text: preset_chip_text,
Expand Down