Class: Askcii::Chat
- Inherits:
-
Object
- Object
- Askcii::Chat
- Defined in:
- lib/askcii/models/chat.rb
Instance Method Summary collapse
- #persist_message_completion(message) ⇒ Object
- #persist_new_message ⇒ Object
-
#to_llm(config) ⇒ RubyLLM::Chat
Converts this Chat to a RubyLLM::Chat object with message history.
Instance Method Details
#persist_message_completion(message) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/askcii/models/chat.rb', line 34 def () return unless .update( role: .role, content: .content, model_id: .model_id, input_tokens: .input_tokens, output_tokens: .output_tokens ) end |
#persist_new_message ⇒ Object
27 28 29 30 31 32 |
# File 'lib/askcii/models/chat.rb', line 27 def = ( role: :assistant, content: String.new ) end |
#to_llm(config) ⇒ RubyLLM::Chat
Converts this Chat to a RubyLLM::Chat object with message history
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/askcii/models/chat.rb', line 10 def to_llm(config) provider = config[:provider] || config['provider'] || 'openai' provider_symbol = provider.to_sym @chat = RubyLLM.chat( model: model_id, provider: provider_symbol, assume_model_exists: true ) .each do |msg| @chat.(msg.to_llm) end @chat. { } @chat. { |msg| (msg) } @chat end |