Class: OmniAI::DeepSeek::Client

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

Overview

An DeepSeek client implementation. Usage:

w/ ‘api_key“:

client = OmniAI::DeepSeek::Client.new(api_key: '...')

w/ ENV:

ENV['DEEPSEEK_API_KEY'] = '...'
client = OmniAI::DeepSeek::Client.new

w/ config:

OmniAI::DeepSeek.configure do |config|
  config.api_key = '...'
end

client = OmniAI::DeepSeek::Client.new

Instance Method Summary collapse

Constructor Details

#initialize(api_key: OmniAI::DeepSeek.config.api_key, host: OmniAI::DeepSeek.config.host, logger: OmniAI::DeepSeek.config.logger, timeout: OmniAI::DeepSeek.config.timeout) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_key (String, nil) (defaults to: OmniAI::DeepSeek.config.api_key)

    optional - defaults to ‘OmniAI::DeepSeek.config.api_key`

  • host (String) (defaults to: OmniAI::DeepSeek.config.host)

    optional - defaults to ‘OmniAI::DeepSeek.config.host`

  • logger (Logger, nil) (defaults to: OmniAI::DeepSeek.config.logger)

    optional - defaults to ‘OmniAI::DeepSeek.config.logger`

  • timeout (Integer, nil) (defaults to: OmniAI::DeepSeek.config.timeout)

    optional - defaults to ‘OmniAI::DeepSeek.config.timeout`



27
28
29
30
31
32
33
34
# File 'lib/omniai/deepseek/client.rb', line 27

def initialize(
  api_key: OmniAI::DeepSeek.config.api_key,
  host: OmniAI::DeepSeek.config.host,
  logger: OmniAI::DeepSeek.config.logger,
  timeout: OmniAI::DeepSeek.config.timeout
)
  super
end

Instance Method Details

#chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Completion

Parameters:

  • messages (String) (defaults to: nil)

    optional

  • model (String) (defaults to: Chat::DEFAULT_MODEL)

    optional

  • format (Symbol) (defaults to: nil)

    optional :text or :json

  • temperature (Float, nil) (defaults to: nil)

    optional

  • stream (Proc, nil) (defaults to: nil)

    optional

  • tools (Array<OmniAI::Tool>, nil) (defaults to: nil)

    optional

Yields:

  • (prompt)

Yield Parameters:

  • prompt (OmniAI::Chat::Prompt)

Returns:

  • (OmniAI::Chat::Completion)

Raises:

  • (OmniAI::Error)


58
59
60
# File 'lib/omniai/deepseek/client.rb', line 58

def chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil, &)
  Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self, &)
end

#connectionHTTP::Client

Returns:

  • (HTTP::Client)


37
38
39
40
41
42
43
# File 'lib/omniai/deepseek/client.rb', line 37

def connection
  @connection ||= begin
    http = super
    http = http.auth("Bearer #{@api_key}") if @api_key
    http
  end
end