Module: RubyLLM::Providers::OpenAIResponses::BuiltInTools
- Defined in:
- lib/ruby_llm/providers/openai_responses/built_in_tools.rb
Overview
Built-in tools support for the OpenAI Responses API. Provides configuration helpers and result parsing for:
-
Web Search
-
File Search
-
Code Interpreter
-
Image Generation
-
MCP (Model Context Protocol)
Class Method Summary collapse
-
.code_interpreter(container_type: 'auto') ⇒ Object
Code Interpreter tool configuration.
-
.computer_use(display_width:, display_height:, environment: 'browser') ⇒ Object
Computer Use tool configuration (preview).
-
.extract_citations(content) ⇒ Array<Hash>
Extract all citations from message content.
-
.file_search(vector_store_ids:, max_num_results: nil, ranking_options: nil) ⇒ Object
File Search tool configuration.
-
.image_generation(partial_images: nil) ⇒ Object
Image Generation tool configuration.
-
.mcp(server_label:, server_url:, require_approval: 'never', allowed_tools: nil, headers: nil) ⇒ Object
MCP (Model Context Protocol) tool configuration.
-
.parse_code_interpreter_results(output) ⇒ Array<Hash>
Parse code interpreter results from output.
-
.parse_file_search_results(output) ⇒ Array<Hash>
Parse file search results from output.
-
.parse_image_generation_results(output) ⇒ Array<Hash>
Parse image generation results from output.
-
.parse_web_search_results(output) ⇒ Array<Hash>
Parse web search results from output.
-
.web_search(search_context_size: nil, user_location: nil) ⇒ Object
Web Search tool configuration.
Class Method Details
.code_interpreter(container_type: 'auto') ⇒ Object
Code Interpreter tool configuration
42 43 44 45 46 47 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 42 def code_interpreter(container_type: 'auto') { type: 'code_interpreter', container: { type: container_type } } end |
.computer_use(display_width:, display_height:, environment: 'browser') ⇒ Object
Computer Use tool configuration (preview)
79 80 81 82 83 84 85 86 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 79 def computer_use(display_width:, display_height:, environment: 'browser') { type: 'computer_use_preview', display_width: display_width, display_height: display_height, environment: environment } end |
.extract_citations(content) ⇒ Array<Hash>
Extract all citations from message content
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 152 def extract_citations(content) return [] unless content.is_a?(Array) content .select { |c| c['type'] == 'output_text' } .flat_map { |c| c['annotations'] || [] } .map do |annotation| { type: annotation['type'], text: annotation['text'], url: annotation['url'], title: annotation['title'], start_index: annotation['start_index'], end_index: annotation['end_index'] }.compact end end |
.file_search(vector_store_ids:, max_num_results: nil, ranking_options: nil) ⇒ Object
File Search tool configuration
30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 30 def file_search(vector_store_ids:, max_num_results: nil, ranking_options: nil) tool = { type: 'file_search', vector_store_ids: Array(vector_store_ids) } tool[:max_num_results] = max_num_results if max_num_results tool[:ranking_options] = if tool end |
.image_generation(partial_images: nil) ⇒ Object
Image Generation tool configuration
51 52 53 54 55 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 51 def image_generation(partial_images: nil) tool = { type: 'image_generation' } tool[:partial_images] = partial_images if partial_images tool end |
.mcp(server_label:, server_url:, require_approval: 'never', allowed_tools: nil, headers: nil) ⇒ Object
MCP (Model Context Protocol) tool configuration
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 63 def mcp(server_label:, server_url:, require_approval: 'never', allowed_tools: nil, headers: nil) tool = { type: 'mcp', server_label: server_label, server_url: server_url, require_approval: require_approval } tool[:allowed_tools] = allowed_tools if allowed_tools tool[:headers] = headers if headers tool end |
.parse_code_interpreter_results(output) ⇒ Array<Hash>
Parse code interpreter results from output
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 121 def parse_code_interpreter_results(output) output .select { |item| item['type'] == 'code_interpreter_call' } .map do |item| { id: item['id'], code: item['code'], results: item['results'] || [], container_id: item['container_id'] } end end |
.parse_file_search_results(output) ⇒ Array<Hash>
Parse file search results from output
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 106 def parse_file_search_results(output) output .select { |item| item['type'] == 'file_search_call' } .map do |item| { id: item['id'], status: item['status'], results: item['results'] || [] } end end |
.parse_image_generation_results(output) ⇒ Array<Hash>
Parse image generation results from output
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 137 def parse_image_generation_results(output) output .select { |item| item['type'] == 'image_generation_call' } .map do |item| { id: item['id'], status: item['status'], result: item['result'] } end end |
.parse_web_search_results(output) ⇒ Array<Hash>
Parse web search results from output
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 91 def parse_web_search_results(output) output .select { |item| item['type'] == 'web_search_call' } .map do |item| { id: item['id'], status: item['status'], results: parse_citations(item) } end end |
.web_search(search_context_size: nil, user_location: nil) ⇒ Object
Web Search tool configuration
19 20 21 22 23 24 |
# File 'lib/ruby_llm/providers/openai_responses/built_in_tools.rb', line 19 def web_search(search_context_size: nil, user_location: nil) tool = { type: 'web_search_preview' } tool[:search_context_size] = search_context_size if search_context_size tool[:user_location] = user_location if user_location tool end |