Class: Gemini::Messages
- Inherits:
-
Object
- Object
- Gemini::Messages
- Defined in:
- lib/gemini/messages.rb
Instance Method Summary collapse
-
#create(thread_id:, parameters: {}) ⇒ Object
Create a new message.
-
#delete(thread_id:, id:) ⇒ Object
Delete a message (logical deletion).
-
#initialize(client:) ⇒ Messages
constructor
A new instance of Messages.
-
#list(thread_id:, parameters: {}) ⇒ Object
List messages in a thread.
-
#modify(thread_id:, id:, parameters: {}) ⇒ Object
Modify a message.
-
#retrieve(thread_id:, id:) ⇒ Object
Retrieve a specific message.
Constructor Details
#initialize(client:) ⇒ Messages
Returns a new instance of Messages.
3 4 5 6 |
# File 'lib/gemini/messages.rb', line 3 def initialize(client:) @client = client = {} # Store messages by thread ID end |
Instance Method Details
#create(thread_id:, parameters: {}) ⇒ Object
Create a new message
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gemini/messages.rb', line 33 def create(thread_id:, parameters: {}) # Check if thread exists (raise exception if not) validate_thread_exists(thread_id) = SecureRandom.uuid created_at = Time.now.to_i # Build message data from parameters = { "id" => , "object" => "thread.message", "created_at" => created_at, "thread_id" => thread_id, "role" => parameters[:role] || "user", "content" => format_content(parameters[:content]) } # Add message to thread (thread_id, ) end |
#delete(thread_id:, id:) ⇒ Object
Delete a message (logical deletion)
67 68 69 70 71 72 73 74 |
# File 'lib/gemini/messages.rb', line 67 def delete(thread_id:, id:) = retrieve(thread_id: thread_id, id: id) # Set logical deletion flag ["deleted"] = true { "id" => id, "object" => "thread.message.deleted", "deleted" => true } end |
#list(thread_id:, parameters: {}) ⇒ Object
List messages in a thread
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gemini/messages.rb', line 9 def list(thread_id:, parameters: {}) # Internal implementation: Get messages for the thread from message store = (thread_id) # OpenAI-like response format { "object" => "list", "data" => , "first_id" => .first&.dig("id"), "last_id" => .last&.dig("id"), "has_more" => false } end |
#modify(thread_id:, id:, parameters: {}) ⇒ Object
Modify a message
57 58 59 60 61 62 63 64 |
# File 'lib/gemini/messages.rb', line 57 def modify(thread_id:, id:, parameters: {}) = retrieve(thread_id: thread_id, id: id) # Apply modifiable parameters ["metadata"] = parameters[:metadata] if parameters[:metadata] end |
#retrieve(thread_id:, id:) ⇒ Object
Retrieve a specific message
24 25 26 27 28 29 30 |
# File 'lib/gemini/messages.rb', line 24 def retrieve(thread_id:, id:) = (thread_id) = .find { |m| m["id"] == id } raise Error.new("Message not found", "message_not_found") unless end |