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

Commit 55530b3

Browse files
committed
update artifact fixed
1 parent 2283534 commit 55530b3

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

lib/ai_bot/tools/update_artifact.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def self.signature
3939
def self.inject_prompt(prompt:, context:, persona:)
4040
return if persona.options["do_not_echo_artifact"].to_s == "true"
4141
# we inject the current artifact content into the last user message
42-
if topic_id = context[:topic_id]
42+
if topic_id = context.topic_id
4343
posts = Post.where(topic_id: topic_id)
4444
artifact = AiArtifact.order("id desc").where(post: posts).first
4545
if artifact
@@ -113,7 +113,7 @@ def in_progress(instructions:, source: nil)
113113
end
114114

115115
def invoke
116-
post = Post.find_by(id: context[:post_id])
116+
post = Post.find_by(id: context.post_id)
117117
return error_response("No post context found") unless post
118118

119119
artifact = AiArtifact.find_by(id: parameters[:artifact_id])

spec/lib/modules/ai_bot/tools/update_artifact_spec.rb

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
persona_options: {
4848
"update_algorithm" => "full",
4949
},
50-
context: {
51-
post_id: post.id,
52-
},
50+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
5351
)
5452

5553
result = tool.invoke {}
@@ -93,9 +91,7 @@
9391
persona_options: {
9492
"update_algorithm" => "full",
9593
},
96-
context: {
97-
post_id: post.id,
98-
},
94+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
9995
)
10096

10197
result = tool.invoke {}
@@ -119,9 +115,7 @@
119115
{ artifact_id: artifact.id, instructions: "Invalid update" },
120116
bot_user: bot_user,
121117
llm: llm_model.to_llm,
122-
context: {
123-
post_id: post.id,
124-
},
118+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
125119
)
126120

127121
result = tool.invoke {}
@@ -135,9 +129,7 @@
135129
{ artifact_id: -1, instructions: "Update something" },
136130
bot_user: bot_user,
137131
llm: llm_model.to_llm,
138-
context: {
139-
post_id: post.id,
140-
},
132+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
141133
)
142134

143135
result = tool.invoke {}
@@ -163,9 +155,7 @@
163155
persona_options: {
164156
"update_algorithm" => "full",
165157
},
166-
context: {
167-
post_id: post.id,
168-
},
158+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
169159
)
170160

171161
tool.invoke {}
@@ -196,9 +186,7 @@
196186
persona_options: {
197187
"update_algorithm" => "full",
198188
},
199-
context: {
200-
post_id: post.id,
201-
},
189+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
202190
)
203191
.invoke {}
204192
end
@@ -224,9 +212,7 @@
224212
persona_options: {
225213
"update_algorithm" => "full",
226214
},
227-
context: {
228-
post_id: post.id,
229-
},
215+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
230216
)
231217

232218
result = tool.invoke {}
@@ -276,9 +262,7 @@
276262
{ artifact_id: artifact.id, instructions: "Change the text to Updated and color to red" },
277263
bot_user: bot_user,
278264
llm: llm_model.to_llm,
279-
context: {
280-
post_id: post.id,
281-
},
265+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
282266
persona_options: {
283267
"update_algorithm" => "diff",
284268
},
@@ -346,9 +330,7 @@
346330
{ artifact_id: artifact.id, instructions: "Change the text to Updated and color to red" },
347331
bot_user: bot_user,
348332
llm: llm_model.to_llm,
349-
context: {
350-
post_id: post.id,
351-
},
333+
context: DiscourseAi::AiBot::BotContext.new(messages: [], post: post),
352334
persona_options: {
353335
"update_algorithm" => "diff",
354336
},

0 commit comments

Comments
 (0)