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

Commit 2283534

Browse files
committed
fix specs
1 parent 2c8b880 commit 2283534

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

lib/ai_bot/tools/tool.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ def initialize(
5656
persona_options: {},
5757
bot_user:,
5858
llm:,
59-
context: {}
59+
context: nil
6060
)
6161
@parameters = parameters
6262
@tool_call_id = tool_call_id
6363
@persona_options = persona_options
6464
@bot_user = bot_user
6565
@llm = llm
66-
@context = context
66+
@context = context.nil? ? DiscourseAi::AiBot::BotContext.new(messages: []) : context
67+
if !@context.is_a?(DiscourseAi::AiBot::BotContext)
68+
raise ArgumentError, "context must be a DiscourseAi::AiBot::Context"
69+
end
6770
end
6871

6972
def name

lib/automation/llm_triage.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ def self.handle(
4242

4343
content = llm.tokenizer.truncate(content, max_post_tokens) if max_post_tokens.present?
4444

45-
prompt.push(type: :user, content: content, upload_ids: post.upload_ids)
45+
if post.upload_ids.present?
46+
content = [content]
47+
content.concat(post.upload_ids.map { |upload_id| { upload_id: upload_id } })
48+
end
49+
50+
prompt.push(type: :user, content: content)
4651

4752
result = nil
4853

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{gpt_35_turbo.id}") }
1616
let(:progress_blk) { Proc.new {} }
1717

18-
let(:dall_e) do
19-
described_class.new({ prompts: prompts }, llm: llm, bot_user: bot_user, context: {})
20-
end
18+
let(:dall_e) { described_class.new({ prompts: prompts }, llm: llm, bot_user: bot_user) }
2119

2220
let(:base64_image) do
2321
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
@@ -30,8 +28,6 @@
3028
{ prompts: ["a cat"], aspect_ratio: "tall" },
3129
llm: llm,
3230
bot_user: bot_user,
33-
context: {
34-
},
3531
)
3632

3733
data = [{ b64_json: base64_image, revised_prompt: "a tall cat" }]

spec/lib/modules/automation/llm_triage_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def triage(**args)
199199

200200
triage_prompt = DiscourseAi::Completions::Llm.prompts.last
201201

202-
expect(triage_prompt.messages.last[:upload_ids]).to contain_exactly(post_upload.id)
202+
expect(triage_prompt.messages.last[:content].last).to eq({ upload_id: post_upload.id })
203203
end
204204
end
205205

0 commit comments

Comments
 (0)