Class: Genai::BaseChat
- Inherits:
-
Object
- Object
- Genai::BaseChat
- Defined in:
- lib/genai/chat.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#comprehensive_history ⇒ Object
readonly
Returns the value of attribute comprehensive_history.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#curated_history ⇒ Object
readonly
Returns the value of attribute curated_history.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #get_history(curated: false) ⇒ Object
-
#initialize(model:, config: nil, history: []) ⇒ BaseChat
constructor
A new instance of BaseChat.
- #record_history(user_input:, model_output:, automatic_function_calling_history: [], is_valid: true) ⇒ Object
Constructor Details
#initialize(model:, config: nil, history: []) ⇒ BaseChat
Returns a new instance of BaseChat.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/genai/chat.rb', line 69 def initialize(model:, config: nil, history: []) @model = model @config = config content_models = history.map do |content| content.is_a?(Hash) ? content : content end @comprehensive_history = content_models @curated_history = ChatValidator.extract_curated_history(content_models) end |
Instance Attribute Details
#comprehensive_history ⇒ Object (readonly)
Returns the value of attribute comprehensive_history.
67 68 69 |
# File 'lib/genai/chat.rb', line 67 def comprehensive_history @comprehensive_history end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
67 68 69 |
# File 'lib/genai/chat.rb', line 67 def config @config end |
#curated_history ⇒ Object (readonly)
Returns the value of attribute curated_history.
67 68 69 |
# File 'lib/genai/chat.rb', line 67 def curated_history @curated_history end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
67 68 69 |
# File 'lib/genai/chat.rb', line 67 def model @model end |
Instance Method Details
#get_history(curated: false) ⇒ Object
99 100 101 |
# File 'lib/genai/chat.rb', line 99 def get_history(curated: false) curated ? @curated_history : @comprehensive_history end |
#record_history(user_input:, model_output:, automatic_function_calling_history: [], is_valid: true) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/genai/chat.rb', line 81 def record_history(user_input:, model_output:, automatic_function_calling_history: [], is_valid: true) input_contents = if !automatic_function_calling_history.empty? automatic_function_calling_history[@curated_history.length..-1] || [user_input] else [user_input] end output_contents = model_output.empty? ? [{ role: "model", parts: [] }] : model_output @comprehensive_history.concat(input_contents) @comprehensive_history.concat(output_contents) if is_valid @curated_history.concat(input_contents) @curated_history.concat(output_contents) end end |