generated from discourse/discourse-plugin-skeleton
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: refine image and read command (#131)
- Attempt to hint reading is done by sending complete:true - Do not include post_number in result unless it was sent in - Rush visual feedback when a command is run (ensure we always revise) - Include hyperlink in read command description - Stop round tripping to GPT after image generation (speeds up images by a lot) - Add a test for image command
- Loading branch information
1 parent
958dfc3
commit 7eedbf2
Showing
7 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#frozen_string_literal: true | ||
|
||
RSpec.describe DiscourseAi::AiBot::Commands::ImageCommand do | ||
fab!(:bot_user) { User.find(DiscourseAi::AiBot::EntryPoint::GPT3_5_TURBO_ID) } | ||
|
||
describe "#process" do | ||
it "can generate correct info" do | ||
post = Fabricate(:post) | ||
|
||
SiteSetting.ai_stability_api_url = "https://api.stability.dev" | ||
SiteSetting.ai_stability_api_key = "abc" | ||
|
||
image = | ||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==" | ||
|
||
stub_request( | ||
:post, | ||
"https://api.stability.dev/v1/generation/#{SiteSetting.ai_stability_engine}/text-to-image", | ||
) | ||
.with do |request| | ||
json = JSON.parse(request.body) | ||
expect(json["text_prompts"][0]["text"]).to eq("a pink cow") | ||
true | ||
end | ||
.to_return(status: 200, body: { artifacts: [{ base64: image }, { base64: image }] }.to_json) | ||
|
||
image = described_class.new(bot_user, post) | ||
info = image.process(prompt: "a pink cow").to_json | ||
|
||
expect(JSON.parse(info)).to eq("prompt" => "a pink cow", "displayed_to_user" => true) | ||
expect(image.custom_raw).to include("upload://") | ||
expect(image.custom_raw).to include("[grid]") | ||
expect(image.custom_raw).to include("a pink cow") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters