ruby_llm 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,12 +14,13 @@ module RubyLLM
14
14
  def format_tool_call(msg)
15
15
  tool_call = msg.tool_calls.values.first
16
16
 
17
+ content = []
18
+ content << Media.format_text(msg.content) unless msg.content.nil? || msg.content.empty?
19
+ content << format_tool_use_block(tool_call)
20
+
17
21
  {
18
22
  role: 'assistant',
19
- content: [
20
- Media.format_text(msg.content),
21
- format_tool_use_block(tool_call)
22
- ]
23
+ content:
23
24
  }
24
25
  end
25
26
 
@@ -30,7 +30,7 @@ module RubyLLM
30
30
  end
31
31
 
32
32
  def valid_lengths?(total_length, headers_length)
33
- validate_length_constraints(total_length, headers_length)
33
+ valid_length_constraints?(total_length, headers_length)
34
34
  end
35
35
 
36
36
  def calculate_positions(offset, total_length, headers_length)
@@ -67,7 +67,7 @@ module RubyLLM
67
67
 
68
68
  def valid_prelude_at_position?(chunk, pos)
69
69
  lengths = extract_potential_lengths(chunk, pos)
70
- validate_length_constraints(*lengths)
70
+ valid_length_constraints?(*lengths)
71
71
  end
72
72
 
73
73
  def extract_potential_lengths(chunk, pos)
@@ -77,7 +77,7 @@ module RubyLLM
77
77
  ]
78
78
  end
79
79
 
80
- def validate_length_constraints(total_length, headers_length)
80
+ def valid_length_constraints?(total_length, headers_length)
81
81
  return false if total_length.nil? || headers_length.nil?
82
82
  return false if total_length <= 0 || total_length > 1_000_000
83
83
  return false if headers_length <= 0 || headers_length >= total_length
@@ -215,10 +215,13 @@ module RubyLLM
215
215
  end
216
216
  end
217
217
 
218
- def normalize_temperature(temperature, model_id)
218
+ def self.normalize_temperature(temperature, model_id)
219
219
  if model_id.match?(/^o\d/)
220
220
  RubyLLM.logger.debug "Model #{model_id} requires temperature=1.0, ignoring provided value"
221
221
  1.0
222
+ elsif model_id.match?(/-search/)
223
+ RubyLLM.logger.debug "Model #{model_id} does not accept temperature parameter, removing"
224
+ nil
222
225
  else
223
226
  temperature
224
227
  end
@@ -12,18 +12,22 @@ module RubyLLM
12
12
  module_function
13
13
 
14
14
  def render_payload(messages, tools:, temperature:, model:, stream: false)
15
- {
15
+ payload = {
16
16
  model: model,
17
17
  messages: format_messages(messages),
18
- temperature: temperature,
19
18
  stream: stream
20
- }.tap do |payload|
21
- if tools.any?
22
- payload[:tools] = tools.map { |_, tool| tool_for(tool) }
23
- payload[:tool_choice] = 'auto'
24
- end
25
- payload[:stream_options] = { include_usage: true } if stream
19
+ }
20
+
21
+ # Only include temperature if it's not nil (some models don't accept it)
22
+ payload[:temperature] = temperature unless temperature.nil?
23
+
24
+ if tools.any?
25
+ payload[:tools] = tools.map { |_, tool| tool_for(tool) }
26
+ payload[:tool_choice] = 'auto'
26
27
  end
28
+
29
+ payload[:stream_options] = { include_usage: true } if stream
30
+ payload
27
31
  end
28
32
 
29
33
  def parse_completion_response(response)
data/lib/ruby_llm/tool.rb CHANGED
@@ -49,14 +49,14 @@ module RubyLLM
49
49
  end
50
50
 
51
51
  def name
52
- self.class.name
53
- .unicode_normalize(:nfkd)
54
- .encode('ASCII', replace: '')
55
- .gsub(/[^a-zA-Z0-9_-]/, '-')
56
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
57
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
58
- .downcase
59
- .delete_suffix('_tool')
52
+ klass_name = self.class.name
53
+ normalized = klass_name.to_s.dup.force_encoding('UTF-8').unicode_normalize(:nfkd)
54
+ normalized.encode('ASCII', replace: '')
55
+ .gsub(/[^a-zA-Z0-9_-]/, '-')
56
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
57
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
58
+ .downcase
59
+ .delete_suffix('_tool')
60
60
  end
61
61
 
62
62
  def description
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLLM
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.1'
5
5
  end
data/lib/ruby_llm.rb CHANGED
@@ -67,7 +67,7 @@ module RubyLLM
67
67
  end
68
68
 
69
69
  def logger
70
- @logger ||= Logger.new(
70
+ @logger ||= config.logger || Logger.new(
71
71
  config.log_file,
72
72
  progname: 'RubyLLM',
73
73
  level: config.log_level
@@ -30,7 +30,7 @@ def generate_models_markdown
30
30
  # Available Models
31
31
  {: .no_toc }
32
32
 
33
- This guide lists all models available in RubyLLM, automatically generated from the current model registry.
33
+ This guide lists all models available in RubyLLM, automatically generated from the current [model registry](https://github.com/crmne/ruby_llm/blob/main/lib/ruby_llm/models.json).
34
34
  {: .fs-6 .fw-300 }
35
35
 
36
36
  ## Table of contents
@@ -41,15 +41,21 @@ def generate_models_markdown
41
41
 
42
42
  ---
43
43
 
44
- ## Contributing
44
+ ## How Model Data Works
45
45
 
46
- The model list is automatically generated from the model registry. To add or update models:
46
+ RubyLLM's model registry combines data from multiple sources:
47
47
 
48
- 1. Edit the appropriate `capabilities.rb` file in `lib/ruby_llm/providers/<provider>/`
49
- 2. Run `rake models:update` to refresh the model registry
50
- 3. Submit a pull request with the updated `models.json`
48
+ - **OpenAI, Anthropic, DeepSeek, Gemini**: Data from [Parsera](https://api.parsera.org/v1/llm-specs)
49
+ - **OpenRouter**: Direct from OpenRouter's API
50
+ - **Other providers**: Defined in `capabilities.rb` files
51
51
 
52
- See [Contributing Guide](/CONTRIBUTING.md) for more details.
52
+ ## Contributing Model Updates
53
+
54
+ **For major providers** (OpenAI, Anthropic, DeepSeek, Gemini): File issues with [Parsera](https://github.com/parsera-labs/api-llm-specs/issues) for public model data corrections.
55
+
56
+ **For other providers**: Edit `lib/ruby_llm/providers/<provider>/capabilities.rb` then run `rake models:update`.
57
+
58
+ See the [Contributing Guide](https://github.com/crmne/ruby_llm/blob/main/CONTRIBUTING.md) for details.
53
59
 
54
60
  ## Last Updated
55
61
  {: .d-inline-block }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino