Class: GigaChat::Client

Inherits:
Object
  • Object
show all
Includes:
HTTP
Defined in:
lib/gigachat/client.rb

Constant Summary collapse

CONFIG_KEYS =
%i[
  api_type
  api_version
  client_base64
  log_errors
  uri_base
  uri_auth
  request_timeout
  extra_headers
].freeze

Instance Method Summary collapse

Methods included from HTTP

#delete, #get, #json_post, #multipart_post, #post

Methods included from HTTPHeaders

#add_headers

Constructor Details

#initialize(config = {}, &faraday_middleware) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gigachat/client.rb', line 17

def initialize(config = {}, &faraday_middleware)
  CONFIG_KEYS.each do |key|
    # Set instance variables like client_id. Fall back to global config
    # if not present.
    instance_variable_set(
      "@#{key}",
      config[key].nil? ? GigaChat.configuration.send(key) : config[key]
    )
  end
  @faraday_middleware = faraday_middleware
end

Instance Method Details

#chat(parameters: {}) ⇒ Object



33
34
35
# File 'lib/gigachat/client.rb', line 33

def chat(parameters: {})
  json_post(path: "/chat/completions", parameters: parameters)
end

#embeddings(parameters: {}) ⇒ Object



37
38
39
# File 'lib/gigachat/client.rb', line 37

def embeddings(parameters: {})
  json_post(path: "/embeddings", parameters: parameters)
end

#modelsObject



29
30
31
# File 'lib/gigachat/client.rb', line 29

def models
  @models ||= GigaChat::Models.new(client: self)
end