Class: RubyLLM::Providers::VertexAI::Gemini

Inherits:
RubyLLM::Protocols::Gemini show all
Includes:
Embeddings, Models, Videos
Defined in:
lib/ruby_llm/providers/vertexai/gemini.rb,
lib/ruby_llm/providers/vertexai/gemini/batches.rb

Overview

The Gemini protocol over Vertex AI endpoints.

Defined Under Namespace

Modules: Batches

Constant Summary collapse

SERVER_TOOL_ALIASES =
Protocols::Gemini::SERVER_TOOL_ALIASES.merge(
  file_search: lambda { |options|
    { tool: { retrieval: { vertexAiSearch: Support::Utils.deep_symbolize_keys(options) } } }
  }
).freeze

Constants included from Models

Models::CATALOG_LOCATIONS, Models::KNOWN_GOOGLE_MODELS, Models::PUBLISHERS

Instance Attribute Summary

Attributes inherited from RubyLLM::Protocol

#config, #connection, #model, #provider

Instance Method Summary collapse

Methods included from Videos

#download_video, #refresh_video_job, #video_job_url, #video_url

Methods included from Models

#list_models, models_dev_alias

Methods included from Embeddings

embedding_input_tokens, embedding_url, parse_embedding_response, render_embedding_payload, supports_embedding_media?

Methods inherited from RubyLLM::Protocols::Gemini

#attachment_filename, #build_file_attachment, #build_inline_attachment, #build_response_content

Methods inherited from RubyLLM::Protocol

abstract, #animate_later, #apply_compaction, #apply_compaction_headers, #apply_end_user, #cache_content, #compact, #complete, #count_tokens, #delete_cache, #embed, #extend_cache, #find_cache, #initialize, #list_models, #moderate, #ocr, #paint, #parse_error, #parse_image_responses, #post_image, #post_video, #preprocess_message, #raise_transcription_streaming_unsupported, #refresh_video_job, #render, #render_embedding, #render_transcription_options, #render_video_extension_payload, #rerank, #speak, #stream_speech, #stream_speech_response, #stream_transcription, #supports_embedding_media?, #tokenize, #tool_approval_response, #transcribe, #video_extension_attachment, #video_extension_url, #video_request_url

Methods included from RubyLLM::Protocol::BinaryStreaming

#stream_binary

Methods included from RubyLLM::Protocol::Streaming

build_on_data_handler, build_stream_error_response, error_chunk?, failed_http_status, faraday_1?, handle_data, handle_error_chunk, handle_error_event, handle_failed_response, handle_json_error_chunk, handle_sse, handle_stream, json_error_payload?, parse_error_from_json, parse_streaming_error, process_stream_chunk, raise_stream_error, stream_events, stream_response, stream_state

Constructor Details

This class inherits a constructor from RubyLLM::Protocol

Instance Method Details

#cache_model_name(model_id) ⇒ Object



47
48
49
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 47

def cache_model_name(model_id)
  @provider.model_path(model_id)
end

#cache_name(name) ⇒ Object



42
43
44
45
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 42

def cache_name(name)
  name = name.name if name.is_a?(CachedContent)
  name.to_s.include?('/') ? name.to_s : "#{caches_url}/#{name}"
end

#caches_urlObject



38
39
40
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 38

def caches_url
  "#{@provider.location_path}/cachedContents"
end

#completion_urlObject



22
23
24
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 22

def completion_url
  "#{@provider.model_path(@model.id)}:generateContent"
end

#count_tokens_urlObject



30
31
32
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 30

def count_tokens_url
  "#{@provider.model_path(@model.id)}:countTokens"
end

#images_url(with: nil, mask: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



51
52
53
54
55
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 51

def images_url(with: nil, mask: nil) # rubocop:disable Lint/UnusedMethodArgument
  id = model_id(@model)

  "#{@provider.model_path(id)}:#{image_endpoint_action(id)}"
end

#render_count_tokens_payload(messages, **options) ⇒ Object



34
35
36
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 34

def render_count_tokens_payload(messages, **options)
  count_tokens_request(messages, **options)
end

#server_tool_aliasesObject



18
19
20
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 18

def server_tool_aliases
  SERVER_TOOL_ALIASES
end

#speech_url(model:) ⇒ Object



57
58
59
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 57

def speech_url(model:)
  "#{@provider.model_path(model)}:generateContent"
end

#stream_urlObject



26
27
28
# File 'lib/ruby_llm/providers/vertexai/gemini.rb', line 26

def stream_url
  "#{@provider.model_path(@model.id)}:streamGenerateContent?alt=sse"
end