Method: Intelligence::Google::ChatRequestMethods#chat_request_uri

Defined in:
lib/intelligence/adapters/google/chat_request_methods.rb

#chat_request_uri(options) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/intelligence/adapters/google/chat_request_methods.rb', line 29

def chat_request_uri( options )
  options = merge_options( @options, build_options( options ) )

  key = options[ :key ] 
  gc = options[ :generationConfig ] || {}
  model = gc[ :model ]
  stream = gc.key?( :stream ) ? gc[ :stream ] : false 

  raise ArgumentError.new( "A Google API key is required to build a Google chat request." ) \
    if key.nil?
  raise ArgumentError.new( "A Google model is required to build a Google chat request." ) \
    if model.nil?
  
  uri = URI( GENERATIVE_LANGUAGE_URI )
  path = File.join( uri.path, model )
  path += stream ? ':streamGenerateContent' : ':generateContent'
  uri.path = path
  query = { key: key }
  query[ :alt ] = 'sse' if stream
  uri.query = URI.encode_www_form( query )

  uri.to_s
end