Class: LastLLM::Providers::Deepseek
- Inherits:
-
LastLLM::Provider
- Object
- LastLLM::Provider
- LastLLM::Providers::Deepseek
- Defined in:
- lib/last_llm/providers/deepseek.rb
Overview
Deepseek provider implementation
Constant Summary collapse
- BASE_ENDPOINT =
API Configuration
'https://api.deepseek.com'- DEFAULT_MODEL =
'deepseek-chat'- DEFAULT_TEMPERATURE =
LLM Default Parameters
0.7- DEFAULT_TOP_P =
0.8- DEFAULT_TEMPERATURE_OBJECT =
0.2- SUCCESS_STATUS =
Response Configuration
200- UNAUTHORIZED_STATUS =
Error Status Codes
401- BAD_REQUEST_STATUS =
400
Instance Attribute Summary
Attributes inherited from LastLLM::Provider
Class Method Summary collapse
-
.execute_tool(tool, response) ⇒ Hash?
Execute a tool from a Deepseek response.
-
.format_tool(tool) ⇒ Hash
Format a tool for Deepseek function calling.
Instance Method Summary collapse
- #generate_object(prompt, schema, options = {}) ⇒ Object
- #generate_text(prompt, options = {}) ⇒ Object
-
#initialize(config) ⇒ Deepseek
constructor
A new instance of Deepseek.
Methods inherited from LastLLM::Provider
Constructor Details
#initialize(config) ⇒ Deepseek
Returns a new instance of Deepseek.
25 26 27 28 |
# File 'lib/last_llm/providers/deepseek.rb', line 25 def initialize(config) super(Constants::DEEPSEEK, config) @conn = connection(config[:base_url] || BASE_ENDPOINT) end |
Class Method Details
.execute_tool(tool, response) ⇒ Hash?
Execute a tool from a Deepseek response
68 69 70 71 72 73 74 |
# File 'lib/last_llm/providers/deepseek.rb', line 68 def self.execute_tool(tool, response) tool_call = response.dig(:choices, 0, :message, :tool_calls)&.first return nil unless tool_call && tool_call[:function][:name] == tool.name arguments = JSON.parse(tool_call[:function][:arguments], symbolize_names: true) tool.call(arguments) end |
.format_tool(tool) ⇒ Hash
Format a tool for Deepseek function calling
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/last_llm/providers/deepseek.rb', line 53 def self.format_tool(tool) { type: 'function', function: { name: tool.name, description: tool.description, parameters: tool.parameters } } end |
Instance Method Details
#generate_object(prompt, schema, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/last_llm/providers/deepseek.rb', line 36 def generate_object(prompt, schema, = {}) system_prompt = 'You are a helpful assistant that responds with valid JSON.' formatted_prompt = LastLLM::StructuredOutput.format_prompt(prompt, schema) = .dup [:system_prompt] = system_prompt [:temperature] ||= DEFAULT_TEMPERATURE_OBJECT make_request(formatted_prompt, ) do |result| content = result.dig(:choices, 0, :message, :content) parse_json_response(content) end end |
#generate_text(prompt, options = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/last_llm/providers/deepseek.rb', line 30 def generate_text(prompt, = {}) make_request(prompt, ) do |result| result.dig(:choices, 0, :message, :content).to_s end end |