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(*tools) ⇒ Object
(also: #with_tools)
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #ask(message, &block) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(model: nil) ⇒ Chat
constructor
A new instance of Chat.
- #tool(tool) ⇒ Object (also: #with_tool)
Constructor Details
#initialize(model: nil) ⇒ Chat
Returns a new instance of Chat.
9 10 11 12 13 14 15 |
# 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 = [] 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(*tools) ⇒ Object (readonly) Also known as: with_tools
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
17 18 19 20 |
# File 'lib/ruby_llm/chat.rb', line 17 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 |
#tool(tool) ⇒ Object Also known as: with_tool
22 23 24 25 26 27 |
# File 'lib/ruby_llm/chat.rb', line 22 def tool(tool) raise Error, "Model #{@model.id} doesn't support function calling" unless @model.supports_functions @tools << tool self end |