Class: Genai::Chats
- Inherits:
-
Object
- Object
- Genai::Chats
- Defined in:
- lib/genai/chat.rb
Instance Method Summary collapse
- #clear_all_sessions ⇒ Object
- #clear_user_session(user_id) ⇒ Object
- #create(model:, config: nil, history: []) ⇒ Object
- #get_active_users ⇒ Object
- #get_session_count ⇒ Object
- #get_user_session(user_id, model: "gemini-2.0-flash", config: nil) ⇒ Object
-
#initialize(client) ⇒ Chats
constructor
A new instance of Chats.
Constructor Details
#initialize(client) ⇒ Chats
Returns a new instance of Chats.
164 165 166 167 |
# File 'lib/genai/chat.rb', line 164 def initialize(client) @client = client @user_sessions = {} end |
Instance Method Details
#clear_all_sessions ⇒ Object
191 192 193 |
# File 'lib/genai/chat.rb', line 191 def clear_all_sessions @user_sessions.clear end |
#clear_user_session(user_id) ⇒ Object
187 188 189 |
# File 'lib/genai/chat.rb', line 187 def clear_user_session(user_id) @user_sessions.delete(user_id) end |
#create(model:, config: nil, history: []) ⇒ Object
169 170 171 |
# File 'lib/genai/chat.rb', line 169 def create(model:, config: nil, history: []) Chat.new(client: @client, model: model, config: config, history: history) end |
#get_active_users ⇒ Object
199 200 201 |
# File 'lib/genai/chat.rb', line 199 def get_active_users @user_sessions.keys end |
#get_session_count ⇒ Object
195 196 197 |
# File 'lib/genai/chat.rb', line 195 def get_session_count @user_sessions.length end |
#get_user_session(user_id, model: "gemini-2.0-flash", config: nil) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/genai/chat.rb', line 173 def get_user_session(user_id, model: "gemini-2.0-flash", config: nil) unless @user_sessions[user_id] @user_sessions[user_id] = create( model: model, config: config || { temperature: 0.7, max_output_tokens: 2048 } ) end @user_sessions[user_id] end |