From d4fa0c39672ecda44e308f50c0a9e3f8e010dfa4 Mon Sep 17 00:00:00 2001 From: Paul Shippy Date: Mon, 14 Apr 2025 11:53:06 -0700 Subject: [PATCH 1/3] Nested parameter support --- lib/ruby_llm/providers/anthropic/tools.rb | 17 ++++++++++---- lib/ruby_llm/providers/gemini/tools.rb | 28 ++++++++++++++++++----- lib/ruby_llm/providers/openai/tools.rb | 7 +++++- lib/ruby_llm/tool.rb | 12 ++++++---- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/lib/ruby_llm/providers/anthropic/tools.rb b/lib/ruby_llm/providers/anthropic/tools.rb index 3ccfb202..d847a284 100644 --- a/lib/ruby_llm/providers/anthropic/tools.rb +++ b/lib/ruby_llm/providers/anthropic/tools.rb @@ -81,13 +81,22 @@ def parse_tool_calls(content_block) def clean_parameters(parameters) parameters.transform_values do |param| - { - type: param.type, - description: param.description - }.compact + clean_parameter(param) end end + def clean_parameter(param) + { + type: param.type, + description: param.description, + items: param.items && { + type: 'object', + properties: clean_parameters(param.items) + }, + properties: param.properties && clean_parameters(param.properties) + }.compact + end + def required_parameters(parameters) parameters.select { |_, param| param.required }.keys end diff --git a/lib/ruby_llm/providers/gemini/tools.rb b/lib/ruby_llm/providers/gemini/tools.rb index 8cb85b1c..36e63ace 100644 --- a/lib/ruby_llm/providers/gemini/tools.rb +++ b/lib/ruby_llm/providers/gemini/tools.rb @@ -62,16 +62,32 @@ def function_declaration_for(tool) def format_parameters(parameters) { type: 'OBJECT', - properties: parameters.transform_values do |param| - { - type: param_type_for_gemini(param.type), - description: param.description - }.compact - end, + properties: parameters.transform_values { |param| format_parameter(param) }, required: parameters.select { |_, p| p.required }.keys.map(&:to_s) } end + def format_parameter(param) + { + type: param_type_for_gemini(param.type), + description: param.description, + items: param.items && { + type: 'OBJECT', + properties: format_nested_parameters(param.items) + }, + properties: param.properties && format_nested_parameters(param.properties) + }.compact + end + + def format_nested_parameters(parameters) + parameters.transform_values do |param| + { + type: param_type_for_gemini(param.type), + description: param.description + }.compact + end + end + # Convert RubyLLM param types to Gemini API types def param_type_for_gemini(type) case type.to_s.downcase diff --git a/lib/ruby_llm/providers/openai/tools.rb b/lib/ruby_llm/providers/openai/tools.rb index 82bc356d..3769bd8a 100644 --- a/lib/ruby_llm/providers/openai/tools.rb +++ b/lib/ruby_llm/providers/openai/tools.rb @@ -25,7 +25,12 @@ def tool_for(tool) # rubocop:disable Metrics/MethodLength def param_schema(param) { type: param.type, - description: param.description + description: param.description, + items: param.items && { + type: 'object', + properties: param.items.transform_values { |p| param_schema(p) } + }, + properties: param.properties&.transform_values { |p| param_schema(p) } }.compact end diff --git a/lib/ruby_llm/tool.rb b/lib/ruby_llm/tool.rb index fa28ed55..df1642a0 100644 --- a/lib/ruby_llm/tool.rb +++ b/lib/ruby_llm/tool.rb @@ -4,13 +4,15 @@ module RubyLLM # Parameter definition for Tool methods. Specifies type constraints, # descriptions, and whether parameters are required. class Parameter - attr_reader :name, :type, :description, :required + attr_reader :name, :type, :description, :required, :items, :properties - def initialize(name, type: 'string', desc: nil, required: true) + def initialize(name, **options) @name = name - @type = type - @description = desc - @required = required + @type = options.fetch(:type, 'string') + @description = options.fetch(:desc, nil) + @required = options.fetch(:required, true) + @items = options[:items]&.transform_values { |v| Parameter.new(v[:name], **v) } + @properties = options[:properties]&.transform_values { |v| Parameter.new(v[:name], **v) } end end From 65ecd0302c1c78abe3e2ec14c16f60166ed910b6 Mon Sep 17 00:00:00 2001 From: Paul Shippy Date: Mon, 14 Apr 2025 13:53:30 -0700 Subject: [PATCH 2/3] Add specs for arrays and objects --- ...les_array_parameters_with_object_items.yml | 60 +++++ ...41022_handles_nested_object_parameters.yml | 59 +++++ ...les_array_parameters_with_object_items.yml | 199 ++++++++++++++ ...-v1_0_handles_nested_object_parameters.yml | 124 +++++++++ ...les_array_parameters_with_object_items.yml | 61 +++++ ...-chat_handles_nested_object_parameters.yml | 60 +++++ ...les_array_parameters_with_object_items.yml | 78 ++++++ ...flash_handles_nested_object_parameters.yml | 77 ++++++ ...les_array_parameters_with_object_items.yml | 249 ++++++++++++++++++ ...-mini_handles_nested_object_parameters.yml | 239 +++++++++++++++++ spec/ruby_llm/chat_tools_spec.rb | 91 +++++++ 11 files changed, 1297 insertions(+) create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml create mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..ec1a48f8 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml @@ -0,0 +1,60 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.anthropic.com/v1/messages + body: + encoding: UTF-8 + string: '{"model":"claude-3-5-haiku-20241022","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505)"}],"temperature":0.7,"stream":false,"max_tokens":8192,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Api-Key: + - test + Anthropic-Version: + - '2023-06-01' + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 401 + message: Unauthorized + headers: + Date: + - Mon, 14 Apr 2025 20:46:38 GMT + Content-Type: + - application/json + Content-Length: + - '86' + Connection: + - keep-alive + X-Should-Retry: + - 'false' + Request-Id: + - "" + Via: + - 1.1 google + Cf-Cache-Status: + - DYNAMIC + X-Robots-Tag: + - none + Server: + - cloudflare + Cf-Ray: + - "" + body: + encoding: UTF-8 + string: '{"type":"error","error":{"type":"authentication_error","message":"invalid + x-api-key"}}' + recorded_at: Mon, 14 Apr 2025 20:47:20 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml new file mode 100644 index 00000000..1d4b9e41 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml @@ -0,0 +1,59 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.anthropic.com/v1/messages + body: + encoding: UTF-8 + string: '{"model":"claude-3-5-haiku-20241022","messages":[{"role":"user","content":"Add + John Doe to the address book at 123 Main St, Springfield 12345"}],"temperature":0.7,"stream":false,"max_tokens":8192,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Api-Key: + - test + Anthropic-Version: + - '2023-06-01' + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 401 + message: Unauthorized + headers: + Date: + - Mon, 14 Apr 2025 20:46:38 GMT + Content-Type: + - application/json + Content-Length: + - '86' + Connection: + - keep-alive + X-Should-Retry: + - 'false' + Request-Id: + - "" + Via: + - 1.1 google + Cf-Cache-Status: + - DYNAMIC + X-Robots-Tag: + - none + Server: + - cloudflare + Cf-Ray: + - "" + body: + encoding: UTF-8 + string: '{"type":"error","error":{"type":"authentication_error","message":"invalid + x-api-key"}}' + recorded_at: Mon, 14 Apr 2025 20:47:20 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..7e52033f --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml @@ -0,0 +1,199 @@ +--- +http_interactions: +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505)"}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T204725Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 9a3c99a37b5a0fbf8f93c72ff70fec06c4e0cf555e66909f91459d21e1fa8a89 + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=d624bfcb5d75a9a93fc17464a1141e3c76783b01f397407ba4b4371b7013247c + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:46 GMT + Content-Type: + - application/json + Content-Length: + - '698' + Connection: + - keep-alive + X-Amzn-Requestid: + - 961a8679-bc93-4fe7-831a-2a76e846e775 + X-Amzn-Bedrock-Invocation-Latency: + - '2734' + X-Amzn-Bedrock-Output-Token-Count: + - '142' + X-Amzn-Bedrock-Input-Token-Count: + - '455' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_01MEhNBuCytqRkJtHWt9d4SY","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ll + help you add information about California and Texas to the address book. I''ll + use the address_book function to add the capitals of these states.\n\nFirst, + let''s add Sacramento, California:"},{"type":"tool_use","id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","name":"address_book","input":{"contact":{"name":"Sacramento","address":{"street":"State + Capitol","city":"Sacramento","zip":"95814"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":455,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":142}}' + recorded_at: Mon, 14 Apr 2025 20:47:28 GMT +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505)"},{"role":"assistant","content":[{"type":"text","text":"I''ll + help you add information about California and Texas to the address book. I''ll + use the address_book function to add the capitals of these states.\n\nFirst, + let''s add Sacramento, California:"},{"type":"tool_use","id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","name":"address_book","input":{"contact":{"name":"Sacramento","address":{"street":"State + Capitol","city":"Sacramento","zip":"95814"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","content":"Completed + contact: Sacramento at State Capitol, Sacramento 95814"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T204728Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 706421bf40a7bc910c17f178b097504cc517c163fcf88c889c920c79b5f34b71 + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=04d99a303079209b3bb77cb4f3ddd0540104d89bbf6afff506b634c7b3c2c614 + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:48 GMT + Content-Type: + - application/json + Content-Length: + - '465' + Connection: + - keep-alive + X-Amzn-Requestid: + - 2916cefd-da5e-4d30-9d56-3950dfa6ab8a + X-Amzn-Bedrock-Invocation-Latency: + - '1628' + X-Amzn-Bedrock-Output-Token-Count: + - '92' + X-Amzn-Bedrock-Input-Token-Count: + - '602' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_016BvHFxNkm5hnxWTCim4FCQ","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"Now, + let''s add Austin, Texas:"},{"type":"tool_use","id":"toolu_bdrk_01VDVnFxaVAXZ1ix78L6vftL","name":"address_book","input":{"contact":{"name":"Austin","address":{"street":"State + Capitol","city":"Austin","zip":"78701"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":602,"output_tokens":92}}' + recorded_at: Mon, 14 Apr 2025 20:47:30 GMT +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505)"},{"role":"assistant","content":[{"type":"text","text":"I''ll + help you add information about California and Texas to the address book. I''ll + use the address_book function to add the capitals of these states.\n\nFirst, + let''s add Sacramento, California:"},{"type":"tool_use","id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","name":"address_book","input":{"contact":{"name":"Sacramento","address":{"street":"State + Capitol","city":"Sacramento","zip":"95814"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","content":"Completed + contact: Sacramento at State Capitol, Sacramento 95814"}]},{"role":"assistant","content":[{"type":"text","text":"Now, + let''s add Austin, Texas:"},{"type":"tool_use","id":"toolu_bdrk_01VDVnFxaVAXZ1ix78L6vftL","name":"address_book","input":{"contact":{"name":"Austin","address":{"street":"State + Capitol","city":"Austin","zip":"78701"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01VDVnFxaVAXZ1ix78L6vftL","content":"Completed + contact: Austin at State Capitol, Austin 78701"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T204730Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 8154cb3f09a327a022f1d09f0159f9c7d19101000816e45b4fe569b0e46714d3 + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=e8cd3ebea5961b0aacc8f538dcf2d3eb64654c8da4464fcf8c8518420d9d2409 + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:51 GMT + Content-Type: + - application/json + Content-Length: + - '741' + Connection: + - keep-alive + X-Amzn-Requestid: + - 62cb4af4-ee1b-41ab-9ca6-e8ce0e82aedd + X-Amzn-Bedrock-Invocation-Latency: + - '3231' + X-Amzn-Bedrock-Output-Token-Count: + - '101' + X-Amzn-Bedrock-Input-Token-Count: + - '718' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_011fpnzH1AJV2ho9ine3DPeF","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ve + added the capitals of California (Sacramento) and Texas (Austin) to the address + book. I included their respective state capitol addresses and ZIP codes. \n\nNote: + While you provided population information (California: 39,538,223 and Texas: + 29,145,505), the address_book function doesn''t have a field for population, + so I couldn''t include that specific detail.\n\nIs there anything else you + would like me to do with these entries?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":718,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":101}}' + recorded_at: Mon, 14 Apr 2025 20:47:33 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml new file mode 100644 index 00000000..09d5597e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml @@ -0,0 +1,124 @@ +--- +http_interactions: +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + John Doe to the address book at 123 Main St, Springfield 12345"}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T204720Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 20bc836937097802a104c9ae3c86ad4f5f74750c68d26050182b4720a23eba7b + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=b4eb6b38805ab9215646872131465a6e8e0167d18a5d94ab4c5626123696a809 + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:41 GMT + Content-Type: + - application/json + Content-Length: + - '649' + Connection: + - keep-alive + X-Amzn-Requestid: + - 34d437ea-ca44-4187-96a4-8a9d8a565707 + X-Amzn-Bedrock-Invocation-Latency: + - '2088' + X-Amzn-Bedrock-Output-Token-Count: + - '137' + X-Amzn-Bedrock-Input-Token-Count: + - '444' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_01V7R3B9gE4F7vhXQP3m4zug","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ll + help you add John Doe to the address book using the `address_book` function. + I''ll structure the contact information with the provided details."},{"type":"tool_use","id":"toolu_bdrk_01AyRobTeGqtRsWYUH9zJEZS","name":"address_book","input":{"contact":{"name":"John + Doe","address":{"street":"123 Main St","city":"Springfield","zip":"12345"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":444,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":137}}' + recorded_at: Mon, 14 Apr 2025 20:47:23 GMT +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + John Doe to the address book at 123 Main St, Springfield 12345"},{"role":"assistant","content":[{"type":"text","text":"I''ll + help you add John Doe to the address book using the `address_book` function. + I''ll structure the contact information with the provided details."},{"type":"tool_use","id":"toolu_bdrk_01AyRobTeGqtRsWYUH9zJEZS","name":"address_book","input":{"contact":{"name":"John + Doe","address":{"street":"123 Main St","city":"Springfield","zip":"12345"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01AyRobTeGqtRsWYUH9zJEZS","content":"Completed + contact: John Doe at 123 Main St, Springfield 12345"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages + address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T204723Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 30fec609f54ff4603ea7ddc10cca5a6bc14dbc507e38f49c2632939f55d68254 + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=34e01c96541c9033acba54f7a9cab03bdcba5e857eb9a20b916fa834d16b74f7 + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:43 GMT + Content-Type: + - application/json + Content-Length: + - '396' + Connection: + - keep-alive + X-Amzn-Requestid: + - 2592ff66-4c64-4e06-976d-004b3092da44 + X-Amzn-Bedrock-Invocation-Latency: + - '2310' + X-Amzn-Bedrock-Output-Token-Count: + - '40' + X-Amzn-Bedrock-Input-Token-Count: + - '591' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_01FiYNJNLTztpP468zXDEVJA","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"John + Doe has been successfully added to the address book with the address 123 Main + St, Springfield, 12345. Is there anything else I can help you with?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":591,"output_tokens":40}}' + recorded_at: Mon, 14 Apr 2025 20:47:25 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..9aaf0739 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml @@ -0,0 +1,61 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.deepseek.com/chat/completions + body: + encoding: UTF-8 + string: '{"model":"deepseek-chat","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505)"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + headers: + User-Agent: + - Faraday v2.12.2 + Authorization: + - Bearer test + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 401 + message: Unauthorized + headers: + Date: + - Mon, 14 Apr 2025 20:46:53 GMT + Content-Type: + - application/json + Content-Length: + - '149' + Connection: + - keep-alive + Vary: + - origin, access-control-request-method, access-control-request-headers + Access-Control-Allow-Credentials: + - 'true' + X-Ds-Trace-Id: + - e29277e410970fa9d0c36e581a153bea + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Content-Type-Options: + - nosniff + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - "" + Server: + - cloudflare + Cf-Ray: + - "" + body: + encoding: UTF-8 + string: '{"error":{"message":"Authentication Fails, Your api key: test is invalid","type":"authentication_error","param":null,"code":"invalid_request_error"}}' + recorded_at: Mon, 14 Apr 2025 20:47:35 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml new file mode 100644 index 00000000..e6c0ff18 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml @@ -0,0 +1,60 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.deepseek.com/chat/completions + body: + encoding: UTF-8 + string: '{"model":"deepseek-chat","messages":[{"role":"user","content":"Add + John Doe to the address book at 123 Main St, Springfield 12345"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + headers: + User-Agent: + - Faraday v2.12.2 + Authorization: + - Bearer test + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 401 + message: Unauthorized + headers: + Date: + - Mon, 14 Apr 2025 20:46:53 GMT + Content-Type: + - application/json + Content-Length: + - '149' + Connection: + - keep-alive + Vary: + - origin, access-control-request-method, access-control-request-headers + Access-Control-Allow-Credentials: + - 'true' + X-Ds-Trace-Id: + - 84b81fd025e92bfafd31a16d05806bce + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Content-Type-Options: + - nosniff + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - "" + Server: + - cloudflare + Cf-Ray: + - "" + body: + encoding: UTF-8 + string: '{"error":{"message":"Authentication Fails, Your api key: test is invalid","type":"authentication_error","param":null,"code":"invalid_request_error"}}' + recorded_at: Mon, 14 Apr 2025 20:47:35 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..3dd635a5 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml @@ -0,0 +1,78 @@ +--- +http_interactions: +- request: + method: post + uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent + body: + encoding: UTF-8 + string: '{"contents":[{"role":"user","parts":[{"text":"Add information about + California (capital: Sacramento, pop: 39538223) and Texas (capital: Austin, + pop: 29145505)"}]}],"generationConfig":{"temperature":0.7},"tools":[{"functionDeclarations":[{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"OBJECT","properties":{"contact":{"type":"OBJECT","description":"Contact + information","properties":{"name":{"type":"STRING","description":"Full name"},"address":{"type":"OBJECT","description":"Address + details"}}}},"required":["contact"]}}]}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Goog-Api-Key: + - test + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 400 + message: Bad Request + headers: + Vary: + - Origin + - Referer + - X-Origin + Content-Type: + - application/json; charset=UTF-8 + Date: + - Mon, 14 Apr 2025 20:46:52 GMT + Server: + - scaffolding on HTTPServer2 + X-Xss-Protection: + - '0' + X-Frame-Options: + - SAMEORIGIN + X-Content-Type-Options: + - nosniff + Server-Timing: + - gfet4t7; dur=25 + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: | + { + "error": { + "code": 400, + "message": "API key not valid. Please pass a valid API key.", + "status": "INVALID_ARGUMENT", + "details": [ + { + "@type": "type.googleapis.com/google.rpc.ErrorInfo", + "reason": "API_KEY_INVALID", + "domain": "googleapis.com", + "metadata": { + "service": "generativelanguage.googleapis.com" + } + }, + { + "@type": "type.googleapis.com/google.rpc.LocalizedMessage", + "locale": "en-US", + "message": "API key not valid. Please pass a valid API key." + } + ] + } + } + recorded_at: Mon, 14 Apr 2025 20:47:34 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml new file mode 100644 index 00000000..28e71a86 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml @@ -0,0 +1,77 @@ +--- +http_interactions: +- request: + method: post + uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent + body: + encoding: UTF-8 + string: '{"contents":[{"role":"user","parts":[{"text":"Add John Doe to the address + book at 123 Main St, Springfield 12345"}]}],"generationConfig":{"temperature":0.7},"tools":[{"functionDeclarations":[{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"OBJECT","properties":{"contact":{"type":"OBJECT","description":"Contact + information","properties":{"name":{"type":"STRING","description":"Full name"},"address":{"type":"OBJECT","description":"Address + details"}}}},"required":["contact"]}}]}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Goog-Api-Key: + - test + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 400 + message: Bad Request + headers: + Vary: + - Origin + - Referer + - X-Origin + Content-Type: + - application/json; charset=UTF-8 + Date: + - Mon, 14 Apr 2025 20:46:52 GMT + Server: + - scaffolding on HTTPServer2 + X-Xss-Protection: + - '0' + X-Frame-Options: + - SAMEORIGIN + X-Content-Type-Options: + - nosniff + Server-Timing: + - gfet4t7; dur=140 + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: | + { + "error": { + "code": 400, + "message": "API key not valid. Please pass a valid API key.", + "status": "INVALID_ARGUMENT", + "details": [ + { + "@type": "type.googleapis.com/google.rpc.ErrorInfo", + "reason": "API_KEY_INVALID", + "domain": "googleapis.com", + "metadata": { + "service": "generativelanguage.googleapis.com" + } + }, + { + "@type": "type.googleapis.com/google.rpc.LocalizedMessage", + "locale": "en-US", + "message": "API key not valid. Please pass a valid API key." + } + ] + } + } + recorded_at: Mon, 14 Apr 2025 20:47:34 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..28f6e92c --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml @@ -0,0 +1,249 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.openai.com/v1/chat/completions + body: + encoding: UTF-8 + string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add information + about California (capital: Sacramento, pop: 39538223) and Texas (capital: + Austin, pop: 29145505)"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + headers: + User-Agent: + - Faraday v2.12.2 + Authorization: + - Bearer + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:56 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Access-Control-Expose-Headers: + - X-Request-ID + Openai-Organization: + - "" + Openai-Processing-Ms: + - '1042' + Openai-Version: + - '2020-10-01' + X-Ratelimit-Limit-Requests: + - '30000' + X-Ratelimit-Limit-Tokens: + - '150000000' + X-Ratelimit-Remaining-Requests: + - '29999' + X-Ratelimit-Remaining-Tokens: + - '149999970' + X-Ratelimit-Reset-Requests: + - 2ms + X-Ratelimit-Reset-Tokens: + - 0s + X-Request-Id: + - "" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - "" + - "" + X-Content-Type-Options: + - nosniff + Server: + - cloudflare + Cf-Ray: + - "" + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: | + { + "id": "chatcmpl-BMKzflqa6WylxkB5Iafr5niqDrhLT", + "object": "chat.completion", + "created": 1744663615, + "model": "gpt-4o-mini-2024-07-18", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": null, + "tool_calls": [ + { + "id": "call_qaGkFndZdy8Zu9x8CY2XIUpS", + "type": "function", + "function": { + "name": "address_book", + "arguments": "{\"contact\": {\"name\": \"California\", \"address\": {\"street\": \"Sacramento\", \"city\": \"California\", \"zip\": \"95814\"}}}" + } + }, + { + "id": "call_1R5WKeLb3MxwNC9TyVWBOO6I", + "type": "function", + "function": { + "name": "address_book", + "arguments": "{\"contact\": {\"name\": \"Texas\", \"address\": {\"street\": \"Austin\", \"city\": \"Texas\", \"zip\": \"78701\"}}}" + } + } + ], + "refusal": null, + "annotations": [] + }, + "logprobs": null, + "finish_reason": "tool_calls" + } + ], + "usage": { + "prompt_tokens": 114, + "completion_tokens": 82, + "total_tokens": 196, + "prompt_tokens_details": { + "cached_tokens": 0, + "audio_tokens": 0 + }, + "completion_tokens_details": { + "reasoning_tokens": 0, + "audio_tokens": 0, + "accepted_prediction_tokens": 0, + "rejected_prediction_tokens": 0 + } + }, + "service_tier": "default", + "system_fingerprint": "fp_f7d56a8a2c" + } + recorded_at: Mon, 14 Apr 2025 20:47:38 GMT +- request: + method: post + uri: https://api.openai.com/v1/chat/completions + body: + encoding: UTF-8 + string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add information + about California (capital: Sacramento, pop: 39538223) and Texas (capital: + Austin, pop: 29145505)"},{"role":"assistant","tool_calls":[{"id":"call_qaGkFndZdy8Zu9x8CY2XIUpS","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"California\",\"address\":{\"street\":\"Sacramento\",\"city\":\"California\",\"zip\":\"95814\"}}}"}},{"id":"call_1R5WKeLb3MxwNC9TyVWBOO6I","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"Texas\",\"address\":{\"street\":\"Austin\",\"city\":\"Texas\",\"zip\":\"78701\"}}}"}}]},{"role":"tool","content":"Completed + contact: California at Sacramento, California 95814","tool_call_id":"call_qaGkFndZdy8Zu9x8CY2XIUpS"},{"role":"tool","content":"Completed + contact: Texas at Austin, Texas 78701","tool_call_id":"call_1R5WKeLb3MxwNC9TyVWBOO6I"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + headers: + User-Agent: + - Faraday v2.12.2 + Authorization: + - Bearer + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:57 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Access-Control-Expose-Headers: + - X-Request-ID + Openai-Organization: + - "" + Openai-Processing-Ms: + - '886' + Openai-Version: + - '2020-10-01' + X-Ratelimit-Limit-Requests: + - '30000' + X-Ratelimit-Limit-Tokens: + - '150000000' + X-Ratelimit-Remaining-Requests: + - '29999' + X-Ratelimit-Remaining-Tokens: + - '149999940' + X-Ratelimit-Reset-Requests: + - 2ms + X-Ratelimit-Reset-Tokens: + - 0s + X-Request-Id: + - "" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - "" + - "" + X-Content-Type-Options: + - nosniff + Server: + - cloudflare + Cf-Ray: + - "" + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: | + { + "id": "chatcmpl-BMKzgp2kpy5QuBWrblDj5k5lQN5ER", + "object": "chat.completion", + "created": 1744663616, + "model": "gpt-4o-mini-2024-07-18", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "I have successfully added the information for California (capital: Sacramento, population: 39,538,223) and Texas (capital: Austin, population: 29,145,505) to the address book.", + "refusal": null, + "annotations": [] + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 231, + "completion_tokens": 45, + "total_tokens": 276, + "prompt_tokens_details": { + "cached_tokens": 0, + "audio_tokens": 0 + }, + "completion_tokens_details": { + "reasoning_tokens": 0, + "audio_tokens": 0, + "accepted_prediction_tokens": 0, + "rejected_prediction_tokens": 0 + } + }, + "service_tier": "default", + "system_fingerprint": "fp_f7d56a8a2c" + } + recorded_at: Mon, 14 Apr 2025 20:47:39 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml new file mode 100644 index 00000000..78f83bbf --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml @@ -0,0 +1,239 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.openai.com/v1/chat/completions + body: + encoding: UTF-8 + string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add John + Doe to the address book at 123 Main St, Springfield 12345"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + headers: + User-Agent: + - Faraday v2.12.2 + Authorization: + - Bearer + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:54 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Access-Control-Expose-Headers: + - X-Request-ID + Openai-Organization: + - "" + Openai-Processing-Ms: + - '524' + Openai-Version: + - '2020-10-01' + X-Ratelimit-Limit-Requests: + - '30000' + X-Ratelimit-Limit-Tokens: + - '150000000' + X-Ratelimit-Remaining-Requests: + - '29999' + X-Ratelimit-Remaining-Tokens: + - '149999981' + X-Ratelimit-Reset-Requests: + - 2ms + X-Ratelimit-Reset-Tokens: + - 0s + X-Request-Id: + - "" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - "" + - "" + X-Content-Type-Options: + - nosniff + Server: + - cloudflare + Cf-Ray: + - "" + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: | + { + "id": "chatcmpl-BMKzd7UzWUI2tpCrAbEwYOuh8Jq6x", + "object": "chat.completion", + "created": 1744663613, + "model": "gpt-4o-mini-2024-07-18", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": null, + "tool_calls": [ + { + "id": "call_xijRRP0wRf1Bd0N6WTi5jBx4", + "type": "function", + "function": { + "name": "address_book", + "arguments": "{\"contact\":{\"name\":\"John Doe\",\"address\":{\"street\":\"123 Main St\",\"city\":\"Springfield\",\"zip\":\"12345\"}}}" + } + } + ], + "refusal": null, + "annotations": [] + }, + "logprobs": null, + "finish_reason": "tool_calls" + } + ], + "usage": { + "prompt_tokens": 101, + "completion_tokens": 37, + "total_tokens": 138, + "prompt_tokens_details": { + "cached_tokens": 0, + "audio_tokens": 0 + }, + "completion_tokens_details": { + "reasoning_tokens": 0, + "audio_tokens": 0, + "accepted_prediction_tokens": 0, + "rejected_prediction_tokens": 0 + } + }, + "service_tier": "default", + "system_fingerprint": "fp_f7d56a8a2c" + } + recorded_at: Mon, 14 Apr 2025 20:47:36 GMT +- request: + method: post + uri: https://api.openai.com/v1/chat/completions + body: + encoding: UTF-8 + string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add John + Doe to the address book at 123 Main St, Springfield 12345"},{"role":"assistant","tool_calls":[{"id":"call_xijRRP0wRf1Bd0N6WTi5jBx4","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"John + Doe\",\"address\":{\"street\":\"123 Main St\",\"city\":\"Springfield\",\"zip\":\"12345\"}}}"}}]},{"role":"tool","content":"Completed + contact: John Doe at 123 Main St, Springfield 12345","tool_call_id":"call_xijRRP0wRf1Bd0N6WTi5jBx4"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact + information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address + details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City + name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + headers: + User-Agent: + - Faraday v2.12.2 + Authorization: + - Bearer + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 20:46:55 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Access-Control-Expose-Headers: + - X-Request-ID + Openai-Organization: + - "" + Openai-Processing-Ms: + - '580' + Openai-Version: + - '2020-10-01' + X-Ratelimit-Limit-Requests: + - '30000' + X-Ratelimit-Limit-Tokens: + - '150000000' + X-Ratelimit-Remaining-Requests: + - '29999' + X-Ratelimit-Remaining-Tokens: + - '149999963' + X-Ratelimit-Reset-Requests: + - 2ms + X-Ratelimit-Reset-Tokens: + - 0s + X-Request-Id: + - "" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cf-Cache-Status: + - DYNAMIC + Set-Cookie: + - "" + - "" + X-Content-Type-Options: + - nosniff + Server: + - cloudflare + Cf-Ray: + - "" + Alt-Svc: + - h3=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: | + { + "id": "chatcmpl-BMKzeYZaqeijDaZOViMbYh5HfHPRi", + "object": "chat.completion", + "created": 1744663614, + "model": "gpt-4o-mini-2024-07-18", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "John Doe has been successfully added to the address book at 123 Main St, Springfield 12345.", + "refusal": null, + "annotations": [] + }, + "logprobs": null, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 160, + "completion_tokens": 23, + "total_tokens": 183, + "prompt_tokens_details": { + "cached_tokens": 0, + "audio_tokens": 0 + }, + "completion_tokens_details": { + "reasoning_tokens": 0, + "audio_tokens": 0, + "accepted_prediction_tokens": 0, + "rejected_prediction_tokens": 0 + } + }, + "service_tier": "default", + "system_fingerprint": "fp_f7d56a8a2c" + } + recorded_at: Mon, 14 Apr 2025 20:47:37 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/ruby_llm/chat_tools_spec.rb b/spec/ruby_llm/chat_tools_spec.rb index 43f7e94c..3640427f 100644 --- a/spec/ruby_llm/chat_tools_spec.rb +++ b/spec/ruby_llm/chat_tools_spec.rb @@ -37,6 +37,70 @@ def execute end end + class AddressBook < RubyLLM::Tool # rubocop:disable Lint/ConstantDefinitionInBlock,RSpec/LeakyConstantDeclaration + description 'Manages address book entries' + + param :contact, + type: 'object', + desc: 'Contact information', + properties: { + name: { + type: 'string', + desc: 'Full name' + }, + address: { + type: 'object', + desc: 'Address details', + properties: { + street: { + type: 'string', + desc: 'Street address' + }, + city: { + type: 'string', + desc: 'City name' + }, + zip: { + type: 'string', + desc: 'ZIP/Postal code' + } + } + } + } + + def execute(contact:) + address = contact['address'] + "Completed contact: #{contact['name']} at #{address['street']}, " \ + "#{address['city']} #{address['zip']}" + end + end + + class StateManager < RubyLLM::Tool # rubocop:disable Lint/ConstantDefinitionInBlock,RSpec/LeakyConstantDeclaration + description 'Manages US states information' + + param :states, + type: 'array', + desc: 'List of states', + items: { + name: { + type: 'string', + desc: 'The state name' + }, + capital: { + type: 'string', + desc: 'The capital city' + }, + population: { + type: 'number', + desc: 'Population count' + } + } + + def execute(states:) + states.map { |s| "#{s['name']}: Capital is #{s['capital']} (pop: #{s['population']})" }.join("\n") + end + end + describe 'function calling' do chat_models.each do |model| provider = RubyLLM::Models.provider_for(model).slug @@ -127,6 +191,33 @@ def execute end end + describe 'nested parameters' do + chat_models.each do |model| + provider = RubyLLM::Models.provider_for(model).slug + + context "with #{provider}/#{model}" do + let(:chat) { RubyLLM.chat(model: model).with_tool(AddressBook) } + + it 'handles nested object parameters', :aggregate_failures do + prompt = 'Add John Doe to the address book at 123 Main St, Springfield 12345' + response = chat.ask(prompt) + + expect(response.content).to include('John Doe', '123 Main St', + 'Springfield', '12345') + end + + it 'handles array parameters with object items', :aggregate_failures do + prompt = 'Add information about California (capital: Sacramento, ' \ + 'pop: 39538223) and Texas (capital: Austin, pop: 29145505).' + response = chat.ask(prompt) + + expect(response.content).to include('Sacramento', 'Austin', + '39,538,223', '29,145,505') + end + end + end + end + describe 'error handling' do it 'raises an error when tool execution fails' do # rubocop:disable RSpec/MultipleExpectations chat = RubyLLM.chat.with_tool(BrokenTool) From 4efb76fe570505e4eb4b48ab611d97e8d08df7e9 Mon Sep 17 00:00:00 2001 From: Paul Shippy Date: Mon, 14 Apr 2025 14:30:51 -0700 Subject: [PATCH 3/3] Make Gemini tests work, fix issue with state manager test tool --- ...es_array_parameters_with_object_items.yml} | 14 +- ...les_array_parameters_with_object_items.yml | 129 ++++++++++++ ...es_array_parameters_with_object_items.yml} | 16 +- ...les_array_parameters_with_object_items.yml | 196 +++++++++++++++++ ...es_array_parameters_with_object_items.yml} | 80 +++---- ...41022_handles_nested_object_parameters.yml | 4 +- ...les_array_parameters_with_object_items.yml | 199 ------------------ ...-v1_0_handles_nested_object_parameters.yml | 54 ++--- ...-chat_handles_nested_object_parameters.yml | 6 +- ...les_array_parameters_with_object_items.yml | 78 ------- ...flash_handles_nested_object_parameters.yml | 156 ++++++++++++-- ...-mini_handles_nested_object_parameters.yml | 32 +-- spec/ruby_llm/chat_tools_spec.rb | 23 +- 13 files changed, 583 insertions(+), 404 deletions(-) rename spec/fixtures/vcr_cassettes/{chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml => chat_array_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml} (62%) create mode 100644 spec/fixtures/vcr_cassettes/chat_array_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml rename spec/fixtures/vcr_cassettes/{chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml => chat_array_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml} (63%) create mode 100644 spec/fixtures/vcr_cassettes/chat_array_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml rename spec/fixtures/vcr_cassettes/{chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml => chat_array_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml} (60%) delete mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml delete mode 100644 spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml similarity index 62% rename from spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml rename to spec/fixtures/vcr_cassettes/chat_array_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml index ec1a48f8..5d522452 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml +++ b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_array_parameters_with_object_items.yml @@ -7,11 +7,11 @@ http_interactions: encoding: UTF-8 string: '{"model":"claude-3-5-haiku-20241022","messages":[{"role":"user","content":"Add information about California (capital: Sacramento, pop: 39538223) and Texas - (capital: Austin, pop: 29145505)"}],"temperature":0.7,"stream":false,"max_tokens":8192,"tools":[{"name":"address_book","description":"Manages - address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' + (capital: Austin, pop: 29145505)."}],"temperature":0.7,"stream":false,"max_tokens":8192,"tools":[{"name":"state_manager","description":"Manages + US states information","input_schema":{"type":"object","properties":{"states":{"type":"array","description":"List + of states","items":{"type":"object","properties":{"name":{"type":"string","description":"The + state name"},"capital":{"type":"string","description":"The capital city"},"population":{"type":"number","description":"Population + count"}}}}},"required":["states"]}}]}' headers: User-Agent: - Faraday v2.12.2 @@ -31,7 +31,7 @@ http_interactions: message: Unauthorized headers: Date: - - Mon, 14 Apr 2025 20:46:38 GMT + - Mon, 14 Apr 2025 21:08:25 GMT Content-Type: - application/json Content-Length: @@ -56,5 +56,5 @@ http_interactions: encoding: UTF-8 string: '{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}' - recorded_at: Mon, 14 Apr 2025 20:47:20 GMT + recorded_at: Mon, 14 Apr 2025 21:09:07 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_array_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..b5c2de31 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml @@ -0,0 +1,129 @@ +--- +http_interactions: +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505). Make sure to return all the information + in the final output. Do not add commas to the population numbers."}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"state_manager","description":"Manages + US states information","input_schema":{"type":"object","properties":{"states":{"type":"array","description":"List + of states","items":{"type":"object","properties":{"name":{"type":"string","description":"The + state name"},"capital":{"type":"string","description":"The capital city"},"population":{"type":"number","description":"Population + count"}}}}},"required":["states"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T211556Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 7e4b21d6cf065b6dc4368d96391d34051b6301218526854ae8052fcf46afd2ae + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=a332b9db6d9b43ff184e9daff338de64ad01bf51c48b53579b42e05ede0db345 + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 21:15:16 GMT + Content-Type: + - application/json + Content-Length: + - '629' + Connection: + - keep-alive + X-Amzn-Requestid: + - 61c59f85-06c1-41c0-978d-23bce85bf8b5 + X-Amzn-Bedrock-Invocation-Latency: + - '2462' + X-Amzn-Bedrock-Output-Token-Count: + - '137' + X-Amzn-Bedrock-Input-Token-Count: + - '450' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_016xbQ39Gp6TChms9Bjsq2aE","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ll + help you add the information about California and Texas using the state_manager + tool."},{"type":"tool_use","id":"toolu_bdrk_01EjxynnEzfb8BT2fPe4aSZF","name":"state_manager","input":{"states":[{"name":"California","capital":"Sacramento","population":39538223},{"name":"Texas","capital":"Austin","population":29145505}]}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":450,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":137}}' + recorded_at: Mon, 14 Apr 2025 21:15:58 GMT +- request: + method: post + uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke + body: + encoding: UTF-8 + string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add + information about California (capital: Sacramento, pop: 39538223) and Texas + (capital: Austin, pop: 29145505). Make sure to return all the information + in the final output. Do not add commas to the population numbers."},{"role":"assistant","content":[{"type":"text","text":"I''ll + help you add the information about California and Texas using the state_manager + tool."},{"type":"tool_use","id":"toolu_bdrk_01EjxynnEzfb8BT2fPe4aSZF","name":"state_manager","input":{"states":[{"name":"California","capital":"Sacramento","population":39538223},{"name":"Texas","capital":"Austin","population":29145505}]}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01EjxynnEzfb8BT2fPe4aSZF","content":"California: + Capital is Sacramento (pop: 39538223)\nTexas: Capital is Austin (pop: 29145505)"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"state_manager","description":"Manages + US states information","input_schema":{"type":"object","properties":{"states":{"type":"array","description":"List + of states","items":{"type":"object","properties":{"name":{"type":"string","description":"The + state name"},"capital":{"type":"string","description":"The capital city"},"population":{"type":"number","description":"Population + count"}}}}},"required":["states"]}}]}' + headers: + User-Agent: + - Faraday v2.12.2 + Host: + - bedrock-runtime..amazonaws.com + X-Amz-Date: + - 20250414T211558Z + X-Amz-Security-Token: + - "" + X-Amz-Content-Sha256: + - 68c0f2dfe2b0a596d0b31497c23b3443f50aa292e4a408e4c61059e15de752f3 + Authorization: + - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=5db5594ee8b8fb8d5a394267d15c8e6c9185680a0939c84a6bfa9c1dd4edaf1e + Content-Type: + - application/json + Accept: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 14 Apr 2025 21:15:20 GMT + Content-Type: + - application/json + Content-Length: + - '567' + Connection: + - keep-alive + X-Amzn-Requestid: + - 3e033fcf-0d5a-49f7-8017-17aa94aa0ad0 + X-Amzn-Bedrock-Invocation-Latency: + - '3399' + X-Amzn-Bedrock-Output-Token-Count: + - '77' + X-Amzn-Bedrock-Input-Token-Count: + - '600' + body: + encoding: UTF-8 + string: '{"id":"msg_bdrk_015rg1zK3aSpbT9KtB3tgPLf","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ve + added the information for both California and Texas to the state manager. + The output confirms the details:\n- California: Capital is Sacramento, with + a population of 39,538,223\n- Texas: Capital is Austin, with a population + of 29,145,505\n\nIs there anything else you would like me to do with this + state information?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":600,"output_tokens":77}}' + recorded_at: Mon, 14 Apr 2025 21:16:02 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml similarity index 63% rename from spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml rename to spec/fixtures/vcr_cassettes/chat_array_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml index 9aaf0739..3a0d4084 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml +++ b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_deepseek_deepseek-chat_handles_array_parameters_with_object_items.yml @@ -7,11 +7,11 @@ http_interactions: encoding: UTF-8 string: '{"model":"deepseek-chat","messages":[{"role":"user","content":"Add information about California (capital: Sacramento, pop: 39538223) and Texas - (capital: Austin, pop: 29145505)"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages - address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + (capital: Austin, pop: 29145505)."}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"state_manager","description":"Manages + US states information","parameters":{"type":"object","properties":{"states":{"type":"array","description":"List + of states","items":{"type":"object","properties":{"name":{"type":"string","description":"The + state name"},"capital":{"type":"string","description":"The capital city"},"population":{"type":"number","description":"Population + count"}}}}},"required":["states"]}}}],"tool_choice":"auto"}' headers: User-Agent: - Faraday v2.12.2 @@ -29,7 +29,7 @@ http_interactions: message: Unauthorized headers: Date: - - Mon, 14 Apr 2025 20:46:53 GMT + - Mon, 14 Apr 2025 21:08:31 GMT Content-Type: - application/json Content-Length: @@ -41,7 +41,7 @@ http_interactions: Access-Control-Allow-Credentials: - 'true' X-Ds-Trace-Id: - - e29277e410970fa9d0c36e581a153bea + - f561e72cb0f2899eff06e3264398bacc Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload X-Content-Type-Options: @@ -57,5 +57,5 @@ http_interactions: body: encoding: UTF-8 string: '{"error":{"message":"Authentication Fails, Your api key: test is invalid","type":"authentication_error","param":null,"code":"invalid_request_error"}}' - recorded_at: Mon, 14 Apr 2025 20:47:35 GMT + recorded_at: Mon, 14 Apr 2025 21:09:13 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_array_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml new file mode 100644 index 00000000..51ebd065 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml @@ -0,0 +1,196 @@ +--- +http_interactions: +- request: + method: post + uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent + body: + encoding: UTF-8 + string: '{"contents":[{"role":"user","parts":[{"text":"Add information about + California (capital: Sacramento, pop: 39538223) and Texas (capital: Austin, + pop: 29145505). Make sure to return all the information in the final output."}]}],"generationConfig":{"temperature":0.7},"tools":[{"functionDeclarations":[{"name":"state_manager","description":"Manages + US states information","parameters":{"type":"OBJECT","properties":{"states":{"type":"ARRAY","description":"List + of states","items":{"type":"OBJECT","properties":{"name":{"type":"STRING","description":"The + state name"},"capital":{"type":"STRING","description":"The capital city"},"population":{"type":"NUMBER","description":"Population + count"}}}}},"required":["states"]}}]}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Goog-Api-Key: + - "" + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=UTF-8 + Vary: + - Origin + - Referer + - X-Origin + Date: + - Mon, 14 Apr 2025 21:14:08 GMT + Server: + - scaffolding on HTTPServer2 + X-Xss-Protection: + - '0' + X-Frame-Options: + - SAMEORIGIN + X-Content-Type-Options: + - nosniff + Server-Timing: + - gfet4t7; dur=727 + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: | + { + "candidates": [ + { + "content": { + "parts": [ + { + "functionCall": { + "name": "state_manager", + "args": { + "states": [ + { + "population": 39538223, + "capital": "Sacramento", + "name": "California" + }, + { + "name": "Texas", + "population": 29145505, + "capital": "Austin" + } + ] + } + } + } + ], + "role": "model" + }, + "finishReason": "STOP", + "avgLogprobs": -0.00093624428180711608 + } + ], + "usageMetadata": { + "promptTokenCount": 76, + "candidatesTokenCount": 14, + "totalTokenCount": 90, + "promptTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 76 + } + ], + "candidatesTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 14 + } + ] + }, + "modelVersion": "gemini-2.0-flash" + } + recorded_at: Mon, 14 Apr 2025 21:14:50 GMT +- request: + method: post + uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent + body: + encoding: UTF-8 + string: '{"contents":[{"role":"user","parts":[{"text":"Add information about + California (capital: Sacramento, pop: 39538223) and Texas (capital: Austin, + pop: 29145505). Make sure to return all the information in the final output."}]},{"role":"model","parts":[{"functionCall":{"name":"state_manager","args":{"states":[{"population":39538223,"capital":"Sacramento","name":"California"},{"name":"Texas","population":29145505,"capital":"Austin"}]}}}]},{"role":"user","parts":[{"functionResponse":{"name":"18770573-25f8-41e1-b047-cb8ef0a3f172","response":{"name":"18770573-25f8-41e1-b047-cb8ef0a3f172","content":"California: + Capital is Sacramento (pop: 39538223)\nTexas: Capital is Austin (pop: 29145505)"}}}]}],"generationConfig":{"temperature":0.7},"tools":[{"functionDeclarations":[{"name":"state_manager","description":"Manages + US states information","parameters":{"type":"OBJECT","properties":{"states":{"type":"ARRAY","description":"List + of states","items":{"type":"OBJECT","properties":{"name":{"type":"STRING","description":"The + state name"},"capital":{"type":"STRING","description":"The capital city"},"population":{"type":"NUMBER","description":"Population + count"}}}}},"required":["states"]}}]}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Goog-Api-Key: + - "" + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=UTF-8 + Vary: + - Origin + - Referer + - X-Origin + Date: + - Mon, 14 Apr 2025 21:14:09 GMT + Server: + - scaffolding on HTTPServer2 + X-Xss-Protection: + - '0' + X-Frame-Options: + - SAMEORIGIN + X-Content-Type-Options: + - nosniff + Server-Timing: + - gfet4t7; dur=597 + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: | + { + "candidates": [ + { + "content": { + "parts": [ + { + "text": "California: Capital is Sacramento (pop: 39538223)\nTexas: Capital is Austin (pop: 29145505)\n" + } + ], + "role": "model" + }, + "finishReason": "STOP", + "avgLogprobs": -0.00251712336351997 + } + ], + "usageMetadata": { + "promptTokenCount": 197, + "candidatesTokenCount": 38, + "totalTokenCount": 235, + "promptTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 197 + } + ], + "candidatesTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 38 + } + ] + }, + "modelVersion": "gemini-2.0-flash" + } + recorded_at: Mon, 14 Apr 2025 21:14:51 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml similarity index 60% rename from spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml rename to spec/fixtures/vcr_cassettes/chat_array_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml index 28f6e92c..75d1e280 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml +++ b/spec/fixtures/vcr_cassettes/chat_array_parameters_with_openai_gpt-4o-mini_handles_array_parameters_with_object_items.yml @@ -7,11 +7,12 @@ http_interactions: encoding: UTF-8 string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add information about California (capital: Sacramento, pop: 39538223) and Texas (capital: - Austin, pop: 29145505)"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages - address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + Austin, pop: 29145505). Make sure to return all the information in the final + output. "}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"state_manager","description":"Manages + US states information","parameters":{"type":"object","properties":{"states":{"type":"array","description":"List + of states","items":{"type":"object","properties":{"name":{"type":"string","description":"The + state name"},"capital":{"type":"string","description":"The capital city"},"population":{"type":"number","description":"Population + count"}}}}},"required":["states"]}}}],"tool_choice":"auto"}' headers: User-Agent: - Faraday v2.12.2 @@ -29,7 +30,7 @@ http_interactions: message: OK headers: Date: - - Mon, 14 Apr 2025 20:46:56 GMT + - Mon, 14 Apr 2025 21:26:53 GMT Content-Type: - application/json Transfer-Encoding: @@ -41,7 +42,7 @@ http_interactions: Openai-Organization: - "" Openai-Processing-Ms: - - '1042' + - '1014' Openai-Version: - '2020-10-01' X-Ratelimit-Limit-Requests: @@ -51,7 +52,7 @@ http_interactions: X-Ratelimit-Remaining-Requests: - '29999' X-Ratelimit-Remaining-Tokens: - - '149999970' + - '149999953' X-Ratelimit-Reset-Requests: - 2ms X-Ratelimit-Reset-Tokens: @@ -77,9 +78,9 @@ http_interactions: encoding: ASCII-8BIT string: | { - "id": "chatcmpl-BMKzflqa6WylxkB5Iafr5niqDrhLT", + "id": "chatcmpl-BMLcKjVwX1fSIG2fB8XIsURDiH4uD", "object": "chat.completion", - "created": 1744663615, + "created": 1744666012, "model": "gpt-4o-mini-2024-07-18", "choices": [ { @@ -89,19 +90,19 @@ http_interactions: "content": null, "tool_calls": [ { - "id": "call_qaGkFndZdy8Zu9x8CY2XIUpS", + "id": "call_Oluav8irb6cZvRSQwS8OuWrZ", "type": "function", "function": { - "name": "address_book", - "arguments": "{\"contact\": {\"name\": \"California\", \"address\": {\"street\": \"Sacramento\", \"city\": \"California\", \"zip\": \"95814\"}}}" + "name": "state_manager", + "arguments": "{\"states\": [{\"name\": \"California\", \"capital\": \"Sacramento\", \"population\": 39538223}]}" } }, { - "id": "call_1R5WKeLb3MxwNC9TyVWBOO6I", + "id": "call_daUVINMbQfHdcJOQtwWznVqq", "type": "function", "function": { - "name": "address_book", - "arguments": "{\"contact\": {\"name\": \"Texas\", \"address\": {\"street\": \"Austin\", \"city\": \"Texas\", \"zip\": \"78701\"}}}" + "name": "state_manager", + "arguments": "{\"states\": [{\"name\": \"Texas\", \"capital\": \"Austin\", \"population\": 29145505}]}" } } ], @@ -113,9 +114,9 @@ http_interactions: } ], "usage": { - "prompt_tokens": 114, - "completion_tokens": 82, - "total_tokens": 196, + "prompt_tokens": 117, + "completion_tokens": 74, + "total_tokens": 191, "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 @@ -128,9 +129,9 @@ http_interactions: } }, "service_tier": "default", - "system_fingerprint": "fp_f7d56a8a2c" + "system_fingerprint": "fp_64e0ac9789" } - recorded_at: Mon, 14 Apr 2025 20:47:38 GMT + recorded_at: Mon, 14 Apr 2025 21:27:35 GMT - request: method: post uri: https://api.openai.com/v1/chat/completions @@ -138,13 +139,14 @@ http_interactions: encoding: UTF-8 string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add information about California (capital: Sacramento, pop: 39538223) and Texas (capital: - Austin, pop: 29145505)"},{"role":"assistant","tool_calls":[{"id":"call_qaGkFndZdy8Zu9x8CY2XIUpS","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"California\",\"address\":{\"street\":\"Sacramento\",\"city\":\"California\",\"zip\":\"95814\"}}}"}},{"id":"call_1R5WKeLb3MxwNC9TyVWBOO6I","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"Texas\",\"address\":{\"street\":\"Austin\",\"city\":\"Texas\",\"zip\":\"78701\"}}}"}}]},{"role":"tool","content":"Completed - contact: California at Sacramento, California 95814","tool_call_id":"call_qaGkFndZdy8Zu9x8CY2XIUpS"},{"role":"tool","content":"Completed - contact: Texas at Austin, Texas 78701","tool_call_id":"call_1R5WKeLb3MxwNC9TyVWBOO6I"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages - address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}}],"tool_choice":"auto"}' + Austin, pop: 29145505). Make sure to return all the information in the final + output. "},{"role":"assistant","tool_calls":[{"id":"call_Oluav8irb6cZvRSQwS8OuWrZ","type":"function","function":{"name":"state_manager","arguments":"{\"states\":[{\"name\":\"California\",\"capital\":\"Sacramento\",\"population\":39538223}]}"}},{"id":"call_daUVINMbQfHdcJOQtwWznVqq","type":"function","function":{"name":"state_manager","arguments":"{\"states\":[{\"name\":\"Texas\",\"capital\":\"Austin\",\"population\":29145505}]}"}}]},{"role":"tool","content":"California: + Capital is Sacramento (pop: 39538223)","tool_call_id":"call_Oluav8irb6cZvRSQwS8OuWrZ"},{"role":"tool","content":"Texas: + Capital is Austin (pop: 29145505)","tool_call_id":"call_daUVINMbQfHdcJOQtwWznVqq"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"state_manager","description":"Manages + US states information","parameters":{"type":"object","properties":{"states":{"type":"array","description":"List + of states","items":{"type":"object","properties":{"name":{"type":"string","description":"The + state name"},"capital":{"type":"string","description":"The capital city"},"population":{"type":"number","description":"Population + count"}}}}},"required":["states"]}}}],"tool_choice":"auto"}' headers: User-Agent: - Faraday v2.12.2 @@ -162,7 +164,7 @@ http_interactions: message: OK headers: Date: - - Mon, 14 Apr 2025 20:46:57 GMT + - Mon, 14 Apr 2025 21:26:54 GMT Content-Type: - application/json Transfer-Encoding: @@ -174,7 +176,7 @@ http_interactions: Openai-Organization: - "" Openai-Processing-Ms: - - '886' + - '799' Openai-Version: - '2020-10-01' X-Ratelimit-Limit-Requests: @@ -184,7 +186,7 @@ http_interactions: X-Ratelimit-Remaining-Requests: - '29999' X-Ratelimit-Remaining-Tokens: - - '149999940' + - '149999928' X-Ratelimit-Reset-Requests: - 2ms X-Ratelimit-Reset-Tokens: @@ -210,16 +212,16 @@ http_interactions: encoding: ASCII-8BIT string: | { - "id": "chatcmpl-BMKzgp2kpy5QuBWrblDj5k5lQN5ER", + "id": "chatcmpl-BMLcLBh88FzAMA90ukeBVxzeK6WUL", "object": "chat.completion", - "created": 1744663616, + "created": 1744666013, "model": "gpt-4o-mini-2024-07-18", "choices": [ { "index": 0, "message": { "role": "assistant", - "content": "I have successfully added the information for California (capital: Sacramento, population: 39,538,223) and Texas (capital: Austin, population: 29,145,505) to the address book.", + "content": "Here is the information added:\n\n- **California**: Capital is Sacramento (Population: 39,538,223)\n- **Texas**: Capital is Austin (Population: 29,145,505)", "refusal": null, "annotations": [] }, @@ -228,9 +230,9 @@ http_interactions: } ], "usage": { - "prompt_tokens": 231, - "completion_tokens": 45, - "total_tokens": 276, + "prompt_tokens": 229, + "completion_tokens": 44, + "total_tokens": 273, "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 @@ -243,7 +245,7 @@ http_interactions: } }, "service_tier": "default", - "system_fingerprint": "fp_f7d56a8a2c" + "system_fingerprint": "fp_64e0ac9789" } - recorded_at: Mon, 14 Apr 2025 20:47:39 GMT + recorded_at: Mon, 14 Apr 2025 21:27:36 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml index 1d4b9e41..023e4c4c 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_anthropic_claude-3-5-haiku-20241022_handles_nested_object_parameters.yml @@ -30,7 +30,7 @@ http_interactions: message: Unauthorized headers: Date: - - Mon, 14 Apr 2025 20:46:38 GMT + - Mon, 14 Apr 2025 21:09:04 GMT Content-Type: - application/json Content-Length: @@ -55,5 +55,5 @@ http_interactions: encoding: UTF-8 string: '{"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}' - recorded_at: Mon, 14 Apr 2025 20:47:20 GMT + recorded_at: Mon, 14 Apr 2025 21:09:46 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml deleted file mode 100644 index 7e52033f..00000000 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_array_parameters_with_object_items.yml +++ /dev/null @@ -1,199 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke - body: - encoding: UTF-8 - string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add - information about California (capital: Sacramento, pop: 39538223) and Texas - (capital: Austin, pop: 29145505)"}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages - address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' - headers: - User-Agent: - - Faraday v2.12.2 - Host: - - bedrock-runtime..amazonaws.com - X-Amz-Date: - - 20250414T204725Z - X-Amz-Security-Token: - - "" - X-Amz-Content-Sha256: - - 9a3c99a37b5a0fbf8f93c72ff70fec06c4e0cf555e66909f91459d21e1fa8a89 - Authorization: - - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, - SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=d624bfcb5d75a9a93fc17464a1141e3c76783b01f397407ba4b4371b7013247c - Content-Type: - - application/json - Accept: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - response: - status: - code: 200 - message: OK - headers: - Date: - - Mon, 14 Apr 2025 20:46:46 GMT - Content-Type: - - application/json - Content-Length: - - '698' - Connection: - - keep-alive - X-Amzn-Requestid: - - 961a8679-bc93-4fe7-831a-2a76e846e775 - X-Amzn-Bedrock-Invocation-Latency: - - '2734' - X-Amzn-Bedrock-Output-Token-Count: - - '142' - X-Amzn-Bedrock-Input-Token-Count: - - '455' - body: - encoding: UTF-8 - string: '{"id":"msg_bdrk_01MEhNBuCytqRkJtHWt9d4SY","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ll - help you add information about California and Texas to the address book. I''ll - use the address_book function to add the capitals of these states.\n\nFirst, - let''s add Sacramento, California:"},{"type":"tool_use","id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","name":"address_book","input":{"contact":{"name":"Sacramento","address":{"street":"State - Capitol","city":"Sacramento","zip":"95814"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":455,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":142}}' - recorded_at: Mon, 14 Apr 2025 20:47:28 GMT -- request: - method: post - uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke - body: - encoding: UTF-8 - string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add - information about California (capital: Sacramento, pop: 39538223) and Texas - (capital: Austin, pop: 29145505)"},{"role":"assistant","content":[{"type":"text","text":"I''ll - help you add information about California and Texas to the address book. I''ll - use the address_book function to add the capitals of these states.\n\nFirst, - let''s add Sacramento, California:"},{"type":"tool_use","id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","name":"address_book","input":{"contact":{"name":"Sacramento","address":{"street":"State - Capitol","city":"Sacramento","zip":"95814"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","content":"Completed - contact: Sacramento at State Capitol, Sacramento 95814"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages - address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' - headers: - User-Agent: - - Faraday v2.12.2 - Host: - - bedrock-runtime..amazonaws.com - X-Amz-Date: - - 20250414T204728Z - X-Amz-Security-Token: - - "" - X-Amz-Content-Sha256: - - 706421bf40a7bc910c17f178b097504cc517c163fcf88c889c920c79b5f34b71 - Authorization: - - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, - SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=04d99a303079209b3bb77cb4f3ddd0540104d89bbf6afff506b634c7b3c2c614 - Content-Type: - - application/json - Accept: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - response: - status: - code: 200 - message: OK - headers: - Date: - - Mon, 14 Apr 2025 20:46:48 GMT - Content-Type: - - application/json - Content-Length: - - '465' - Connection: - - keep-alive - X-Amzn-Requestid: - - 2916cefd-da5e-4d30-9d56-3950dfa6ab8a - X-Amzn-Bedrock-Invocation-Latency: - - '1628' - X-Amzn-Bedrock-Output-Token-Count: - - '92' - X-Amzn-Bedrock-Input-Token-Count: - - '602' - body: - encoding: UTF-8 - string: '{"id":"msg_bdrk_016BvHFxNkm5hnxWTCim4FCQ","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"Now, - let''s add Austin, Texas:"},{"type":"tool_use","id":"toolu_bdrk_01VDVnFxaVAXZ1ix78L6vftL","name":"address_book","input":{"contact":{"name":"Austin","address":{"street":"State - Capitol","city":"Austin","zip":"78701"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":602,"output_tokens":92}}' - recorded_at: Mon, 14 Apr 2025 20:47:30 GMT -- request: - method: post - uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke - body: - encoding: UTF-8 - string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add - information about California (capital: Sacramento, pop: 39538223) and Texas - (capital: Austin, pop: 29145505)"},{"role":"assistant","content":[{"type":"text","text":"I''ll - help you add information about California and Texas to the address book. I''ll - use the address_book function to add the capitals of these states.\n\nFirst, - let''s add Sacramento, California:"},{"type":"tool_use","id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","name":"address_book","input":{"contact":{"name":"Sacramento","address":{"street":"State - Capitol","city":"Sacramento","zip":"95814"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01E8VdwdULsTyopHcsVSJmGS","content":"Completed - contact: Sacramento at State Capitol, Sacramento 95814"}]},{"role":"assistant","content":[{"type":"text","text":"Now, - let''s add Austin, Texas:"},{"type":"tool_use","id":"toolu_bdrk_01VDVnFxaVAXZ1ix78L6vftL","name":"address_book","input":{"contact":{"name":"Austin","address":{"street":"State - Capitol","city":"Austin","zip":"78701"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01VDVnFxaVAXZ1ix78L6vftL","content":"Completed - contact: Austin at State Capitol, Austin 78701"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages - address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact - information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address - details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City - name"},"zip":{"type":"string","description":"ZIP/Postal code"}}}}}},"required":["contact"]}}]}' - headers: - User-Agent: - - Faraday v2.12.2 - Host: - - bedrock-runtime..amazonaws.com - X-Amz-Date: - - 20250414T204730Z - X-Amz-Security-Token: - - "" - X-Amz-Content-Sha256: - - 8154cb3f09a327a022f1d09f0159f9c7d19101000816e45b4fe569b0e46714d3 - Authorization: - - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, - SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=e8cd3ebea5961b0aacc8f538dcf2d3eb64654c8da4464fcf8c8518420d9d2409 - Content-Type: - - application/json - Accept: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - response: - status: - code: 200 - message: OK - headers: - Date: - - Mon, 14 Apr 2025 20:46:51 GMT - Content-Type: - - application/json - Content-Length: - - '741' - Connection: - - keep-alive - X-Amzn-Requestid: - - 62cb4af4-ee1b-41ab-9ca6-e8ce0e82aedd - X-Amzn-Bedrock-Invocation-Latency: - - '3231' - X-Amzn-Bedrock-Output-Token-Count: - - '101' - X-Amzn-Bedrock-Input-Token-Count: - - '718' - body: - encoding: UTF-8 - string: '{"id":"msg_bdrk_011fpnzH1AJV2ho9ine3DPeF","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ve - added the capitals of California (Sacramento) and Texas (Austin) to the address - book. I included their respective state capitol addresses and ZIP codes. \n\nNote: - While you provided population information (California: 39,538,223 and Texas: - 29,145,505), the address_book function doesn''t have a field for population, - so I couldn''t include that specific detail.\n\nIs there anything else you - would like me to do with these entries?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":718,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":101}}' - recorded_at: Mon, 14 Apr 2025 20:47:33 GMT -recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml index 09d5597e..364e28c8 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_bedrock_anthropic_claude-3-5-haiku-20241022-v1_0_handles_nested_object_parameters.yml @@ -17,14 +17,14 @@ http_interactions: Host: - bedrock-runtime..amazonaws.com X-Amz-Date: - - 20250414T204720Z + - 20250414T210946Z X-Amz-Security-Token: - "" X-Amz-Content-Sha256: - 20bc836937097802a104c9ae3c86ad4f5f74750c68d26050182b4720a23eba7b Authorization: - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, - SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=b4eb6b38805ab9215646872131465a6e8e0167d18a5d94ab4c5626123696a809 + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=a5df834cb610f068397cb62fe151c75110efa170b1fe4a42ce795d46a3705e61 Content-Type: - application/json Accept: @@ -37,28 +37,28 @@ http_interactions: message: OK headers: Date: - - Mon, 14 Apr 2025 20:46:41 GMT + - Mon, 14 Apr 2025 21:09:06 GMT Content-Type: - application/json Content-Length: - - '649' + - '655' Connection: - keep-alive X-Amzn-Requestid: - - 34d437ea-ca44-4187-96a4-8a9d8a565707 + - 5e77035b-9fb7-4f9a-a5d7-31d91b879490 X-Amzn-Bedrock-Invocation-Latency: - - '2088' + - '2425' X-Amzn-Bedrock-Output-Token-Count: - - '137' + - '140' X-Amzn-Bedrock-Input-Token-Count: - '444' body: encoding: UTF-8 - string: '{"id":"msg_bdrk_01V7R3B9gE4F7vhXQP3m4zug","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ll + string: '{"id":"msg_bdrk_01Ko7AtCEYwWGeWASuiHmuSq","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ll help you add John Doe to the address book using the `address_book` function. - I''ll structure the contact information with the provided details."},{"type":"tool_use","id":"toolu_bdrk_01AyRobTeGqtRsWYUH9zJEZS","name":"address_book","input":{"contact":{"name":"John - Doe","address":{"street":"123 Main St","city":"Springfield","zip":"12345"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":444,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":137}}' - recorded_at: Mon, 14 Apr 2025 20:47:23 GMT + I''ll parse the address details you provided and create a contact entry."},{"type":"tool_use","id":"toolu_bdrk_016zu287CPSP7fc7whbMpAZm","name":"address_book","input":{"contact":{"name":"John + Doe","address":{"street":"123 Main St","city":"Springfield","zip":"12345"}}}}],"stop_reason":"tool_use","stop_sequence":null,"usage":{"input_tokens":444,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":140}}' + recorded_at: Mon, 14 Apr 2025 21:09:48 GMT - request: method: post uri: https://bedrock-runtime..amazonaws.com/model/anthropic.claude-3-5-haiku-20241022-v1:0/invoke @@ -67,8 +67,8 @@ http_interactions: string: '{"anthropic_version":"bedrock-2023-05-31","messages":[{"role":"user","content":"Add John Doe to the address book at 123 Main St, Springfield 12345"},{"role":"assistant","content":[{"type":"text","text":"I''ll help you add John Doe to the address book using the `address_book` function. - I''ll structure the contact information with the provided details."},{"type":"tool_use","id":"toolu_bdrk_01AyRobTeGqtRsWYUH9zJEZS","name":"address_book","input":{"contact":{"name":"John - Doe","address":{"street":"123 Main St","city":"Springfield","zip":"12345"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_01AyRobTeGqtRsWYUH9zJEZS","content":"Completed + I''ll parse the address details you provided and create a contact entry."},{"type":"tool_use","id":"toolu_bdrk_016zu287CPSP7fc7whbMpAZm","name":"address_book","input":{"contact":{"name":"John + Doe","address":{"street":"123 Main St","city":"Springfield","zip":"12345"}}}}]},{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_bdrk_016zu287CPSP7fc7whbMpAZm","content":"Completed contact: John Doe at 123 Main St, Springfield 12345"}]}],"temperature":0.7,"max_tokens":4096,"tools":[{"name":"address_book","description":"Manages address book entries","input_schema":{"type":"object","properties":{"contact":{"type":"object","description":"Contact information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address @@ -80,14 +80,14 @@ http_interactions: Host: - bedrock-runtime..amazonaws.com X-Amz-Date: - - 20250414T204723Z + - 20250414T210948Z X-Amz-Security-Token: - "" X-Amz-Content-Sha256: - - 30fec609f54ff4603ea7ddc10cca5a6bc14dbc507e38f49c2632939f55d68254 + - 2826a3b34811574291899c05638d0d60f20dc746eeb29235ced9f7fc1e09ed94 Authorization: - AWS4-HMAC-SHA256 Credential=/20250414//bedrock/aws4_request, - SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=34e01c96541c9033acba54f7a9cab03bdcba5e857eb9a20b916fa834d16b74f7 + SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=7475450c7cd8c01a696d678566c9b4677f18f452d9925d4f28be69d5d4cbf934 Content-Type: - application/json Accept: @@ -100,25 +100,27 @@ http_interactions: message: OK headers: Date: - - Mon, 14 Apr 2025 20:46:43 GMT + - Mon, 14 Apr 2025 21:09:08 GMT Content-Type: - application/json Content-Length: - - '396' + - '542' Connection: - keep-alive X-Amzn-Requestid: - - 2592ff66-4c64-4e06-976d-004b3092da44 + - fb2c2301-2178-4b18-8f3f-2702d4fc5ea7 X-Amzn-Bedrock-Invocation-Latency: - - '2310' + - '1306' X-Amzn-Bedrock-Output-Token-Count: - - '40' + - '66' X-Amzn-Bedrock-Input-Token-Count: - - '591' + - '594' body: encoding: UTF-8 - string: '{"id":"msg_bdrk_01FiYNJNLTztpP468zXDEVJA","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"John - Doe has been successfully added to the address book with the address 123 Main - St, Springfield, 12345. Is there anything else I can help you with?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":591,"output_tokens":40}}' - recorded_at: Mon, 14 Apr 2025 20:47:25 GMT + string: '{"id":"msg_bdrk_01EB71hKVYvuo5J2f9B2rpXm","type":"message","role":"assistant","model":"claude-3-5-haiku-20241022","content":[{"type":"text","text":"I''ve + added John Doe to the address book with the following details:\n- Name: John + Doe\n- Street: 123 Main St\n- City: Springfield\n- ZIP Code: 12345\n\nThe + contact has been successfully saved. Is there anything else I can help you + with?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":594,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":66}}' + recorded_at: Mon, 14 Apr 2025 21:09:50 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml index e6c0ff18..0dbfecef 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_deepseek_deepseek-chat_handles_nested_object_parameters.yml @@ -28,7 +28,7 @@ http_interactions: message: Unauthorized headers: Date: - - Mon, 14 Apr 2025 20:46:53 GMT + - Mon, 14 Apr 2025 21:09:10 GMT Content-Type: - application/json Content-Length: @@ -40,7 +40,7 @@ http_interactions: Access-Control-Allow-Credentials: - 'true' X-Ds-Trace-Id: - - 84b81fd025e92bfafd31a16d05806bce + - 1637f04e185f05aae40972a845805bf2 Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload X-Content-Type-Options: @@ -56,5 +56,5 @@ http_interactions: body: encoding: UTF-8 string: '{"error":{"message":"Authentication Fails, Your api key: test is invalid","type":"authentication_error","param":null,"code":"invalid_request_error"}}' - recorded_at: Mon, 14 Apr 2025 20:47:35 GMT + recorded_at: Mon, 14 Apr 2025 21:09:52 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml deleted file mode 100644 index 3dd635a5..00000000 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_array_parameters_with_object_items.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent - body: - encoding: UTF-8 - string: '{"contents":[{"role":"user","parts":[{"text":"Add information about - California (capital: Sacramento, pop: 39538223) and Texas (capital: Austin, - pop: 29145505)"}]}],"generationConfig":{"temperature":0.7},"tools":[{"functionDeclarations":[{"name":"address_book","description":"Manages - address book entries","parameters":{"type":"OBJECT","properties":{"contact":{"type":"OBJECT","description":"Contact - information","properties":{"name":{"type":"STRING","description":"Full name"},"address":{"type":"OBJECT","description":"Address - details"}}}},"required":["contact"]}}]}]}' - headers: - User-Agent: - - Faraday v2.12.2 - X-Goog-Api-Key: - - test - Content-Type: - - application/json - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - response: - status: - code: 400 - message: Bad Request - headers: - Vary: - - Origin - - Referer - - X-Origin - Content-Type: - - application/json; charset=UTF-8 - Date: - - Mon, 14 Apr 2025 20:46:52 GMT - Server: - - scaffolding on HTTPServer2 - X-Xss-Protection: - - '0' - X-Frame-Options: - - SAMEORIGIN - X-Content-Type-Options: - - nosniff - Server-Timing: - - gfet4t7; dur=25 - Alt-Svc: - - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 - Transfer-Encoding: - - chunked - body: - encoding: ASCII-8BIT - string: | - { - "error": { - "code": 400, - "message": "API key not valid. Please pass a valid API key.", - "status": "INVALID_ARGUMENT", - "details": [ - { - "@type": "type.googleapis.com/google.rpc.ErrorInfo", - "reason": "API_KEY_INVALID", - "domain": "googleapis.com", - "metadata": { - "service": "generativelanguage.googleapis.com" - } - }, - { - "@type": "type.googleapis.com/google.rpc.LocalizedMessage", - "locale": "en-US", - "message": "API key not valid. Please pass a valid API key." - } - ] - } - } - recorded_at: Mon, 14 Apr 2025 20:47:34 GMT -recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml index 28e71a86..8e57884b 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_gemini_gemini-2_0-flash_handles_nested_object_parameters.yml @@ -14,7 +14,7 @@ http_interactions: User-Agent: - Faraday v2.12.2 X-Goog-Api-Key: - - test + - "" Content-Type: - application/json Accept-Encoding: @@ -23,17 +23,117 @@ http_interactions: - "*/*" response: status: - code: 400 - message: Bad Request + code: 200 + message: OK headers: + Content-Type: + - application/json; charset=UTF-8 Vary: - Origin - Referer - X-Origin + Date: + - Mon, 14 Apr 2025 21:09:09 GMT + Server: + - scaffolding on HTTPServer2 + X-Xss-Protection: + - '0' + X-Frame-Options: + - SAMEORIGIN + X-Content-Type-Options: + - nosniff + Server-Timing: + - gfet4t7; dur=701 + Alt-Svc: + - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: | + { + "candidates": [ + { + "content": { + "parts": [ + { + "functionCall": { + "name": "address_book", + "args": { + "contact": { + "address": { + "zip": "12345", + "city": "Springfield", + "street": "123 Main St" + }, + "name": "John Doe" + } + } + } + } + ], + "role": "model" + }, + "finishReason": "STOP", + "avgLogprobs": -0.048165299675681374 + } + ], + "usageMetadata": { + "promptTokenCount": 40, + "candidatesTokenCount": 22, + "totalTokenCount": 62, + "promptTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 40 + } + ], + "candidatesTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 22 + } + ] + }, + "modelVersion": "gemini-2.0-flash" + } + recorded_at: Mon, 14 Apr 2025 21:09:51 GMT +- request: + method: post + uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent + body: + encoding: UTF-8 + string: '{"contents":[{"role":"user","parts":[{"text":"Add John Doe to the address + book at 123 Main St, Springfield 12345"}]},{"role":"model","parts":[{"functionCall":{"name":"address_book","args":{"contact":{"address":{"zip":"12345","city":"Springfield","street":"123 + Main St"},"name":"John Doe"}}}}]},{"role":"user","parts":[{"functionResponse":{"name":"fa7e318e-60b9-443a-b9fb-064beb07def1","response":{"name":"fa7e318e-60b9-443a-b9fb-064beb07def1","content":"Completed + contact: John Doe at 123 Main St, Springfield 12345"}}}]}],"generationConfig":{"temperature":0.7},"tools":[{"functionDeclarations":[{"name":"address_book","description":"Manages + address book entries","parameters":{"type":"OBJECT","properties":{"contact":{"type":"OBJECT","description":"Contact + information","properties":{"name":{"type":"STRING","description":"Full name"},"address":{"type":"OBJECT","description":"Address + details"}}}},"required":["contact"]}}]}]}' + headers: + User-Agent: + - Faraday v2.12.2 + X-Goog-Api-Key: + - "" + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: Content-Type: - application/json; charset=UTF-8 + Vary: + - Origin + - Referer + - X-Origin Date: - - Mon, 14 Apr 2025 20:46:52 GMT + - Mon, 14 Apr 2025 21:09:09 GMT Server: - scaffolding on HTTPServer2 X-Xss-Protection: @@ -43,7 +143,7 @@ http_interactions: X-Content-Type-Options: - nosniff Server-Timing: - - gfet4t7; dur=140 + - gfet4t7; dur=582 Alt-Svc: - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 Transfer-Encoding: @@ -52,26 +152,38 @@ http_interactions: encoding: ASCII-8BIT string: | { - "error": { - "code": 400, - "message": "API key not valid. Please pass a valid API key.", - "status": "INVALID_ARGUMENT", - "details": [ - { - "@type": "type.googleapis.com/google.rpc.ErrorInfo", - "reason": "API_KEY_INVALID", - "domain": "googleapis.com", - "metadata": { - "service": "generativelanguage.googleapis.com" - } + "candidates": [ + { + "content": { + "parts": [ + { + "text": "OK. I've added John Doe to the address book at 123 Main St, Springfield 12345.\n" + } + ], + "role": "model" }, + "finishReason": "STOP", + "avgLogprobs": -2.87032814632202e-06 + } + ], + "usageMetadata": { + "promptTokenCount": 144, + "candidatesTokenCount": 29, + "totalTokenCount": 173, + "promptTokensDetails": [ + { + "modality": "TEXT", + "tokenCount": 144 + } + ], + "candidatesTokensDetails": [ { - "@type": "type.googleapis.com/google.rpc.LocalizedMessage", - "locale": "en-US", - "message": "API key not valid. Please pass a valid API key." + "modality": "TEXT", + "tokenCount": 29 } ] - } + }, + "modelVersion": "gemini-2.0-flash" } - recorded_at: Mon, 14 Apr 2025 20:47:34 GMT + recorded_at: Mon, 14 Apr 2025 21:09:51 GMT recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml index 78f83bbf..cc236ea3 100644 --- a/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml +++ b/spec/fixtures/vcr_cassettes/chat_nested_parameters_with_openai_gpt-4o-mini_handles_nested_object_parameters.yml @@ -28,7 +28,7 @@ http_interactions: message: OK headers: Date: - - Mon, 14 Apr 2025 20:46:54 GMT + - Mon, 14 Apr 2025 21:09:11 GMT Content-Type: - application/json Transfer-Encoding: @@ -40,7 +40,7 @@ http_interactions: Openai-Organization: - "" Openai-Processing-Ms: - - '524' + - '800' Openai-Version: - '2020-10-01' X-Ratelimit-Limit-Requests: @@ -76,9 +76,9 @@ http_interactions: encoding: ASCII-8BIT string: | { - "id": "chatcmpl-BMKzd7UzWUI2tpCrAbEwYOuh8Jq6x", + "id": "chatcmpl-BMLLCcjzvidhHBtxez6XVPcNgczrE", "object": "chat.completion", - "created": 1744663613, + "created": 1744664950, "model": "gpt-4o-mini-2024-07-18", "choices": [ { @@ -88,7 +88,7 @@ http_interactions: "content": null, "tool_calls": [ { - "id": "call_xijRRP0wRf1Bd0N6WTi5jBx4", + "id": "call_cAycKaaDWaCzemZl97fq37Ei", "type": "function", "function": { "name": "address_book", @@ -121,16 +121,16 @@ http_interactions: "service_tier": "default", "system_fingerprint": "fp_f7d56a8a2c" } - recorded_at: Mon, 14 Apr 2025 20:47:36 GMT + recorded_at: Mon, 14 Apr 2025 21:09:53 GMT - request: method: post uri: https://api.openai.com/v1/chat/completions body: encoding: UTF-8 string: '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Add John - Doe to the address book at 123 Main St, Springfield 12345"},{"role":"assistant","tool_calls":[{"id":"call_xijRRP0wRf1Bd0N6WTi5jBx4","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"John + Doe to the address book at 123 Main St, Springfield 12345"},{"role":"assistant","tool_calls":[{"id":"call_cAycKaaDWaCzemZl97fq37Ei","type":"function","function":{"name":"address_book","arguments":"{\"contact\":{\"name\":\"John Doe\",\"address\":{\"street\":\"123 Main St\",\"city\":\"Springfield\",\"zip\":\"12345\"}}}"}}]},{"role":"tool","content":"Completed - contact: John Doe at 123 Main St, Springfield 12345","tool_call_id":"call_xijRRP0wRf1Bd0N6WTi5jBx4"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages + contact: John Doe at 123 Main St, Springfield 12345","tool_call_id":"call_cAycKaaDWaCzemZl97fq37Ei"}],"temperature":0.7,"stream":false,"tools":[{"type":"function","function":{"name":"address_book","description":"Manages address book entries","parameters":{"type":"object","properties":{"contact":{"type":"object","description":"Contact information","properties":{"name":{"type":"string","description":"Full name"},"address":{"type":"object","description":"Address details","properties":{"street":{"type":"string","description":"Street address"},"city":{"type":"string","description":"City @@ -152,7 +152,7 @@ http_interactions: message: OK headers: Date: - - Mon, 14 Apr 2025 20:46:55 GMT + - Mon, 14 Apr 2025 21:09:11 GMT Content-Type: - application/json Transfer-Encoding: @@ -164,7 +164,7 @@ http_interactions: Openai-Organization: - "" Openai-Processing-Ms: - - '580' + - '464' Openai-Version: - '2020-10-01' X-Ratelimit-Limit-Requests: @@ -200,16 +200,16 @@ http_interactions: encoding: ASCII-8BIT string: | { - "id": "chatcmpl-BMKzeYZaqeijDaZOViMbYh5HfHPRi", + "id": "chatcmpl-BMLLDEPQfYItQFOa2G0mMQE7xT6Y1", "object": "chat.completion", - "created": 1744663614, + "created": 1744664951, "model": "gpt-4o-mini-2024-07-18", "choices": [ { "index": 0, "message": { "role": "assistant", - "content": "John Doe has been successfully added to the address book at 123 Main St, Springfield 12345.", + "content": "John Doe has been successfully added to the address book with the address 123 Main St, Springfield 12345.", "refusal": null, "annotations": [] }, @@ -219,8 +219,8 @@ http_interactions: ], "usage": { "prompt_tokens": 160, - "completion_tokens": 23, - "total_tokens": 183, + "completion_tokens": 25, + "total_tokens": 185, "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 @@ -235,5 +235,5 @@ http_interactions: "service_tier": "default", "system_fingerprint": "fp_f7d56a8a2c" } - recorded_at: Mon, 14 Apr 2025 20:47:37 GMT + recorded_at: Mon, 14 Apr 2025 21:09:53 GMT recorded_with: VCR 6.3.1 diff --git a/spec/ruby_llm/chat_tools_spec.rb b/spec/ruby_llm/chat_tools_spec.rb index 3640427f..770ffc32 100644 --- a/spec/ruby_llm/chat_tools_spec.rb +++ b/spec/ruby_llm/chat_tools_spec.rb @@ -97,6 +97,8 @@ class StateManager < RubyLLM::Tool # rubocop:disable Lint/ConstantDefinitionInBl } def execute(states:) + return 'No states provided' if states.empty? + states.map { |s| "#{s['name']}: Capital is #{s['capital']} (pop: #{s['population']})" }.join("\n") end end @@ -205,14 +207,27 @@ def execute(states:) expect(response.content).to include('John Doe', '123 Main St', 'Springfield', '12345') end + end + end + end + + describe 'array parameters' do + chat_models.each do |model| + provider = RubyLLM::Models.provider_for(model).slug + + context "with #{provider}/#{model}" do + let(:chat) { RubyLLM.chat(model: model).with_tool(StateManager) } + let(:prompt) do + 'Add information about California (capital: Sacramento, ' \ + 'pop: 39538223) and Texas (capital: Austin, pop: 29145505). ' \ + 'Make sure to return all the information in the final output. ' + end it 'handles array parameters with object items', :aggregate_failures do - prompt = 'Add information about California (capital: Sacramento, ' \ - 'pop: 39538223) and Texas (capital: Austin, pop: 29145505).' response = chat.ask(prompt) - expect(response.content).to include('Sacramento', 'Austin', - '39,538,223', '29,145,505') + expect(response.content).to include('Sacramento', 'Austin') + expect(response.content).to match(/39538223|39,538,223/).and(match(/29145505|29,145,505/)) end end end