Module: LLM::ActiveRecord::ActsAsLLM::InstanceMethods

Defined in:
lib/llm/active_record/acts_as_llm.rb

Instance Method Summary collapse

Instance Method Details

#askLLM::Response

Continues the stored context with new input and flushes it.

Returns:

See Also:



71
72
73
74
# File 'lib/llm/active_record/acts_as_llm.rb', line 71

def ask(...)
  options = self.class.llm_plugin_options
  ctx.ask(...).tap { Utils.save!(self, ctx, options) }
end

#context_windowInteger

Returns:

  • (Integer)

See Also:



137
138
139
140
141
# File 'lib/llm/active_record/acts_as_llm.rb', line 137

def context_window
  ctx.context_window
rescue LLM::NoSuchModelError, LLM::NoSuchRegistryError
  0
end

#costLLM::Cost

Returns:

See Also:



130
131
132
# File 'lib/llm/active_record/acts_as_llm.rb', line 130

def cost
  ctx.cost
end

#functionsArray<LLM::Function>

Returns:

See Also:



109
110
111
# File 'lib/llm/active_record/acts_as_llm.rb', line 109

def functions
  ctx.functions
end

#functions?Boolean

Returns:

  • (Boolean)

See Also:



116
117
118
# File 'lib/llm/active_record/acts_as_llm.rb', line 116

def functions?
  ctx.functions?
end

#image_urlLLM::Object

Returns:

See Also:



169
170
171
# File 'lib/llm/active_record/acts_as_llm.rb', line 169

def image_url(...)
  ctx.image_url(...)
end

#interrupt!nil Also known as: cancel!

Returns:

  • (nil)

See Also:



153
154
155
# File 'lib/llm/active_record/acts_as_llm.rb', line 153

def interrupt!
  ctx.interrupt!
end

#llmLLM::Provider

Returns the resolved provider instance for this record.

Returns:



197
198
199
200
201
202
203
# File 'lib/llm/active_record/acts_as_llm.rb', line 197

def llm
  options = self.class.llm_plugin_options
  return @llm if @llm
  @llm = Utils.resolve_provider(self, options, EMPTY_HASH)
  @llm.tracer = Utils.resolve_option(self, options[:tracer]) if options[:tracer]
  @llm
end

#local_fileLLM::Object

Returns:

See Also:



176
177
178
# File 'lib/llm/active_record/acts_as_llm.rb', line 176

def local_file(...)
  ctx.local_file(...)
end

#messagesArray<LLM::Message>

Returns:

See Also:



94
95
96
# File 'lib/llm/active_record/acts_as_llm.rb', line 94

def messages
  ctx.messages
end

#modeSymbol

Returns:

  • (Symbol)

See Also:



87
88
89
# File 'lib/llm/active_record/acts_as_llm.rb', line 87

def mode
  ctx.mode
end

#model!String

Note:

The bang keeps the ActiveRecord and Sequel wrappers aligned.

Returns:

  • (String)

See Also:



102
103
104
# File 'lib/llm/active_record/acts_as_llm.rb', line 102

def model!
  ctx.model
end

#promptLLM::Prompt Also known as: build_prompt

Returns:

See Also:



161
162
163
# File 'lib/llm/active_record/acts_as_llm.rb', line 161

def prompt(&)
  ctx.prompt(&)
end

#remote_fileLLM::Object

Returns:

See Also:



183
184
185
# File 'lib/llm/active_record/acts_as_llm.rb', line 183

def remote_file(...)
  ctx.remote_file(...)
end

#returnsArray<LLM::Function::Return>

Returns:

See Also:



123
124
125
# File 'lib/llm/active_record/acts_as_llm.rb', line 123

def returns
  ctx.returns
end

#talkLLM::Response

Continues the stored context with new input and flushes it.

Returns:

See Also:



62
63
64
65
# File 'lib/llm/active_record/acts_as_llm.rb', line 62

def talk(...)
  options = self.class.llm_plugin_options
  ctx.talk(...).tap { Utils.save!(self, ctx, options) }
end

#tracerLLM::Tracer

Returns:

See Also:



190
191
192
# File 'lib/llm/active_record/acts_as_llm.rb', line 190

def tracer
  ctx.tracer
end

#usageLLM::Object

Returns usage from the mapped usage columns.

Returns:



146
147
148
# File 'lib/llm/active_record/acts_as_llm.rb', line 146

def usage
  ctx.usage || LLM::Object.from(input_tokens: 0, output_tokens: 0, total_tokens: 0)
end

#waitArray<LLM::Function::Return>

Waits for queued tool work to finish.

Returns:

See Also:



80
81
82
# File 'lib/llm/active_record/acts_as_llm.rb', line 80

def wait(...)
  ctx.wait(...)
end