Class: Ask::Providers::DeepSeek
- Inherits:
-
OpenAI
- Object
- Ask::Provider
- OpenAI
- Ask::Providers::DeepSeek
show all
- Defined in:
- lib/ask/provider/deepseek.rb
Overview
DeepSeek API — an OpenAI-compatible provider at api.deepseek.com. Supports DeepSeek V2, V3, V4 Chat, R1 reasoning, and all DeepSeek models via the OpenAI-compatible endpoint.
Configuration via environment:
DEEPSEEK_API_KEY — required, your DeepSeek API key
DEEPSEEK_API_BASE — optional, base URL (default: https://api.deepseek.com)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from OpenAI
assume_models_exist?, capabilities, #chat, #embed, #initialize, #list_models, #parse_error
Class Method Details
.configuration_options ⇒ Object
37
|
# File 'lib/ask/provider/deepseek.rb', line 37
def configuration_options; %i[api_key base_url]; end
|
.configuration_requirements ⇒ Object
38
|
# File 'lib/ask/provider/deepseek.rb', line 38
def configuration_requirements; %i[api_key]; end
|
39
40
41
42
43
|
# File 'lib/ask/provider/deepseek.rb', line 39
def configured?(config)
key = config.respond_to?(:api_key) ? config.api_key : nil
key ||= ENV["DEEPSEEK_API_KEY"]
key.to_s.length > 0
end
|
.slug ⇒ Object
36
|
# File 'lib/ask/provider/deepseek.rb', line 36
def slug; "deepseek"; end
|
Instance Method Details
#api_base ⇒ Object
13
14
15
|
# File 'lib/ask/provider/deepseek.rb', line 13
def api_base
@config.base_url || ENV["DEEPSEEK_API_BASE"] || "https://api.deepseek.com"
end
|
DeepSeek requires reasoning_content in every assistant message that includes tool_calls. Override format_messages to inject it.
26
27
28
29
30
31
32
33
|
# File 'lib/ask/provider/deepseek.rb', line 26
def format_messages(messages)
super.map do |fm|
if fm[:role] == "assistant" && fm[:tool_calls]
fm[:reasoning_content] = fm[:reasoning_content] || ""
end
fm
end
end
|
17
18
19
20
21
22
|
# File 'lib/ask/provider/deepseek.rb', line 17
def
key = @config.api_key || ENV["DEEPSEEK_API_KEY"]
h = { "Content-Type" => "application/json" }
h["Authorization"] = "Bearer #{key}" if key
h
end
|