Sam ab78d9b597
REFACTOR: Simplify tool invocation by removing bot_user and llm parameters (#603)
* Well, it was quite a journey but now tools have "context" which
can be critical for the stuff they generate

This entire change was so Dall E and Artist generate images in the correct context

* FIX: improve error handling around image generation

- also corrects image markdown and clarifies code

* fix spec
2024-05-07 21:55:46 +10:00

53 lines
1.1 KiB
Ruby

#frozen_string_literal: true
module DiscourseAi
module AiBot
module Tools
class Time < Tool
def self.signature
{
name: name,
description: "Will generate the time in a timezone",
parameters: [
{
name: "timezone",
description: "ALWAYS supply a Ruby compatible timezone",
type: "string",
required: true,
},
],
}
end
def self.name
"time"
end
def timezone
parameters[:timezone].to_s
end
def invoke
time =
begin
::Time.now.in_time_zone(timezone)
rescue StandardError
nil
end
time = ::Time.now if !time
@last_time = time.to_s
{ args: { timezone: timezone }, time: time.to_s }
end
private
def description_args
{ timezone: timezone, time: @last_time }
end
end
end
end
end