Skip to content

Commit 3fd8e62

Browse files
author
Yetibot
committed
Show model and cost in USD as footer for agent prompt and banana image responses
1 parent d7dc93b commit 3fd8e62

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/yetibot/core/commands/agent.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@
132132
(defn say-final
133133
"The clean final reply: Gemini's summary plus links to any relevant PRs."
134134
[summary pr-urls]
135-
(str (if (string/blank? summary) "✅ done." (str "" summary))
136-
(when (seq pr-urls)
137-
(str "\n\n🔗 " (string/join "" (distinct pr-urls))))))
135+
(let [footer (format "\n\nSent via %s | Cost: $%.2f" (model) (gemini/agent-cost-per-session))]
136+
(str (if (string/blank? summary) "✅ done." (str "" summary))
137+
(when (seq pr-urls)
138+
(str "\n\n🔗 " (string/join "" (distinct pr-urls))))
139+
footer)))
138140

139141
(defn say-broken [msg]
140142
(str "⚠️ Gemini error: " msg))

src/yetibot/core/commands/banana.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
(str "Generate an image: " prompt) nil image-urls)
3636
id (store-image! image)
3737
base-url (gemini/yetibot-base-url)
38-
image-url (format "%s/generated-images/%s.png" base-url id)]
38+
image-url (format "%s/generated-images/%s.png" base-url id)
39+
footer (format "\n\nSent via %s | Cost: $%.3f" (gemini/gemini-model) (gemini/cost-per-image))]
3940
(info "banana: image generated successfully, serving at" image-url)
40-
{:result/value image-url
41+
{:result/value (str image-url footer)
4142
:result/data {:id id :prompt match :url image-url}})
4243
(catch Exception e
4344
(error "banana: Gemini image generation error:" (.getMessage e))

src/yetibot/core/util/gemini.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"Default monthly budget in USD for image generation."
5656
5.00)
5757

58-
(defn- cost-per-image []
58+
(defn cost-per-image []
5959
(or (parse-number (-> config :cost :per))
6060
(case (gemini-model)
6161
"gemini-3.1-flash-image-preview" 0.039
@@ -68,7 +68,7 @@
6868
(defn- max-images-per-month []
6969
(long (Math/floor (/ (monthly-budget) (cost-per-image)))))
7070

71-
(defn- agent-cost-per-session []
71+
(defn agent-cost-per-session []
7272
(or (parse-number (-> config :agent :cost-per-session)) 1.00))
7373

7474
(defn agent-cost-units []

test/yetibot/core/test/commands/agent.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
(agent/say-final "done" ["https://github.com/yetibot/core/pull/242"]) => (contains "pull/242"))
7474
(fact "say-final copes with a blank answer"
7575
(agent/say-final "" nil) => (contains "done"))
76+
(fact "say-final appends the model and cost footer"
77+
(agent/say-final "Added features" nil) => (contains "Sent via gemini-3.1-pro-preview | Cost: $1.00"))
7678
(fact "say-timeout names the limit"
7779
(agent/say-timeout 5) => (contains "5 min")))
7880

test/yetibot/core/test/commands/banana_test.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@
2323
:agent-sessions-left 10
2424
:agent-cost-units 10
2525
:month "2026-05"})))
26+
27+
(facts "about banana-cmd"
28+
(fact "it generates an image and returns URL with model and cost footer"
29+
(b/banana-cmd {:match "banana monkey" :chat-source {}})
30+
=> (contains {:result/value #"http://localhost:3003/generated-images/img123.png\n\nSent via gemini-3.1-flash-image-preview \| Cost: \$0.039"
31+
:result/data {:id "img123" :prompt "banana monkey" :url "http://localhost:3003/generated-images/img123.png"}})
32+
(provided
33+
(gemini/configured?) => true
34+
(yetibot.core.util.image-input/extract-images "banana monkey" {}) => {:prompt "monkey" :image-urls []}
35+
(gemini/generate-image "Generate an image: monkey" nil []) => {:data "bytes" :mime-type "image/png"}
36+
(yetibot.core.webapp.routes.images/store-image! {:data "bytes" :mime-type "image/png"}) => "img123"
37+
(gemini/yetibot-base-url) => "http://localhost:3003"
38+
(gemini/gemini-model) => "gemini-3.1-flash-image-preview"
39+
(gemini/cost-per-image) => 0.039)))

0 commit comments

Comments
 (0)