mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-07 03:58:18 +00:00
f57c1bb0f6
We pass the text to the current LLM and ask them to generate a StableDifussion prompt. We'll use that to generate 4 samples, temporarily creating uploads and returning their short URLs.
22 lines
578 B
Ruby
22 lines
578 B
Ruby
# frozen_string_literal: true
|
|
|
|
class StableDiffusionStubs
|
|
include RSpec::Matchers
|
|
|
|
def stub_response(prompt, images)
|
|
artifacts = images.map { |i| { base64: i } }
|
|
|
|
WebMock
|
|
.stub_request(
|
|
:post,
|
|
"https://api.stability.dev/v1/generation/#{SiteSetting.ai_stability_engine}/text-to-image",
|
|
)
|
|
.with do |request|
|
|
json = JSON.parse(request.body, symbolize_names: true)
|
|
expect(json[:text_prompts][0][:text]).to eq(prompt)
|
|
true
|
|
end
|
|
.to_return(status: 200, body: { artifacts: artifacts }.to_json)
|
|
end
|
|
end
|