Module: Raix::FunctionDispatch

Extended by:
ActiveSupport::Concern
Defined in:
lib/raix/function_dispatch.rb

Overview

Provides declarative function definition for ChatCompletion classes.

Example:

class MeaningOfLife
  include Raix::ChatCompletion
  include Raix::FunctionDispatch

  function :ask_deep_thought do
    wait 236_682_000_000_000
    "The meaning of life is 42"
  end

  def initialize
    transcript << { user: "What is the meaning of life?" }
    chat_completion
  end
end

Instance Method Summary collapse

Instance Method Details

#chat_completion(**chat_completion_args) ⇒ Object



114
115
116
117
# File 'lib/raix/function_dispatch.rb', line 114

def chat_completion(**chat_completion_args)
  self.chat_completion_args = chat_completion_args
  super
end

#stop_tool_calls_and_respond!Object

Stops the automatic continuation of chat completions after this function call. Useful when you want to halt processing within a function and force the AI to provide a text response without making additional tool calls.



122
123
124
# File 'lib/raix/function_dispatch.rb', line 122

def stop_tool_calls_and_respond!
  @stop_tool_calls_and_respond = true
end

#toolsObject



126
127
128
129
130
# File 'lib/raix/function_dispatch.rb', line 126

def tools
  return [] unless self.class.functions

  self.class.functions.map { |function| { type: "function", function: } }
end