From 0b62c0fa020c4feb46c2367d7db4f7cf6e27f2ae Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 31 Oct 2023 19:12:25 +1100 Subject: [PATCH] FIX: keep parity of shape for image command (#275) Function calling will start hallucinating if you reshape results. Previously we were morphing from: `{ prompts: ["prompt 1", "prompt 2"] }` to `{ prompts: { prompt: "prompt 1", seed: 222}, { ... ` This meant that over a few call sequences function_call starts hallucinating an incorrect shape. This change grounds us even on GPT-3.5 --- lib/modules/ai_bot/commands/image_command.rb | 5 +---- spec/lib/modules/ai_bot/commands/image_command_spec.rb | 8 +------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/modules/ai_bot/commands/image_command.rb b/lib/modules/ai_bot/commands/image_command.rb index 22cd83fc..a170cef8 100644 --- a/lib/modules/ai_bot/commands/image_command.rb +++ b/lib/modules/ai_bot/commands/image_command.rb @@ -129,10 +129,7 @@ module DiscourseAi::AiBot::Commands [/grid] RAW - { - prompts: uploads.map { |item| { prompt: item[:prompt], seed: item[:seed] } }, - displayed_to_user: true, - } + { prompts: uploads.map { |item| item[:prompt] }, seeds: uploads.map { |item| item[:seed] } } end end end diff --git a/spec/lib/modules/ai_bot/commands/image_command_spec.rb b/spec/lib/modules/ai_bot/commands/image_command_spec.rb index ddecb5f2..0bd77657 100644 --- a/spec/lib/modules/ai_bot/commands/image_command_spec.rb +++ b/spec/lib/modules/ai_bot/commands/image_command_spec.rb @@ -34,13 +34,7 @@ RSpec.describe DiscourseAi::AiBot::Commands::ImageCommand do info = image.process(prompts: prompts).to_json - expect(JSON.parse(info)).to eq( - "prompts" => [ - { "prompt" => "a pink cow", "seed" => 99 }, - { "prompt" => "a red cow", "seed" => 99 }, - ], - "displayed_to_user" => true, - ) + expect(JSON.parse(info)).to eq("prompts" => ["a pink cow", "a red cow"], "seeds" => [99, 99]) expect(image.custom_raw).to include("upload://") expect(image.custom_raw).to include("[grid]") expect(image.custom_raw).to include("a pink cow")