Class: LastLLM::Providers::GoogleGemini
- Inherits:
-
LastLLM::Provider
- Object
- LastLLM::Provider
- LastLLM::Providers::GoogleGemini
- Defined in:
- lib/last_llm/providers/google_gemini.rb
Overview
Google Gemini provider implementation
Constant Summary collapse
- BASE_ENDPOINT =
API Configuration
'https://generativelanguage.googleapis.com'- DEFAULT_MODEL =
'gemini-1.5-flash'- DEFAULT_TEMPERATURE =
LLM Default Parameters
0.3- DEFAULT_TOP_P =
0.95- DEFAULT_TOP_K =
40- DEFAULT_MAX_TOKENS =
1024- JSON_MIME_TYPE =
Response Configuration
'application/json'- SUCCESS_STATUS =
200- UNAUTHORIZED_STATUS =
Error Status Codes
401- BAD_REQUEST_STATUS =
400- UNAUTHENTICATED_STATUS =
'UNAUTHENTICATED'
Instance Attribute Summary
Attributes inherited from LastLLM::Provider
Instance Method Summary collapse
- #generate_object(prompt, schema, options = {}) ⇒ Object
- #generate_text(prompt, options = {}) ⇒ Object
-
#initialize(config) ⇒ GoogleGemini
constructor
A new instance of GoogleGemini.
Methods inherited from LastLLM::Provider
#handle_request_error, #parse_response
Constructor Details
#initialize(config) ⇒ GoogleGemini
Returns a new instance of GoogleGemini.
28 29 30 31 32 33 34 |
# File 'lib/last_llm/providers/google_gemini.rb', line 28 def initialize(config) super(Constants::GOOGLE_GEMINI, config) @api_key = config[:api_key] @conn = connection(config[:base_url] || BASE_ENDPOINT) # Use plain format for initialization log to match test expectations logger.debug("Initialized Google Gemini provider with endpoint: #{config[:base_url] || BASE_ENDPOINT}") end |
Instance Method Details
#generate_object(prompt, schema, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/last_llm/providers/google_gemini.rb', line 48 def generate_object(prompt, schema, = {}) model = get_model(, DEFAULT_MODEL) logger.info("#{@name}: Generating object with model: #{model}") logger.debug("#{@name}: Object prompt: #{format_prompt_for_logging(prompt)}") = .merge(response_mime_type: JSON_MIME_TYPE, response_schema: schema) make_request(prompt, ) do |response| text_response = extract_text_content(response) logger.debug("Raw JSON response: #{text_response}") parse_json_response(text_response) end end |
#generate_text(prompt, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/last_llm/providers/google_gemini.rb', line 36 def generate_text(prompt, = {}) model = get_model(, DEFAULT_MODEL) logger.info("#{@name}: Generating text with model: #{model}") logger.debug("#{@name}: Text prompt: #{format_prompt_for_logging(prompt)}") make_request(prompt, ) do |response| result = extract_text_content(response) logger.debug("Generated response of #{result.length} characters") result end end |