Class: Ask::Providers::DeepSeek
- 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
- .configuration_options ⇒ Object
- .configuration_requirements ⇒ Object
- .configured?(config) ⇒ Boolean
- .slug ⇒ Object
Instance Method Summary collapse
- #api_base ⇒ Object
-
#format_messages(messages) ⇒ Object
DeepSeek requires reasoning_content in every assistant message that includes tool_calls.
- #headers ⇒ Object
Methods inherited from OpenAI
assume_models_exist?, capabilities, #chat, #embed, #initialize, #list_models, #parse_error
Methods included from LLM::SSEBuffer
#each_sse_event, #init_sse_buffer
Constructor Details
This class inherits a constructor from Ask::Providers::OpenAI
Class Method Details
.configuration_options ⇒ Object
37 |
# File 'lib/ask/provider/deepseek.rb', line 37 def ; %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 |
.configured?(config) ⇒ Boolean
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 |
#format_messages(messages) ⇒ Object
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 () super.map do |fm| if fm[:role] == "assistant" && fm[:tool_calls] fm[:reasoning_content] = fm[:reasoning_content] || "" end fm end end |
#headers ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ask/provider/deepseek.rb', line 17 def headers key = @config.api_key || ENV["DEEPSEEK_API_KEY"] h = { "Content-Type" => "application/json" } h["Authorization"] = "Bearer #{key}" if key h end |