Class: Deepseek::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/deepseek/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, **options) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/deepseek/client.rb', line 9

def initialize(api_key: nil, **options)
  @config = Configuration.new
  @config.api_key = api_key if api_key
  options.each do |key, value|
    @config.send("#{key}=", value) if @config.respond_to?("#{key}=")
  end
  @config.validate! # This will raise ConfigurationError if no API key is set
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/deepseek/client.rb', line 7

def config
  @config
end

Instance Method Details

#chat(messages:, model: 'deepseek-chat', **params) ⇒ Object



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

def chat(messages:, model: 'deepseek-chat', **params)
  post('/v1/chat/completions', {
    model: model,
    messages: messages,
    **params
  })
rescue Faraday::Error => e
  handle_error_response(e.response) if e.response
  raise e
end