Class: Llm::Functions::AddToMemory

Inherits:
Base
  • Object
show all
Defined in:
lib/llm/functions/add_to_memory.rb

Instance Method Summary collapse

Methods inherited from Base

#stop_llm_call?

Constructor Details

#initialize(message_container) ⇒ AddToMemory

Returns a new instance of AddToMemory.



8
9
10
# File 'lib/llm/functions/add_to_memory.rb', line 8

def initialize(message_container)
  @message_container = message_container
end

Instance Method Details

#definitionObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/llm/functions/add_to_memory.rb', line 12

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: {
        contents_to_memory: {
          type: :string,
          description: I18n.t("ghostest.functions.#{self.function_name}.parameters.contents_to_memory"),
        },
      },
      required: [:contents_to_memory],
    },
  }
  @definition
end

#execute_and_generate_message(args) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/llm/functions/add_to_memory.rb', line 32

def execute_and_generate_message(args)
  if args[:contents_to_memory].nil? || args[:contents_to_memory].empty?
    raise "contents_to_memory is required"
  end
  @message_container.add_system_message(I18n.t("ghostest.functions.#{self.function_name}.system_message_prefix", contents_to_memory: args[:contents_to_memory]))
  { result: 'success' }
end

#function_nameObject



4
5
6
# File 'lib/llm/functions/add_to_memory.rb', line 4

def function_name
  :add_to_memory
end