Class: Google::Genai::Chat

Inherits:
Object
  • Object
show all
Defined in:
lib/google/genai/chats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, model:, history: [], config: nil) ⇒ Chat

Returns a new instance of Chat.



18
19
20
21
22
23
# File 'lib/google/genai/chats.rb', line 18

def initialize(client:, model:, history: [], config: nil)
  @client = client
  @model = model
  @history = history
  @config = config
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



16
17
18
# File 'lib/google/genai/chats.rb', line 16

def history
  @history
end

Instance Method Details

#send_message(message) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/google/genai/chats.rb', line 25

def send_message(message)
  @history << { role: 'user', parts: [{ text: message }] }
  response = @client.models.generate_content(
    model: @model,
    contents: @history,
    config: @config
  )
  @history << response.candidates.first.content.to_h
  response
end