Class: GenAI::Chat::Base
Direct Known Subclasses
Constant Summary collapse
- USER_ROLE =
'user'
- ASSISTANT_ROLE =
'assistant'
Instance Attribute Summary collapse
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
Instance Method Summary collapse
-
#initialize(provider:, token:, options: {}) ⇒ Base
constructor
A new instance of Base.
- #message(message, options = {}, &block) ⇒ Object
- #start(history: [], context: nil, examples: []) ⇒ Object
Methods included from Dependency
Constructor Details
Instance Attribute Details
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
9 10 11 |
# File 'lib/gen_ai/chat/base.rb', line 9 def @default_options end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
9 10 11 |
# File 'lib/gen_ai/chat/base.rb', line 9 def history @history end |
Instance Method Details
#message(message, options = {}, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gen_ai/chat/base.rb', line 21 def (, = {}, &block) if @history.size == 1 && @history.first[:role] != 'system' () else append_to_history({ role: USER_ROLE, content: }) end response = @model.chat(@history.dup, .merge().compact, &block) append_to_history({ role: ASSISTANT_ROLE, content: response.value }) response end |
#start(history: [], context: nil, examples: []) ⇒ Object
17 18 19 |
# File 'lib/gen_ai/chat/base.rb', line 17 def start(history: [], context: nil, examples: []) @history = build_history(history.map(&:deep_symbolize_keys), context, examples.map(&:deep_symbolize_keys)) end |