Class: RubyLLM::Chat
- Inherits:
-
Object
- Object
- RubyLLM::Chat
- Includes:
- Enumerable
- Defined in:
- lib/ruby_llm/chat.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #ask(message, &block) ⇒ Object (also: #say)
- #each(&block) ⇒ Object
-
#initialize(model: nil) ⇒ Chat
constructor
A new instance of Chat.
- #with_tool(tool) ⇒ Object
- #with_tools(*tools) ⇒ Object
Constructor Details
#initialize(model: nil) ⇒ Chat
Returns a new instance of Chat.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_llm/chat.rb', line 9 def initialize(model: nil) model_id = model || RubyLLM.config.default_model @model = Models.find model_id @provider = Models.provider_for model_id @messages = [] @tools = {} ensure_valid_tools end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
7 8 9 |
# File 'lib/ruby_llm/chat.rb', line 7 def @messages end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/ruby_llm/chat.rb', line 7 def model @model end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
7 8 9 |
# File 'lib/ruby_llm/chat.rb', line 7 def tools @tools end |
Instance Method Details
#ask(message, &block) ⇒ Object Also known as: say
19 20 21 22 |
# File 'lib/ruby_llm/chat.rb', line 19 def ask(, &block) role: :user, content: complete(&block) end |
#each(&block) ⇒ Object
38 39 40 |
# File 'lib/ruby_llm/chat.rb', line 38 def each(&block) .each(&block) end |
#with_tool(tool) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ruby_llm/chat.rb', line 26 def with_tool(tool) raise Error, "Model #{@model.id} doesn't support function calling" unless @model.supports_functions @tools[tool.name] = tool self end |
#with_tools(*tools) ⇒ Object
33 34 35 36 |
# File 'lib/ruby_llm/chat.rb', line 33 def with_tools(*tools) tools.each { |tool| with_tool tool } self end |