openai 0.18.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +1 -1
  4. data/lib/openai/client.rb +4 -0
  5. data/lib/openai/helpers/structured_output/boolean.rb +1 -0
  6. data/lib/openai/internal/conversation_cursor_page.rb +92 -0
  7. data/lib/openai/internal/transport/base_client.rb +1 -4
  8. data/lib/openai/internal/transport/pooled_net_requester.rb +1 -9
  9. data/lib/openai/internal/util.rb +1 -1
  10. data/lib/openai/models/audio/transcription.rb +1 -4
  11. data/lib/openai/models/audio/transcription_create_params.rb +2 -7
  12. data/lib/openai/models/audio/transcription_text_done_event.rb +1 -4
  13. data/lib/openai/models/beta/assistant_create_params.rb +6 -19
  14. data/lib/openai/models/beta/assistant_stream_event.rb +6 -24
  15. data/lib/openai/models/beta/assistant_update_params.rb +1 -4
  16. data/lib/openai/models/beta/message_stream_event.rb +1 -4
  17. data/lib/openai/models/beta/run_step_stream_event.rb +1 -4
  18. data/lib/openai/models/beta/thread_create_and_run_params.rb +10 -32
  19. data/lib/openai/models/beta/thread_create_params.rb +7 -22
  20. data/lib/openai/models/beta/threads/message.rb +3 -10
  21. data/lib/openai/models/beta/threads/message_create_params.rb +2 -7
  22. data/lib/openai/models/beta/threads/run.rb +2 -7
  23. data/lib/openai/models/beta/threads/run_create_params.rb +3 -10
  24. data/lib/openai/models/beta/threads/run_submit_tool_outputs_params.rb +1 -3
  25. data/lib/openai/models/beta/threads/runs/code_interpreter_tool_call.rb +5 -17
  26. data/lib/openai/models/beta/threads/runs/code_interpreter_tool_call_delta.rb +1 -3
  27. data/lib/openai/models/beta/threads/runs/file_search_tool_call.rb +4 -12
  28. data/lib/openai/models/beta/threads/runs/run_step_delta_message_delta.rb +1 -4
  29. data/lib/openai/models/beta/threads/runs/tool_calls_step_details.rb +1 -4
  30. data/lib/openai/models/beta/threads/text.rb +1 -4
  31. data/lib/openai/models/chat/chat_completion_chunk.rb +1 -3
  32. data/lib/openai/models/chat/chat_completion_custom_tool.rb +2 -7
  33. data/lib/openai/models/chat/chat_completion_message.rb +7 -5
  34. data/lib/openai/models/chat/chat_completion_message_function_tool_call.rb +7 -5
  35. data/lib/openai/models/conversations/computer_screenshot_content.rb +38 -0
  36. data/lib/openai/models/conversations/container_file_citation_body.rb +58 -0
  37. data/lib/openai/models/conversations/conversation.rb +51 -0
  38. data/lib/openai/models/conversations/conversation_create_params.rb +39 -0
  39. data/lib/openai/models/conversations/conversation_delete_params.rb +16 -0
  40. data/lib/openai/models/conversations/conversation_deleted.rb +29 -0
  41. data/lib/openai/models/conversations/conversation_deleted_resource.rb +30 -0
  42. data/lib/openai/models/conversations/conversation_item.rb +568 -0
  43. data/lib/openai/models/conversations/conversation_item_list.rb +55 -0
  44. data/lib/openai/models/conversations/conversation_retrieve_params.rb +16 -0
  45. data/lib/openai/models/conversations/conversation_update_params.rb +31 -0
  46. data/lib/openai/models/conversations/file_citation_body.rb +42 -0
  47. data/lib/openai/models/conversations/input_file_content.rb +42 -0
  48. data/lib/openai/models/conversations/input_image_content.rb +62 -0
  49. data/lib/openai/models/conversations/input_text_content.rb +26 -0
  50. data/lib/openai/models/conversations/item_create_params.rb +37 -0
  51. data/lib/openai/models/conversations/item_delete_params.rb +22 -0
  52. data/lib/openai/models/conversations/item_list_params.rb +86 -0
  53. data/lib/openai/models/conversations/item_retrieve_params.rb +36 -0
  54. data/lib/openai/models/conversations/lob_prob.rb +35 -0
  55. data/lib/openai/models/conversations/message.rb +115 -0
  56. data/lib/openai/models/conversations/output_text_content.rb +57 -0
  57. data/lib/openai/models/conversations/refusal_content.rb +26 -0
  58. data/lib/openai/models/conversations/summary_text_content.rb +23 -0
  59. data/lib/openai/models/conversations/text_content.rb +23 -0
  60. data/lib/openai/models/conversations/top_log_prob.rb +29 -0
  61. data/lib/openai/models/conversations/url_citation_body.rb +50 -0
  62. data/lib/openai/models/eval_create_params.rb +6 -20
  63. data/lib/openai/models/evals/create_eval_completions_run_data_source.rb +29 -53
  64. data/lib/openai/models/evals/create_eval_jsonl_run_data_source.rb +1 -3
  65. data/lib/openai/models/evals/run_cancel_response.rb +2 -2
  66. data/lib/openai/models/evals/run_create_params.rb +20 -56
  67. data/lib/openai/models/evals/run_create_response.rb +2 -2
  68. data/lib/openai/models/evals/run_list_response.rb +2 -2
  69. data/lib/openai/models/evals/run_retrieve_response.rb +2 -2
  70. data/lib/openai/models/fine_tuning/reinforcement_hyperparameters.rb +1 -4
  71. data/lib/openai/models/moderation.rb +5 -15
  72. data/lib/openai/models/responses/input_item_list_params.rb +1 -9
  73. data/lib/openai/models/responses/response.rb +28 -3
  74. data/lib/openai/models/responses/response_computer_tool_call.rb +2 -6
  75. data/lib/openai/models/responses/response_computer_tool_call_output_item.rb +1 -3
  76. data/lib/openai/models/responses/response_conversation_param.rb +20 -0
  77. data/lib/openai/models/responses/response_create_params.rb +38 -3
  78. data/lib/openai/models/responses/response_function_tool_call.rb +7 -5
  79. data/lib/openai/models/responses/response_function_web_search.rb +35 -1
  80. data/lib/openai/models/responses/response_includable.rb +2 -0
  81. data/lib/openai/models/responses/response_input_item.rb +2 -7
  82. data/lib/openai/models/responses/response_input_message_item.rb +1 -4
  83. data/lib/openai/models/responses/response_output_item.rb +1 -3
  84. data/lib/openai/models/responses/response_output_message.rb +1 -3
  85. data/lib/openai/models/responses/response_output_text.rb +10 -15
  86. data/lib/openai/models/responses/response_stream_event.rb +4 -16
  87. data/lib/openai/models/responses/response_text_delta_event.rb +1 -3
  88. data/lib/openai/models/responses/response_text_done_event.rb +1 -3
  89. data/lib/openai/models/responses/tool.rb +303 -35
  90. data/lib/openai/models.rb +2 -0
  91. data/lib/openai/resources/conversations/items.rb +141 -0
  92. data/lib/openai/resources/conversations.rb +112 -0
  93. data/lib/openai/resources/responses/input_items.rb +1 -3
  94. data/lib/openai/resources/responses.rb +8 -4
  95. data/lib/openai/version.rb +1 -1
  96. data/lib/openai.rb +31 -0
  97. data/rbi/openai/client.rbi +3 -0
  98. data/rbi/openai/errors.rbi +5 -5
  99. data/rbi/openai/internal/conversation_cursor_page.rbi +25 -0
  100. data/rbi/openai/models/conversations/computer_screenshot_content.rbi +60 -0
  101. data/rbi/openai/models/conversations/container_file_citation_body.rbi +82 -0
  102. data/rbi/openai/models/conversations/conversation.rbi +76 -0
  103. data/rbi/openai/models/conversations/conversation_create_params.rbi +144 -0
  104. data/rbi/openai/models/conversations/conversation_delete_params.rbi +32 -0
  105. data/rbi/openai/models/conversations/conversation_deleted.rbi +40 -0
  106. data/rbi/openai/models/conversations/conversation_deleted_resource.rbi +40 -0
  107. data/rbi/openai/models/conversations/conversation_item.rbi +835 -0
  108. data/rbi/openai/models/conversations/conversation_item_list.rbi +101 -0
  109. data/rbi/openai/models/conversations/conversation_retrieve_params.rbi +32 -0
  110. data/rbi/openai/models/conversations/conversation_update_params.rbi +56 -0
  111. data/rbi/openai/models/conversations/file_citation_body.rbi +61 -0
  112. data/rbi/openai/models/conversations/input_file_content.rbi +72 -0
  113. data/rbi/openai/models/conversations/input_image_content.rbi +113 -0
  114. data/rbi/openai/models/conversations/input_text_content.rbi +38 -0
  115. data/rbi/openai/models/conversations/item_create_params.rbi +150 -0
  116. data/rbi/openai/models/conversations/item_delete_params.rbi +40 -0
  117. data/rbi/openai/models/conversations/item_list_params.rbi +178 -0
  118. data/rbi/openai/models/conversations/item_retrieve_params.rbi +70 -0
  119. data/rbi/openai/models/conversations/lob_prob.rbi +50 -0
  120. data/rbi/openai/models/conversations/message.rbi +196 -0
  121. data/rbi/openai/models/conversations/output_text_content.rbi +110 -0
  122. data/rbi/openai/models/conversations/refusal_content.rbi +38 -0
  123. data/rbi/openai/models/conversations/summary_text_content.rbi +31 -0
  124. data/rbi/openai/models/conversations/text_content.rbi +28 -0
  125. data/rbi/openai/models/conversations/top_log_prob.rbi +41 -0
  126. data/rbi/openai/models/conversations/url_citation_body.rbi +74 -0
  127. data/rbi/openai/models/evals/create_eval_completions_run_data_source.rbi +33 -33
  128. data/rbi/openai/models/evals/run_cancel_response.rbi +2 -0
  129. data/rbi/openai/models/evals/run_create_params.rbi +4 -0
  130. data/rbi/openai/models/evals/run_create_response.rbi +2 -0
  131. data/rbi/openai/models/evals/run_list_response.rbi +2 -0
  132. data/rbi/openai/models/evals/run_retrieve_response.rbi +2 -0
  133. data/rbi/openai/models/responses/input_item_list_params.rbi +0 -11
  134. data/rbi/openai/models/responses/response.rbi +50 -0
  135. data/rbi/openai/models/responses/response_conversation_param.rbi +33 -0
  136. data/rbi/openai/models/responses/response_create_params.rbi +62 -0
  137. data/rbi/openai/models/responses/response_function_web_search.rbi +78 -2
  138. data/rbi/openai/models/responses/response_includable.rbi +2 -0
  139. data/rbi/openai/models/responses/tool.rbi +590 -31
  140. data/rbi/openai/models.rbi +2 -0
  141. data/rbi/openai/resources/conversations/items.rbi +154 -0
  142. data/rbi/openai/resources/conversations.rbi +110 -0
  143. data/rbi/openai/resources/responses/input_items.rbi +0 -3
  144. data/rbi/openai/resources/responses.rbi +32 -0
  145. data/sig/openai/client.rbs +2 -0
  146. data/sig/openai/internal/conversation_cursor_page.rbs +15 -0
  147. data/sig/openai/models/conversations/computer_screenshot_content.rbs +28 -0
  148. data/sig/openai/models/conversations/container_file_citation_body.rbs +47 -0
  149. data/sig/openai/models/conversations/conversation.rbs +37 -0
  150. data/sig/openai/models/conversations/conversation_create_params.rbs +33 -0
  151. data/sig/openai/models/conversations/conversation_delete_params.rbs +17 -0
  152. data/sig/openai/models/conversations/conversation_deleted.rbs +28 -0
  153. data/sig/openai/models/conversations/conversation_deleted_resource.rbs +28 -0
  154. data/sig/openai/models/conversations/conversation_item.rbs +403 -0
  155. data/sig/openai/models/conversations/conversation_item_list.rbs +44 -0
  156. data/sig/openai/models/conversations/conversation_retrieve_params.rbs +17 -0
  157. data/sig/openai/models/conversations/conversation_update_params.rbs +26 -0
  158. data/sig/openai/models/conversations/file_citation_body.rbs +37 -0
  159. data/sig/openai/models/conversations/input_file_content.rbs +41 -0
  160. data/sig/openai/models/conversations/input_image_content.rbs +49 -0
  161. data/sig/openai/models/conversations/input_text_content.rbs +17 -0
  162. data/sig/openai/models/conversations/item_create_params.rbs +37 -0
  163. data/sig/openai/models/conversations/item_delete_params.rbs +25 -0
  164. data/sig/openai/models/conversations/item_list_params.rbs +66 -0
  165. data/sig/openai/models/conversations/item_retrieve_params.rbs +37 -0
  166. data/sig/openai/models/conversations/lob_prob.rbs +37 -0
  167. data/sig/openai/models/conversations/message.rbs +95 -0
  168. data/sig/openai/models/conversations/output_text_content.rbs +52 -0
  169. data/sig/openai/models/conversations/refusal_content.rbs +17 -0
  170. data/sig/openai/models/conversations/summary_text_content.rbs +17 -0
  171. data/sig/openai/models/conversations/text_content.rbs +17 -0
  172. data/sig/openai/models/conversations/top_log_prob.rbs +28 -0
  173. data/sig/openai/models/conversations/url_citation_body.rbs +42 -0
  174. data/sig/openai/models/evals/create_eval_completions_run_data_source.rbs +22 -22
  175. data/sig/openai/models/responses/input_item_list_params.rbs +0 -7
  176. data/sig/openai/models/responses/response.rbs +15 -0
  177. data/sig/openai/models/responses/response_conversation_param.rbs +15 -0
  178. data/sig/openai/models/responses/response_create_params.rbs +14 -0
  179. data/sig/openai/models/responses/response_function_web_search.rbs +34 -3
  180. data/sig/openai/models/responses/tool.rbs +204 -18
  181. data/sig/openai/models.rbs +2 -0
  182. data/sig/openai/resources/conversations/items.rbs +38 -0
  183. data/sig/openai/resources/conversations.rbs +31 -0
  184. data/sig/openai/resources/responses/input_items.rbs +0 -1
  185. data/sig/openai/resources/responses.rbs +2 -0
  186. metadata +95 -2
@@ -20,9 +20,24 @@ module OpenAI
20
20
  sig { returns(T.nilable(T::Boolean)) }
21
21
  attr_accessor :background
22
22
 
23
+ # The conversation that this response belongs to. Items from this conversation are
24
+ # prepended to `input_items` for this response request. Input items and output
25
+ # items from this response are automatically added to this conversation after this
26
+ # response completes.
27
+ sig do
28
+ returns(
29
+ T.nilable(
30
+ T.any(String, OpenAI::Responses::ResponseConversationParam)
31
+ )
32
+ )
33
+ end
34
+ attr_accessor :conversation
35
+
23
36
  # Specify additional output data to include in the model response. Currently
24
37
  # supported values are:
25
38
  #
39
+ # - `web_search_call.action.sources`: Include the sources of the web search tool
40
+ # call.
26
41
  # - `code_interpreter_call.outputs`: Includes the outputs of python code execution
27
42
  # in code interpreter tool call items.
28
43
  # - `computer_call_output.output.image_url`: Include image urls from the computer
@@ -133,6 +148,7 @@ module OpenAI
133
148
  # The unique ID of the previous response to the model. Use this to create
134
149
  # multi-turn conversations. Learn more about
135
150
  # [conversation state](https://platform.openai.com/docs/guides/conversation-state).
151
+ # Cannot be used in conjunction with `conversation`.
136
152
  sig { returns(T.nilable(String)) }
137
153
  attr_accessor :previous_response_id
138
154
 
@@ -314,6 +330,7 @@ module OpenAI
314
330
  OpenAI::Responses::Tool::ImageGeneration,
315
331
  OpenAI::Responses::Tool::LocalShell,
316
332
  OpenAI::Responses::CustomTool,
333
+ OpenAI::Responses::Tool::WebSearchTool,
317
334
  OpenAI::Responses::WebSearchTool
318
335
  )
319
336
  ]
@@ -335,6 +352,7 @@ module OpenAI
335
352
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
336
353
  OpenAI::Responses::Tool::LocalShell::OrHash,
337
354
  OpenAI::Responses::CustomTool::OrHash,
355
+ OpenAI::Responses::Tool::WebSearchTool::OrHash,
338
356
  OpenAI::Responses::WebSearchTool::OrHash
339
357
  )
340
358
  ]
@@ -385,6 +403,13 @@ module OpenAI
385
403
  sig do
386
404
  params(
387
405
  background: T.nilable(T::Boolean),
406
+ conversation:
407
+ T.nilable(
408
+ T.any(
409
+ String,
410
+ OpenAI::Responses::ResponseConversationParam::OrHash
411
+ )
412
+ ),
388
413
  include:
389
414
  T.nilable(
390
415
  T::Array[OpenAI::Responses::ResponseIncludable::OrSymbol]
@@ -437,6 +462,7 @@ module OpenAI
437
462
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
438
463
  OpenAI::Responses::Tool::LocalShell::OrHash,
439
464
  OpenAI::Responses::CustomTool::OrHash,
465
+ OpenAI::Responses::Tool::WebSearchTool::OrHash,
440
466
  OpenAI::Responses::WebSearchTool::OrHash
441
467
  )
442
468
  ],
@@ -454,9 +480,16 @@ module OpenAI
454
480
  # Whether to run the model response in the background.
455
481
  # [Learn more](https://platform.openai.com/docs/guides/background).
456
482
  background: nil,
483
+ # The conversation that this response belongs to. Items from this conversation are
484
+ # prepended to `input_items` for this response request. Input items and output
485
+ # items from this response are automatically added to this conversation after this
486
+ # response completes.
487
+ conversation: nil,
457
488
  # Specify additional output data to include in the model response. Currently
458
489
  # supported values are:
459
490
  #
491
+ # - `web_search_call.action.sources`: Include the sources of the web search tool
492
+ # call.
460
493
  # - `code_interpreter_call.outputs`: Includes the outputs of python code execution
461
494
  # in code interpreter tool call items.
462
495
  # - `computer_call_output.output.image_url`: Include image urls from the computer
@@ -514,6 +547,7 @@ module OpenAI
514
547
  # The unique ID of the previous response to the model. Use this to create
515
548
  # multi-turn conversations. Learn more about
516
549
  # [conversation state](https://platform.openai.com/docs/guides/conversation-state).
550
+ # Cannot be used in conjunction with `conversation`.
517
551
  previous_response_id: nil,
518
552
  # Reference to a prompt template and its variables.
519
553
  # [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
@@ -617,6 +651,10 @@ module OpenAI
617
651
  override.returns(
618
652
  {
619
653
  background: T.nilable(T::Boolean),
654
+ conversation:
655
+ T.nilable(
656
+ T.any(String, OpenAI::Responses::ResponseConversationParam)
657
+ ),
620
658
  include:
621
659
  T.nilable(
622
660
  T::Array[OpenAI::Responses::ResponseIncludable::OrSymbol]
@@ -669,6 +707,7 @@ module OpenAI
669
707
  OpenAI::Responses::Tool::ImageGeneration,
670
708
  OpenAI::Responses::Tool::LocalShell,
671
709
  OpenAI::Responses::CustomTool,
710
+ OpenAI::Responses::Tool::WebSearchTool,
672
711
  OpenAI::Responses::WebSearchTool
673
712
  )
674
713
  ],
@@ -686,6 +725,29 @@ module OpenAI
686
725
  def to_hash
687
726
  end
688
727
 
728
+ # The conversation that this response belongs to. Items from this conversation are
729
+ # prepended to `input_items` for this response request. Input items and output
730
+ # items from this response are automatically added to this conversation after this
731
+ # response completes.
732
+ module Conversation
733
+ extend OpenAI::Internal::Type::Union
734
+
735
+ Variants =
736
+ T.type_alias do
737
+ T.any(String, OpenAI::Responses::ResponseConversationParam)
738
+ end
739
+
740
+ sig do
741
+ override.returns(
742
+ T::Array[
743
+ OpenAI::Responses::ResponseCreateParams::Conversation::Variants
744
+ ]
745
+ )
746
+ end
747
+ def self.variants
748
+ end
749
+ end
750
+
689
751
  # Text, image, or file inputs to the model, used to generate a response.
690
752
  #
691
753
  # Learn more:
@@ -121,21 +121,97 @@ module OpenAI
121
121
  sig { returns(Symbol) }
122
122
  attr_accessor :type
123
123
 
124
+ # The sources used in the search.
125
+ sig do
126
+ returns(
127
+ T.nilable(
128
+ T::Array[
129
+ OpenAI::Responses::ResponseFunctionWebSearch::Action::Search::Source
130
+ ]
131
+ )
132
+ )
133
+ end
134
+ attr_reader :sources
135
+
136
+ sig do
137
+ params(
138
+ sources:
139
+ T::Array[
140
+ OpenAI::Responses::ResponseFunctionWebSearch::Action::Search::Source::OrHash
141
+ ]
142
+ ).void
143
+ end
144
+ attr_writer :sources
145
+
124
146
  # Action type "search" - Performs a web search query.
125
147
  sig do
126
- params(query: String, type: Symbol).returns(T.attached_class)
148
+ params(
149
+ query: String,
150
+ sources:
151
+ T::Array[
152
+ OpenAI::Responses::ResponseFunctionWebSearch::Action::Search::Source::OrHash
153
+ ],
154
+ type: Symbol
155
+ ).returns(T.attached_class)
127
156
  end
128
157
  def self.new(
129
158
  # The search query.
130
159
  query:,
160
+ # The sources used in the search.
161
+ sources: nil,
131
162
  # The action type.
132
163
  type: :search
133
164
  )
134
165
  end
135
166
 
136
- sig { override.returns({ query: String, type: Symbol }) }
167
+ sig do
168
+ override.returns(
169
+ {
170
+ query: String,
171
+ type: Symbol,
172
+ sources:
173
+ T::Array[
174
+ OpenAI::Responses::ResponseFunctionWebSearch::Action::Search::Source
175
+ ]
176
+ }
177
+ )
178
+ end
137
179
  def to_hash
138
180
  end
181
+
182
+ class Source < OpenAI::Internal::Type::BaseModel
183
+ OrHash =
184
+ T.type_alias do
185
+ T.any(
186
+ OpenAI::Responses::ResponseFunctionWebSearch::Action::Search::Source,
187
+ OpenAI::Internal::AnyHash
188
+ )
189
+ end
190
+
191
+ # The type of source. Always `url`.
192
+ sig { returns(Symbol) }
193
+ attr_accessor :type
194
+
195
+ # The URL of the source.
196
+ sig { returns(String) }
197
+ attr_accessor :url
198
+
199
+ # A source used in the search.
200
+ sig do
201
+ params(url: String, type: Symbol).returns(T.attached_class)
202
+ end
203
+ def self.new(
204
+ # The URL of the source.
205
+ url:,
206
+ # The type of source. Always `url`.
207
+ type: :url
208
+ )
209
+ end
210
+
211
+ sig { override.returns({ type: Symbol, url: String }) }
212
+ def to_hash
213
+ end
214
+ end
139
215
  end
140
216
 
141
217
  class OpenPage < OpenAI::Internal::Type::BaseModel
@@ -6,6 +6,8 @@ module OpenAI
6
6
  # Specify additional output data to include in the model response. Currently
7
7
  # supported values are:
8
8
  #
9
+ # - `web_search_call.action.sources`: Include the sources of the web search tool
10
+ # call.
9
11
  # - `code_interpreter_call.outputs`: Includes the outputs of python code execution
10
12
  # in code interpreter tool call items.
11
13
  # - `computer_call_output.output.image_url`: Include image urls from the computer