ruby_llm 2.0.0.rc3 → 2.0.0

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rdoc_options +2 -2
  3. data/README.md +34 -23
  4. data/lib/generators/ruby_llm/generator_helpers.rb +4 -1
  5. data/lib/generators/ruby_llm/install/templates/create_chats_migration.rb.tt +1 -1
  6. data/lib/generators/ruby_llm/install/templates/create_messages_migration.rb.tt +1 -1
  7. data/lib/generators/ruby_llm/install/templates/create_ruby_llm_records_migration.rb.tt +5 -5
  8. data/lib/generators/ruby_llm/upgrade/online_copy_migration/data.rb +9 -0
  9. data/lib/generators/ruby_llm/upgrade/online_copy_migration.rb +5 -1
  10. data/lib/generators/ruby_llm/upgrade/templates/backfill_v2_data.rb.tt +6 -2
  11. data/lib/generators/ruby_llm/upgrade/templates/finish_v2_upgrade.rb.tt +8 -2
  12. data/lib/generators/ruby_llm/upgrade/templates/prepare_v2_upgrade.rb.tt +2 -2
  13. data/lib/generators/ruby_llm/upgrade/templates/ruby_llm_upgrade.rb.tt +1 -1
  14. data/lib/generators/ruby_llm/upgrade/templates/upgrade_initializer.rb.tt +1 -1
  15. data/lib/generators/ruby_llm/upgrade/upgrade_generator.rb +11 -0
  16. data/lib/generators/ruby_llm/upgrade/upgrade_migration.rb +2 -1
  17. data/lib/ruby_llm/active_record/attachment_helpers.rb +81 -3
  18. data/lib/ruby_llm/active_record/chat_methods.rb +11 -8
  19. data/lib/ruby_llm/agent.rb +17 -17
  20. data/lib/ruby_llm/batch.rb +2 -2
  21. data/lib/ruby_llm/chat.rb +17 -17
  22. data/lib/ruby_llm/embedding.rb +1 -1
  23. data/lib/ruby_llm/error.rb +1 -1
  24. data/lib/ruby_llm/image.rb +1 -1
  25. data/lib/ruby_llm/message.rb +15 -1
  26. data/lib/ruby_llm/models.json +1654 -1791
  27. data/lib/ruby_llm/moderation.rb +1 -1
  28. data/lib/ruby_llm/ocr.rb +1 -1
  29. data/lib/ruby_llm/protocol.rb +36 -13
  30. data/lib/ruby_llm/protocols/anthropic/chat.rb +1 -6
  31. data/lib/ruby_llm/protocols/chat_completions/chat.rb +2 -11
  32. data/lib/ruby_llm/protocols/converse/chat.rb +0 -1
  33. data/lib/ruby_llm/protocols/responses/chat.rb +0 -10
  34. data/lib/ruby_llm/protocols/vertexai/research.rb +8 -8
  35. data/lib/ruby_llm/provider.rb +4 -4
  36. data/lib/ruby_llm/providers/openrouter/chat.rb +5 -5
  37. data/lib/ruby_llm/rerank.rb +1 -1
  38. data/lib/ruby_llm/research_job.rb +4 -4
  39. data/lib/ruby_llm/server_tool_call.rb +2 -2
  40. data/lib/ruby_llm/speech.rb +1 -1
  41. data/lib/ruby_llm/tools/{server_tools.rb → provider_tools.rb} +7 -7
  42. data/lib/ruby_llm/transcription.rb +1 -1
  43. data/lib/ruby_llm/version.rb +1 -1
  44. data/lib/ruby_llm/video_job.rb +1 -1
  45. data/lib/ruby_llm.rb +2 -2
  46. metadata +7 -7
@@ -101,7 +101,7 @@ module RubyLLM
101
101
  chats = normalize_chats(records)
102
102
 
103
103
  provider = shared_provider(chats)
104
- payload = { provider: provider.slug, provider_class: provider.class.display_name, requests: chats.size }
104
+ payload = { provider: provider.slug, provider_class: provider.name, requests: chats.size }
105
105
  RubyLLM.instrument('batch.ruby_llm', payload, config: provider.config) do |event|
106
106
  requests = chats.each_with_index.map do |chat, index|
107
107
  { custom_id: index.to_s, model: chat.model.id, payload: chat.render }
@@ -120,7 +120,7 @@ module RubyLLM
120
120
  end
121
121
 
122
122
  provider = shared_provider(requests)
123
- payload = { provider: provider.slug, provider_class: provider.class.display_name, requests: requests.size }
123
+ payload = { provider: provider.slug, provider_class: provider.name, requests: requests.size }
124
124
  RubyLLM.instrument('batch.ruby_llm', payload, config: provider.config) do |event|
125
125
  lines = requests.each_with_index.map do |request, index|
126
126
  { custom_id: index.to_s, model: request.model.id, payload: request.render, text: request.text }
data/lib/ruby_llm/chat.rb CHANGED
@@ -42,9 +42,9 @@ module RubyLLM
42
42
  # The registered tools, as a Hash of tool name Symbols to Tool instances.
43
43
  attr_reader :tools
44
44
 
45
- # The server tools enabled with #with_server_tools, as an array of
45
+ # The provider tools enabled with #with_provider_tools, as an array of
46
46
  # normalized entry Hashes.
47
- attr_reader :server_tools
47
+ attr_reader :provider_tools
48
48
 
49
49
  # Extra request options set with #with_provider_options, expressed in
50
50
  # the provider's request vocabulary.
@@ -119,7 +119,7 @@ module RubyLLM
119
119
  @messages = []
120
120
  @usage_entries = []
121
121
  @tools = {}
122
- @server_tools = []
122
+ @provider_tools = []
123
123
  @tool_prefs = { choice: nil, calls: nil }
124
124
  @concurrency = normalize_tool_concurrency(@config.tool_concurrency)
125
125
  @provider_options = {}
@@ -354,10 +354,10 @@ module RubyLLM
354
354
  # no alias for yet work without a gem update. Entries add to any tools
355
355
  # enabled earlier; pass +nil+ to clear them all. Returns +self+.
356
356
  #
357
- # chat.with_server_tools(:web_search)
358
- # chat.with_server_tools(:web_search, :code_execution)
359
- # chat.with_server_tools(web_search: { allowed_domains: ["ruby-lang.org"] })
360
- # chat.with_server_tools({ type: "web_search_20260318", name: "web_search" })
357
+ # chat.with_provider_tools(:web_search)
358
+ # chat.with_provider_tools(:web_search, :code_execution)
359
+ # chat.with_provider_tools(web_search: { allowed_domains: ["ruby-lang.org"] })
360
+ # chat.with_provider_tools({ type: "web_search_20260318", name: "web_search" })
361
361
  #
362
362
  # The tool steps the model ran come back on
363
363
  # Message#server_tool_calls, citations from search tools on
@@ -365,14 +365,14 @@ module RubyLLM
365
365
  # <tt>message.tokens.server_tool_use</tt>.
366
366
  #
367
367
  # Raises UnsupportedServerToolError at request time when the provider
368
- # has no server-tool support or does not define a requested alias.
369
- def with_server_tools(*tools, **tools_with_options)
368
+ # has no provider-tool support or does not define a requested alias.
369
+ def with_provider_tools(*tools, **tools_with_options)
370
370
  if tools == [nil] && tools_with_options.empty?
371
- @server_tools = []
371
+ @provider_tools = []
372
372
  return self
373
373
  end
374
374
 
375
- @server_tools += RubyLLM::Tools::ServerTools.normalize(tools, tools_with_options)
375
+ @provider_tools += RubyLLM::Tools::ProviderTools.normalize(tools, tools_with_options)
376
376
  self
377
377
  end
378
378
 
@@ -742,7 +742,7 @@ module RubyLLM
742
742
  # chat.with_instructions("Be terse.").with_tools(Weather)
743
743
  # chat.count_tokens("What's the weather in Berlin?")
744
744
  #
745
- # Server tools, provider_options, compaction, and before_request hooks
745
+ # Provider tools, provider_options, compaction, and before_request hooks
746
746
  # are not included. Raises Error when the provider has no token counting
747
747
  # endpoint.
748
748
  def count_tokens(message = nil)
@@ -849,7 +849,7 @@ module RubyLLM
849
849
  @provider.render(
850
850
  preprocessed_messages,
851
851
  tools: @tools,
852
- server_tools: @server_tools,
852
+ provider_tools: @provider_tools,
853
853
  tool_prefs: @tool_prefs,
854
854
  temperature: @temperature,
855
855
  max_output_tokens: @max_output_tokens,
@@ -1003,13 +1003,13 @@ module RubyLLM
1003
1003
  {
1004
1004
  chat: self,
1005
1005
  provider: @provider.slug,
1006
- provider_class: @provider.class.display_name,
1006
+ provider_class: @provider.name,
1007
1007
  model: @model.id,
1008
1008
  model_info: @model,
1009
1009
  input_messages: messages.dup,
1010
1010
  message_count: messages.size,
1011
1011
  tools: tools.keys,
1012
- server_tools: server_tools,
1012
+ provider_tools: provider_tools,
1013
1013
  tool_choice: tool_prefs[:choice],
1014
1014
  tool_call_limit: tool_prefs[:calls],
1015
1015
  temperature: @temperature,
@@ -1147,7 +1147,7 @@ module RubyLLM
1147
1147
  @provider.complete(
1148
1148
  preprocessed_messages,
1149
1149
  tools: @tools,
1150
- server_tools: @server_tools,
1150
+ provider_tools: @provider_tools,
1151
1151
  tool_prefs: @tool_prefs,
1152
1152
  temperature: @temperature,
1153
1153
  max_output_tokens: @max_output_tokens,
@@ -1347,7 +1347,7 @@ module RubyLLM
1347
1347
  payload = {
1348
1348
  chat: self,
1349
1349
  provider: @provider.slug,
1350
- provider_class: @provider.class.display_name,
1350
+ provider_class: @provider.name,
1351
1351
  model: @model.id,
1352
1352
  model_info: @model,
1353
1353
  tool: tool,
@@ -117,7 +117,7 @@ module RubyLLM
117
117
 
118
118
  payload = {
119
119
  provider: provider_instance.slug,
120
- provider_class: provider_instance.class.display_name,
120
+ provider_class: provider_instance.name,
121
121
  model: model_id,
122
122
  model_info: model,
123
123
  input: text,
@@ -83,7 +83,7 @@ module RubyLLM
83
83
  end
84
84
  end
85
85
 
86
- # Raised when Chat#with_server_tools is used with a provider RubyLLM has
86
+ # Raised when Chat#with_provider_tools is used with a provider RubyLLM has
87
87
  # no server-tool support for, or with an alias the provider's protocol
88
88
  # does not define.
89
89
  class UnsupportedServerToolError < Error; end
@@ -75,7 +75,7 @@ module RubyLLM
75
75
  empty_tokens = Tokens.new
76
76
  payload = {
77
77
  provider: provider_instance.slug,
78
- provider_class: provider_instance.class.display_name,
78
+ provider_class: provider_instance.name,
79
79
  model: model.id,
80
80
  model_info: model,
81
81
  prompt: prompt,
@@ -64,7 +64,7 @@ module RubyLLM
64
64
 
65
65
  # The provider-executed tool steps in this response, as an array of
66
66
  # ServerToolCall objects. Empty unless the chat enabled tools with
67
- # Chat#with_server_tools and the model used one.
67
+ # Chat#with_provider_tools and the model used one.
68
68
  attr_reader :server_tool_calls
69
69
 
70
70
  # The provider-shaped content blocks of this assistant message, kept
@@ -129,6 +129,14 @@ module RubyLLM
129
129
  dup.tap { |message| message.instance_variable_set(:@attachments, wrapped) }
130
130
  end
131
131
 
132
+ def without_thinking # :nodoc:
133
+ dup.tap do |message|
134
+ message.instance_variable_set(:@thinking, nil)
135
+ message.instance_variable_set(:@raw_reasoning, nil)
136
+ message.instance_variable_set(:@tool_calls, tool_calls_without_thought_signatures)
137
+ end
138
+ end
139
+
132
140
  # Returns +true+ if the assistant requested one or more tool calls,
133
141
  # +false+ otherwise.
134
142
  def tool_call?
@@ -276,6 +284,12 @@ module RubyLLM
276
284
  end
277
285
  end
278
286
 
287
+ def tool_calls_without_thought_signatures
288
+ tool_calls&.transform_values do |call|
289
+ call.dup.tap { |copy| copy.thought_signature = nil }
290
+ end
291
+ end
292
+
279
293
  def coerce_thinking(thinking, signature)
280
294
  case thinking
281
295
  when nil, Thinking then thinking