Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 0f242bf

Browse files
committed
Fix progress tracker for tools
1 parent 8862e55 commit 0f242bf

File tree

4 files changed

+339
-62
lines changed

4 files changed

+339
-62
lines changed

lib/ai_bot/tools/create_artifact.rb

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -110,67 +110,6 @@ def update_custom_html(artifact = nil)
110110
self.custom_raw = content.map { |c| c[1] }.join("\n\n")
111111
end
112112

113-
def update_custom_html_old(artifact = nil)
114-
html = parameters[:html_body].to_s
115-
css = parameters[:css].to_s
116-
js = parameters[:js].to_s
117-
118-
tabs = { css: [css, "CSS"], js: [js, "JavaScript"], html: [html, "HTML"] }
119-
120-
if artifact
121-
iframe =
122-
"<iframe src=\"#{Discourse.base_url}/discourse-ai/ai-bot/artifacts/#{artifact.id}\" width=\"100%\" height=\"500\" frameborder=\"0\"></iframe>"
123-
tabs[:preview] = [iframe, "Preview"]
124-
end
125-
126-
first = true
127-
html_tabs =
128-
tabs.map do |tab, (content, name)|
129-
selected = " data-selected" if first
130-
first = false
131-
(<<~HTML).strip
132-
<div class="ai-artifact-tab" data-#{tab}#{selected}>
133-
<a>#{name}</a>
134-
</div>
135-
HTML
136-
end
137-
138-
first = true
139-
html_panels =
140-
tabs.map do |tab, (content, name)|
141-
selected = " data-selected" if (first || (!artifact && tab == @selected_tab))
142-
first = false
143-
inner_content =
144-
if tab == :preview
145-
content
146-
else
147-
<<~HTML
148-
149-
```#{tab}
150-
#{content}
151-
```
152-
HTML
153-
end
154-
(<<~HTML).strip
155-
<div class="ai-artifact-panel" data-#{tab}#{selected}>
156-
157-
#{inner_content}
158-
</div>
159-
HTML
160-
end
161-
162-
self.custom_raw = <<~RAW
163-
<div class="ai-artifact">
164-
<div class="ai-artifact-tabs">
165-
#{html_tabs.join("\n")}
166-
</div>
167-
<div class="ai-artifact-panels">
168-
#{html_panels.join("\n")}
169-
</div>
170-
</div>
171-
RAW
172-
end
173-
174113
def success_response(artifact)
175114
@chain_next_response = false
176115
iframe_url = "#{Discourse.base_url}/discourse-ai/ai-bot/artifacts/#{artifact.id}"

lib/completions/tool_call_progress_tracker.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def initialize(tool_call)
1616
@current_value = nil
1717
end
1818

19-
@parser.value { |v| tool_call.notify_progress(@current_key, v) if @current_key }
19+
@parser.value do |v|
20+
if @current_key
21+
tool_call.notify_progress(@current_key, v)
22+
@current_key = nil
23+
end
24+
end
2025
end
2126

2227
def <<(json)

0 commit comments

Comments
 (0)