Sha256: 6db99511f78d1de102380b6503a576fb0524182c9b824a3a8326c683e2cd7f2b

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Llm
  module Functions
    class OverwriteFile < Base
      def function_name
        :overwrite_file
      end

      def definition
        return @definition unless @definition.nil?

        @definition = {
          name: self.function_name,
          description: I18n.t("ghostest.functions.#{self.function_name}.description"),
          parameters: {
            type: :object,
            properties: {
              filepath: {
                type: :string,
                description: I18n.t("ghostest.functions.#{self.function_name}.parameters.filepath"),
              },
              new_text: {
                type: :string,
                description: I18n.t("ghostest.functions.#{self.function_name}.parameters.new_text"),
              },
            },
            required: [:filepath, :new_text],
          },
        }
        @definition
      end

      def execute_and_generate_message(args)
        unless File.exist?(args[:filepath])
          raise Ghostest::Error.new("File not found: #{args[:filepath]}")
        end
        File.write(args[:filepath], args[:new_text])

        { result: :success }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ghostest-0.1.0 lib/llm/functions/overwrite_file.rb