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_model(model_id) ⇒ Object
- #with_temperature(temperature) ⇒ Object
- #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 18 |
# 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 @temperature = 0.7 @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
20 21 22 23 |
# File 'lib/ruby_llm/chat.rb', line 20 def ask(, &block) role: :user, content: complete(&block) end |
#each(&block) ⇒ Object
51 52 53 |
# File 'lib/ruby_llm/chat.rb', line 51 def each(&block) .each(&block) end |
#with_model(model_id) ⇒ Object
40 41 42 43 44 |
# File 'lib/ruby_llm/chat.rb', line 40 def with_model(model_id) @model = Models.find model_id @provider = Models.provider_for model_id self end |
#with_temperature(temperature) ⇒ Object
46 47 48 49 |
# File 'lib/ruby_llm/chat.rb', line 46 def with_temperature(temperature) @temperature = temperature self end |
#with_tool(tool) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ruby_llm/chat.rb', line 27 def with_tool(tool) raise Error, "Model #{@model.id} doesn't support function calling" unless @model.supports_functions tool_instance = tool.is_a?(Class) ? tool.new : tool @tools[tool_instance.name.to_sym] = tool_instance self end |
#with_tools(*tools) ⇒ Object
35 36 37 38 |
# File 'lib/ruby_llm/chat.rb', line 35 def with_tools(*tools) tools.each { |tool| with_tool tool } self end |