Module: Geminize::RequestBuilder
- Defined in:
- lib/geminize/request_builder.rb
Overview
Utility module for building requests to the Gemini API
Class Method Summary collapse
-
.build_chat_request(chat_request, message_history = []) ⇒ Hash
Build a chat request for the Gemini API.
-
.build_embedding_endpoint(model_name) ⇒ String
Build the endpoint for embedding generation.
-
.build_get_model_endpoint(model_name) ⇒ String
Build a specific model endpoint for the get model info API.
-
.build_model_endpoint(model_name, action) ⇒ String
Build a complete API endpoint path for a model.
-
.build_models_list_params(page_size = nil, page_token = nil) ⇒ Hash
Build a models list request parameters.
-
.build_streaming_endpoint(model_name) ⇒ String
Build the streaming text generation endpoint for a specific model.
-
.build_text_generation_endpoint(model_name) ⇒ String
Build the text generation endpoint for a specific model.
-
.build_text_generation_request(content_request) ⇒ Hash
Build a text generation request for the Gemini API.
Class Method Details
.build_chat_request(chat_request, message_history = []) ⇒ Hash
Build a chat request for the Gemini API
24 25 26 27 28 29 30 31 32 |
# File 'lib/geminize/request_builder.rb', line 24 def build_chat_request(chat_request, = []) model_name = chat_request.model_name Validators.validate_not_empty!(model_name, "Model name") { model: model_name, **chat_request.to_hash() } end |
.build_embedding_endpoint(model_name) ⇒ String
Build the endpoint for embedding generation
81 82 83 |
# File 'lib/geminize/request_builder.rb', line 81 def (model_name) build_model_endpoint(model_name, "embedContent") end |
.build_get_model_endpoint(model_name) ⇒ String
Build a specific model endpoint for the get model info API
70 71 72 73 74 75 76 |
# File 'lib/geminize/request_builder.rb', line 70 def build_get_model_endpoint(model_name) # Handle both formats: "models/gemini-2.0-flash" or just "gemini-2.0-flash" unless model_name.start_with?("models/") model_name = "models/#{model_name}" end model_name end |
.build_model_endpoint(model_name, action) ⇒ String
Build a complete API endpoint path for a model
38 39 40 |
# File 'lib/geminize/request_builder.rb', line 38 def build_model_endpoint(model_name, action) "models/#{model_name}:#{action}" end |
.build_models_list_params(page_size = nil, page_token = nil) ⇒ Hash
Build a models list request parameters
60 61 62 63 64 65 |
# File 'lib/geminize/request_builder.rb', line 60 def build_models_list_params(page_size = nil, page_token = nil) params = {} params[:pageSize] = page_size if page_size params[:pageToken] = page_token if page_token params end |
.build_streaming_endpoint(model_name) ⇒ String
Build the streaming text generation endpoint for a specific model
52 53 54 |
# File 'lib/geminize/request_builder.rb', line 52 def build_streaming_endpoint(model_name) build_model_endpoint(model_name, "streamGenerateContent") end |
.build_text_generation_endpoint(model_name) ⇒ String
Build the text generation endpoint for a specific model
45 46 47 |
# File 'lib/geminize/request_builder.rb', line 45 def build_text_generation_endpoint(model_name) build_model_endpoint(model_name, "generateContent") end |
.build_text_generation_request(content_request) ⇒ Hash
Build a text generation request for the Gemini API
10 11 12 13 14 15 16 17 18 |
# File 'lib/geminize/request_builder.rb', line 10 def build_text_generation_request(content_request) model_name = content_request.model_name Validators.validate_not_empty!(model_name, "Model name") { model: model_name, **content_request.to_hash } end |