|
| 1 | +(ns yetibot.core.test.commands.grokimage-test |
| 2 | + (:require [midje.sweet :refer [facts fact => contains provided]] |
| 3 | + [yetibot.core.commands.grokimage :as grokimg] |
| 4 | + [yetibot.core.util.xai :as xai] |
| 5 | + [yetibot.core.util.gemini :as gemini])) |
| 6 | + |
| 7 | +(facts "about grokimage-cmd" |
| 8 | + (fact "it returns an error if xAI is not configured" |
| 9 | + (grokimg/grokimage-cmd {:match "grokimage space kitty" :chat-source {}}) => (contains {:result/error string?}) |
| 10 | + (provided (xai/configured?) => false)) |
| 11 | + |
| 12 | + (fact "it generates an image and returns URL with model footer when configured, without any system instruction" |
| 13 | + (grokimg/grokimage-cmd {:match "grokimage space kitty" :chat-source {}}) |
| 14 | + => (contains {:result/value #"http://localhost:3003/generated-images/grok123.png\n\nSent via grok-imagine-image-2.0 \| Cost: \$0.04" |
| 15 | + :result/data {:id "grok123" :prompt "grokimage space kitty" :url "http://localhost:3003/generated-images/grok123.png"}}) |
| 16 | + (provided |
| 17 | + (xai/configured?) => true |
| 18 | + (yetibot.core.util.image-input/extract-images "grokimage space kitty" {}) => {:prompt "space kitty" :image-urls []} |
| 19 | + (xai/generate-image "space kitty" nil []) => {:data "grokbytes" :mime-type "image/jpeg"} |
| 20 | + (yetibot.core.webapp.routes.images/store-image! {:data "grokbytes" :mime-type "image/jpeg"}) => "grok123" |
| 21 | + (gemini/yetibot-base-url) => "http://localhost:3003")) |
| 22 | + |
| 23 | + (fact "it generates an edited image when image-urls/attachments are provided, without any system instruction" |
| 24 | + (grokimg/grokimage-cmd {:match "sketch this" :chat-source {:raw-event {:attachments [{:url "https://example.com/source.jpg" :content-type "image/jpeg"}]}}}) |
| 25 | + => (contains {:result/value #"http://localhost:3003/generated-images/grok123.png\n\nSent via grok-imagine-image-2.0 \| Cost: \$0.04" |
| 26 | + :result/data {:id "grok123" :prompt "sketch this" :url "http://localhost:3003/generated-images/grok123.png"}}) |
| 27 | + (provided |
| 28 | + (xai/configured?) => true |
| 29 | + (yetibot.core.util.image-input/extract-images "sketch this" (contains {:raw-event map?})) => {:prompt "sketch this" :image-urls ["https://example.com/source.jpg"]} |
| 30 | + (xai/generate-image "sketch this" nil ["https://example.com/source.jpg"]) => {:data "grokbytes" :mime-type "image/jpeg"} |
| 31 | + (yetibot.core.webapp.routes.images/store-image! {:data "grokbytes" :mime-type "image/jpeg"}) => "grok123" |
| 32 | + (gemini/yetibot-base-url) => "http://localhost:3003"))) |
0 commit comments