Class: Geminize::Models::ChatRequest
- Inherits:
-
Object
- Object
- Geminize::Models::ChatRequest
- Defined in:
- lib/geminize/models/chat_request.rb
Overview
Represents a chat request to the Gemini API
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
The user's message content.
-
#max_tokens ⇒ Integer
Maximum tokens to generate.
-
#model_name ⇒ String
readonly
The model name to use.
-
#stop_sequences ⇒ Array<String>
Stop sequences to end generation.
-
#system_instruction ⇒ String?
System instruction to guide model behavior.
-
#temperature ⇒ Float
Temperature (controls randomness).
-
#timestamp ⇒ Time
readonly
When the message was created.
-
#top_k ⇒ Integer
Top-k value for sampling.
-
#top_p ⇒ Float
Top-p value for nucleus sampling.
-
#user_id ⇒ String?
readonly
Optional user identifier.
Instance Method Summary collapse
-
#initialize(content, model_name = nil, user_id = nil, params = {}) ⇒ ChatRequest
constructor
Initialize a new chat request.
-
#to_h(history = []) ⇒ Hash
Alias for to_hash for consistency with Ruby conventions.
-
#to_hash(history = []) ⇒ Hash
Convert the request to a hash suitable for the API.
-
#to_message_hash ⇒ Hash
Convert the request to a hash for forming a single message.
-
#validate! ⇒ Boolean
Validate the request parameters.
Constructor Details
#initialize(content, model_name = nil, user_id = nil, params = {}) ⇒ ChatRequest
Initialize a new chat request
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/geminize/models/chat_request.rb', line 48 def initialize(content, model_name = nil, user_id = nil, params = {}) @content = content @model_name = model_name || Geminize.configuration.default_model @user_id = user_id = Time.now @temperature = params[:temperature] @max_tokens = params[:max_tokens] @top_p = params[:top_p] @top_k = params[:top_k] @stop_sequences = params[:stop_sequences] @system_instruction = params[:system_instruction] validate! end |
Instance Attribute Details
#content ⇒ String (readonly)
8 9 10 |
# File 'lib/geminize/models/chat_request.rb', line 8 def content @content end |
#max_tokens ⇒ Integer
23 24 25 |
# File 'lib/geminize/models/chat_request.rb', line 23 def max_tokens @max_tokens end |
#model_name ⇒ String (readonly)
14 15 16 |
# File 'lib/geminize/models/chat_request.rb', line 14 def model_name @model_name end |
#stop_sequences ⇒ Array<String>
32 33 34 |
# File 'lib/geminize/models/chat_request.rb', line 32 def stop_sequences @stop_sequences end |
#system_instruction ⇒ String?
35 36 37 |
# File 'lib/geminize/models/chat_request.rb', line 35 def system_instruction @system_instruction end |
#temperature ⇒ Float
20 21 22 |
# File 'lib/geminize/models/chat_request.rb', line 20 def temperature @temperature end |
#timestamp ⇒ Time (readonly)
17 18 19 |
# File 'lib/geminize/models/chat_request.rb', line 17 def end |
#top_k ⇒ Integer
29 30 31 |
# File 'lib/geminize/models/chat_request.rb', line 29 def top_k @top_k end |
#top_p ⇒ Float
26 27 28 |
# File 'lib/geminize/models/chat_request.rb', line 26 def top_p @top_p end |
#user_id ⇒ String? (readonly)
11 12 13 |
# File 'lib/geminize/models/chat_request.rb', line 11 def user_id @user_id end |
Instance Method Details
#to_h(history = []) ⇒ Hash
Alias for to_hash for consistency with Ruby conventions
116 117 118 |
# File 'lib/geminize/models/chat_request.rb', line 116 def to_h(history = []) to_hash(history) end |
#to_hash(history = []) ⇒ Hash
Convert the request to a hash suitable for the API
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/geminize/models/chat_request.rb', line 93 def to_hash(history = []) request = { contents: history + [], generationConfig: generation_config }.compact # Add system_instruction if provided if @system_instruction request[:systemInstruction] = { parts: [ { text: @system_instruction } ] } end request end |
#to_message_hash ⇒ Hash
Convert the request to a hash for forming a single message
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/geminize/models/chat_request.rb', line 79 def { role: "user", parts: [ { text: @content } ] } end |
#validate! ⇒ Boolean
Validate the request parameters
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/geminize/models/chat_request.rb', line 66 def validate! validate_content! validate_temperature! validate_max_tokens! validate_top_p! validate_top_k! validate_stop_sequences! validate_system_instruction! true end |