mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-10 07:55:21 +02:00
Clean up "thinking" UI interactions
This commit is contained in:
parent
6068f04a48
commit
38ee33e9f7
3 changed files with 18 additions and 14 deletions
|
@ -30,24 +30,33 @@ class Assistant
|
|||
llm: get_model_provider(message.ai_model)
|
||||
)
|
||||
|
||||
latest_response_id = chat.latest_assistant_response_id
|
||||
|
||||
responder.on(:output_text) do |text|
|
||||
stop_thinking
|
||||
assistant_message.append_text!(text)
|
||||
if assistant_message.content.blank?
|
||||
stop_thinking
|
||||
|
||||
Chat.transaction do
|
||||
assistant_message.append_text!(text)
|
||||
chat.update_latest_response!(latest_response_id)
|
||||
end
|
||||
else
|
||||
assistant_message.append_text!(text)
|
||||
end
|
||||
end
|
||||
|
||||
responder.on(:response) do |data|
|
||||
update_thinking("Analyzing your data...")
|
||||
|
||||
Chat.transaction do
|
||||
if data[:function_tool_calls].present?
|
||||
assistant_message.append_tool_calls!(data[:function_tool_calls])
|
||||
end
|
||||
|
||||
if data[:function_tool_calls].present?
|
||||
assistant_message.tool_calls = data[:function_tool_calls]
|
||||
latest_response_id = data[:id]
|
||||
else
|
||||
chat.update_latest_response!(data[:id])
|
||||
end
|
||||
end
|
||||
|
||||
responder.respond(previous_response_id: chat.latest_assistant_response_id)
|
||||
responder.respond(previous_response_id: latest_response_id)
|
||||
rescue => e
|
||||
stop_thinking
|
||||
chat.add_error(e)
|
||||
|
|
|
@ -9,9 +9,4 @@ class AssistantMessage < Message
|
|||
self.content += text
|
||||
save!
|
||||
end
|
||||
|
||||
def append_tool_calls!(tool_calls)
|
||||
self.tool_calls.concat(tool_calls)
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class Message < ApplicationRecord
|
|||
failed: "failed"
|
||||
}
|
||||
|
||||
validates :content, presence: true, allow_blank: true
|
||||
validates :content, presence: true
|
||||
|
||||
after_create_commit -> { broadcast_append_to chat, target: "messages" }, if: :broadcast?
|
||||
after_update_commit -> { broadcast_update_to chat }, if: :broadcast?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue