openai 0.15.0 → 0.17.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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/README.md +14 -20
  4. data/lib/openai/helpers/structured_output/json_schema_converter.rb +20 -21
  5. data/lib/openai/helpers/structured_output/union_of.rb +11 -1
  6. data/lib/openai/internal/transport/base_client.rb +1 -1
  7. data/lib/openai/internal/type/enum.rb +6 -6
  8. data/lib/openai/internal/type/union.rb +13 -17
  9. data/lib/openai/models/beta/assistant_create_params.rb +4 -5
  10. data/lib/openai/models/beta/assistant_update_params.rb +22 -5
  11. data/lib/openai/models/beta/threads/run_create_params.rb +4 -5
  12. data/lib/openai/models/chat/chat_completion_allowed_tool_choice.rb +33 -0
  13. data/lib/openai/models/chat/chat_completion_allowed_tools.rb +64 -0
  14. data/lib/openai/models/chat/chat_completion_assistant_message_param.rb +3 -5
  15. data/lib/openai/models/chat/chat_completion_custom_tool.rb +163 -0
  16. data/lib/openai/models/chat/chat_completion_function_tool.rb +29 -0
  17. data/lib/openai/models/chat/chat_completion_message.rb +3 -5
  18. data/lib/openai/models/chat/chat_completion_message_custom_tool_call.rb +60 -0
  19. data/lib/openai/models/chat/chat_completion_message_function_tool_call.rb +73 -0
  20. data/lib/openai/models/chat/chat_completion_message_tool_call.rb +10 -56
  21. data/lib/openai/models/chat/chat_completion_named_tool_choice.rb +2 -2
  22. data/lib/openai/models/chat/chat_completion_named_tool_choice_custom.rb +42 -0
  23. data/lib/openai/models/chat/chat_completion_store_message.rb +32 -1
  24. data/lib/openai/models/chat/chat_completion_stream_options.rb +14 -1
  25. data/lib/openai/models/chat/chat_completion_tool.rb +12 -14
  26. data/lib/openai/models/chat/chat_completion_tool_choice_option.rb +7 -1
  27. data/lib/openai/models/chat/completion_create_params.rb +65 -16
  28. data/lib/openai/models/chat_model.rb +7 -0
  29. data/lib/openai/models/custom_tool_input_format.rb +76 -0
  30. data/lib/openai/models/evals/create_eval_completions_run_data_source.rb +3 -3
  31. data/lib/openai/models/evals/run_cancel_response.rb +2 -2
  32. data/lib/openai/models/evals/run_create_params.rb +2 -2
  33. data/lib/openai/models/evals/run_create_response.rb +2 -2
  34. data/lib/openai/models/evals/run_list_response.rb +2 -2
  35. data/lib/openai/models/evals/run_retrieve_response.rb +2 -2
  36. data/lib/openai/models/reasoning.rb +4 -5
  37. data/lib/openai/models/reasoning_effort.rb +4 -4
  38. data/lib/openai/models/response_format_text_grammar.rb +27 -0
  39. data/lib/openai/models/response_format_text_python.rb +20 -0
  40. data/lib/openai/models/responses/custom_tool.rb +48 -0
  41. data/lib/openai/models/responses/response.rb +70 -16
  42. data/lib/openai/models/responses/response_create_params.rb +78 -14
  43. data/lib/openai/models/responses/response_custom_tool_call.rb +55 -0
  44. data/lib/openai/models/responses/response_custom_tool_call_input_delta_event.rb +52 -0
  45. data/lib/openai/models/responses/response_custom_tool_call_input_done_event.rb +52 -0
  46. data/lib/openai/models/responses/response_custom_tool_call_output.rb +47 -0
  47. data/lib/openai/models/responses/response_input_item.rb +7 -1
  48. data/lib/openai/models/responses/response_output_item.rb +4 -1
  49. data/lib/openai/models/responses/response_output_item_added_event.rb +2 -2
  50. data/lib/openai/models/responses/response_output_item_done_event.rb +2 -2
  51. data/lib/openai/models/responses/response_reasoning_item.rb +36 -5
  52. data/lib/openai/models/responses/response_reasoning_text_delta_event.rb +63 -0
  53. data/lib/openai/models/responses/response_reasoning_text_done_event.rb +63 -0
  54. data/lib/openai/models/responses/response_retrieve_params.rb +14 -1
  55. data/lib/openai/models/responses/response_stream_event.rb +13 -11
  56. data/lib/openai/models/responses/response_text_config.rb +27 -1
  57. data/lib/openai/models/responses/tool.rb +5 -1
  58. data/lib/openai/models/responses/tool_choice_allowed.rb +73 -0
  59. data/lib/openai/models/responses/tool_choice_custom.rb +28 -0
  60. data/lib/openai/models/vector_store_search_params.rb +6 -1
  61. data/lib/openai/models.rb +6 -0
  62. data/lib/openai/resources/beta/assistants.rb +2 -2
  63. data/lib/openai/resources/beta/threads/runs.rb +2 -2
  64. data/lib/openai/resources/chat/completions.rb +26 -12
  65. data/lib/openai/resources/responses.rb +77 -36
  66. data/lib/openai/version.rb +1 -1
  67. data/lib/openai.rb +19 -2
  68. data/rbi/openai/internal/transport/base_client.rbi +1 -1
  69. data/rbi/openai/models/beta/assistant_create_params.rbi +6 -8
  70. data/rbi/openai/models/beta/assistant_update_params.rbi +36 -8
  71. data/rbi/openai/models/beta/threads/run_create_params.rbi +6 -8
  72. data/rbi/openai/models/chat/chat_completion_allowed_tool_choice.rbi +60 -0
  73. data/rbi/openai/models/chat/chat_completion_allowed_tools.rbi +118 -0
  74. data/rbi/openai/models/chat/chat_completion_assistant_message_param.rbi +27 -4
  75. data/rbi/openai/models/chat/chat_completion_custom_tool.rbi +335 -0
  76. data/rbi/openai/models/chat/chat_completion_function_tool.rbi +51 -0
  77. data/rbi/openai/models/chat/chat_completion_message.rbi +17 -4
  78. data/rbi/openai/models/chat/chat_completion_message_custom_tool_call.rbi +105 -0
  79. data/rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi +118 -0
  80. data/rbi/openai/models/chat/chat_completion_message_tool_call.rbi +9 -92
  81. data/rbi/openai/models/chat/chat_completion_named_tool_choice.rbi +2 -2
  82. data/rbi/openai/models/chat/chat_completion_named_tool_choice_custom.rbi +89 -0
  83. data/rbi/openai/models/chat/chat_completion_store_message.rbi +68 -3
  84. data/rbi/openai/models/chat/chat_completion_stream_options.rbi +30 -2
  85. data/rbi/openai/models/chat/chat_completion_tool.rbi +11 -30
  86. data/rbi/openai/models/chat/chat_completion_tool_choice_option.rbi +3 -1
  87. data/rbi/openai/models/chat/completion_create_params.rbi +150 -31
  88. data/rbi/openai/models/chat_model.rbi +11 -0
  89. data/rbi/openai/models/custom_tool_input_format.rbi +136 -0
  90. data/rbi/openai/models/evals/create_eval_completions_run_data_source.rbi +8 -4
  91. data/rbi/openai/models/evals/run_cancel_response.rbi +2 -0
  92. data/rbi/openai/models/evals/run_create_params.rbi +4 -0
  93. data/rbi/openai/models/evals/run_create_response.rbi +2 -0
  94. data/rbi/openai/models/evals/run_list_response.rbi +2 -0
  95. data/rbi/openai/models/evals/run_retrieve_response.rbi +2 -0
  96. data/rbi/openai/models/reasoning.rbi +6 -8
  97. data/rbi/openai/models/reasoning_effort.rbi +4 -4
  98. data/rbi/openai/models/response_format_text_grammar.rbi +35 -0
  99. data/rbi/openai/models/response_format_text_python.rbi +30 -0
  100. data/rbi/openai/models/responses/custom_tool.rbi +96 -0
  101. data/rbi/openai/models/responses/response.rbi +59 -11
  102. data/rbi/openai/models/responses/response_create_params.rbi +138 -13
  103. data/rbi/openai/models/responses/response_custom_tool_call.rbi +78 -0
  104. data/rbi/openai/models/responses/response_custom_tool_call_input_delta_event.rbi +75 -0
  105. data/rbi/openai/models/responses/response_custom_tool_call_input_done_event.rbi +75 -0
  106. data/rbi/openai/models/responses/response_custom_tool_call_output.rbi +65 -0
  107. data/rbi/openai/models/responses/response_input_item.rbi +2 -0
  108. data/rbi/openai/models/responses/response_output_item.rbi +2 -1
  109. data/rbi/openai/models/responses/response_output_item_added_event.rbi +2 -1
  110. data/rbi/openai/models/responses/response_output_item_done_event.rbi +2 -1
  111. data/rbi/openai/models/responses/response_reasoning_item.rbi +63 -4
  112. data/rbi/openai/models/responses/response_reasoning_text_delta_event.rbi +83 -0
  113. data/rbi/openai/models/responses/{response_reasoning_summary_done_event.rbi → response_reasoning_text_done_event.rbi} +20 -20
  114. data/rbi/openai/models/responses/response_retrieve_params.rbi +21 -0
  115. data/rbi/openai/models/responses/response_stream_event.rbi +4 -2
  116. data/rbi/openai/models/responses/response_text_config.rbi +64 -1
  117. data/rbi/openai/models/responses/tool.rbi +1 -0
  118. data/rbi/openai/models/responses/tool_choice_allowed.rbi +124 -0
  119. data/rbi/openai/models/responses/tool_choice_custom.rbi +39 -0
  120. data/rbi/openai/models/vector_store_search_params.rbi +12 -1
  121. data/rbi/openai/models.rbi +6 -0
  122. data/rbi/openai/resources/beta/assistants.rbi +6 -8
  123. data/rbi/openai/resources/beta/threads/runs.rbi +8 -10
  124. data/rbi/openai/resources/chat/completions.rbi +78 -25
  125. data/rbi/openai/resources/responses.rbi +249 -47
  126. data/sig/openai/internal/transport/base_client.rbs +1 -1
  127. data/sig/openai/models/beta/assistant_update_params.rbs +12 -0
  128. data/sig/openai/models/chat/chat_completion_allowed_tool_choice.rbs +29 -0
  129. data/sig/openai/models/chat/chat_completion_allowed_tools.rbs +38 -0
  130. data/sig/openai/models/chat/chat_completion_assistant_message_param.rbs +6 -6
  131. data/sig/openai/models/chat/chat_completion_custom_tool.rbs +137 -0
  132. data/sig/openai/models/chat/chat_completion_function_tool.rbs +26 -0
  133. data/sig/openai/models/chat/chat_completion_message.rbs +6 -6
  134. data/sig/openai/models/chat/chat_completion_message_custom_tool_call.rbs +46 -0
  135. data/sig/openai/models/chat/chat_completion_message_function_tool_call.rbs +46 -0
  136. data/sig/openai/models/chat/chat_completion_message_tool_call.rbs +6 -35
  137. data/sig/openai/models/chat/chat_completion_named_tool_choice_custom.rbs +39 -0
  138. data/sig/openai/models/chat/chat_completion_store_message.rbs +29 -3
  139. data/sig/openai/models/chat/chat_completion_stream_options.rbs +11 -3
  140. data/sig/openai/models/chat/chat_completion_tool.rbs +6 -15
  141. data/sig/openai/models/chat/chat_completion_tool_choice_option.rbs +2 -0
  142. data/sig/openai/models/chat/completion_create_params.rbs +37 -6
  143. data/sig/openai/models/chat_model.rbs +15 -1
  144. data/sig/openai/models/custom_tool_input_format.rbs +61 -0
  145. data/sig/openai/models/evals/create_eval_completions_run_data_source.rbs +6 -6
  146. data/sig/openai/models/reasoning_effort.rbs +2 -1
  147. data/sig/openai/models/response_format_text_grammar.rbs +15 -0
  148. data/sig/openai/models/response_format_text_python.rbs +13 -0
  149. data/sig/openai/models/responses/custom_tool.rbs +43 -0
  150. data/sig/openai/models/responses/response.rbs +16 -0
  151. data/sig/openai/models/responses/response_create_params.rbs +33 -0
  152. data/sig/openai/models/responses/response_custom_tool_call.rbs +44 -0
  153. data/sig/openai/models/responses/response_custom_tool_call_input_delta_event.rbs +42 -0
  154. data/sig/openai/models/responses/response_custom_tool_call_input_done_event.rbs +42 -0
  155. data/sig/openai/models/responses/response_custom_tool_call_output.rbs +39 -0
  156. data/sig/openai/models/responses/response_input_item.rbs +2 -0
  157. data/sig/openai/models/responses/response_output_item.rbs +1 -0
  158. data/sig/openai/models/responses/response_reasoning_item.rbs +21 -0
  159. data/sig/openai/models/responses/{response_reasoning_summary_delta_event.rbs → response_reasoning_text_delta_event.rbs} +15 -15
  160. data/sig/openai/models/responses/{response_reasoning_summary_done_event.rbs → response_reasoning_text_done_event.rbs} +11 -11
  161. data/sig/openai/models/responses/response_retrieve_params.rbs +7 -0
  162. data/sig/openai/models/responses/response_stream_event.rbs +4 -2
  163. data/sig/openai/models/responses/response_text_config.rbs +22 -3
  164. data/sig/openai/models/responses/tool.rbs +1 -0
  165. data/sig/openai/models/responses/tool_choice_allowed.rbs +43 -0
  166. data/sig/openai/models/responses/tool_choice_custom.rbs +17 -0
  167. data/sig/openai/models/vector_store_search_params.rbs +2 -1
  168. data/sig/openai/models.rbs +6 -0
  169. data/sig/openai/resources/chat/completions.rbs +8 -2
  170. data/sig/openai/resources/responses.rbs +36 -0
  171. metadata +59 -8
  172. data/lib/openai/models/responses/response_reasoning_summary_delta_event.rb +0 -65
  173. data/lib/openai/models/responses/response_reasoning_summary_done_event.rb +0 -60
  174. data/rbi/openai/models/responses/response_reasoning_summary_delta_event.rbi +0 -85
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Chat
6
+ class ChatCompletionCustomTool < OpenAI::Internal::Type::BaseModel
7
+ # @!attribute custom
8
+ # Properties of the custom tool.
9
+ #
10
+ # @return [OpenAI::Models::Chat::ChatCompletionCustomTool::Custom]
11
+ required :custom, -> { OpenAI::Chat::ChatCompletionCustomTool::Custom }
12
+
13
+ # @!attribute type
14
+ # The type of the custom tool. Always `custom`.
15
+ #
16
+ # @return [Symbol, :custom]
17
+ required :type, const: :custom
18
+
19
+ # @!method initialize(custom:, type: :custom)
20
+ # Some parameter documentations has been truncated, see
21
+ # {OpenAI::Models::Chat::ChatCompletionCustomTool} for more details.
22
+ #
23
+ # A custom tool that processes input using a specified format.
24
+ #
25
+ # @param custom [OpenAI::Models::Chat::ChatCompletionCustomTool::Custom] Properties of the custom tool.
26
+ #
27
+ # @param type [Symbol, :custom] The type of the custom tool. Always `custom`.
28
+
29
+ # @see OpenAI::Models::Chat::ChatCompletionCustomTool#custom
30
+ class Custom < OpenAI::Internal::Type::BaseModel
31
+ # @!attribute name
32
+ # The name of the custom tool, used to identify it in tool calls.
33
+ #
34
+ # @return [String]
35
+ required :name, String
36
+
37
+ # @!attribute description
38
+ # Optional description of the custom tool, used to provide more context.
39
+ #
40
+ # @return [String, nil]
41
+ optional :description, String
42
+
43
+ # @!attribute format_
44
+ # The input format for the custom tool. Default is unconstrained text.
45
+ #
46
+ # @return [OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Text, OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar, nil]
47
+ optional :format_,
48
+ union: -> {
49
+ OpenAI::Chat::ChatCompletionCustomTool::Custom::Format
50
+ },
51
+ api_name: :format
52
+
53
+ # @!method initialize(name:, description: nil, format_: nil)
54
+ # Some parameter documentations has been truncated, see
55
+ # {OpenAI::Models::Chat::ChatCompletionCustomTool::Custom} for more details.
56
+ #
57
+ # Properties of the custom tool.
58
+ #
59
+ # @param name [String] The name of the custom tool, used to identify it in tool calls.
60
+ #
61
+ # @param description [String] Optional description of the custom tool, used to provide more context.
62
+ #
63
+ # @param format_ [OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Text, OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar] The input format for the custom tool. Default is unconstrained text.
64
+
65
+ # The input format for the custom tool. Default is unconstrained text.
66
+ #
67
+ # @see OpenAI::Models::Chat::ChatCompletionCustomTool::Custom#format_
68
+ module Format
69
+ extend OpenAI::Internal::Type::Union
70
+
71
+ discriminator :type
72
+
73
+ # Unconstrained free-form text.
74
+ variant :text, -> { OpenAI::Chat::ChatCompletionCustomTool::Custom::Format::Text }
75
+
76
+ # A grammar defined by the user.
77
+ variant :grammar, -> { OpenAI::Chat::ChatCompletionCustomTool::Custom::Format::Grammar }
78
+
79
+ class Text < OpenAI::Internal::Type::BaseModel
80
+ # @!attribute type
81
+ # Unconstrained text format. Always `text`.
82
+ #
83
+ # @return [Symbol, :text]
84
+ required :type, const: :text
85
+
86
+ # @!method initialize(type: :text)
87
+ # Unconstrained free-form text.
88
+ #
89
+ # @param type [Symbol, :text] Unconstrained text format. Always `text`.
90
+ end
91
+
92
+ class Grammar < OpenAI::Internal::Type::BaseModel
93
+ # @!attribute grammar
94
+ # Your chosen grammar.
95
+ #
96
+ # @return [OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar]
97
+ required :grammar,
98
+ -> {
99
+ OpenAI::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar
100
+ }
101
+
102
+ # @!attribute type
103
+ # Grammar format. Always `grammar`.
104
+ #
105
+ # @return [Symbol, :grammar]
106
+ required :type, const: :grammar
107
+
108
+ # @!method initialize(grammar:, type: :grammar)
109
+ # A grammar defined by the user.
110
+ #
111
+ # @param grammar [OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar] Your chosen grammar.
112
+ #
113
+ # @param type [Symbol, :grammar] Grammar format. Always `grammar`.
114
+
115
+ # @see OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar#grammar
116
+ class Grammar < OpenAI::Internal::Type::BaseModel
117
+ # @!attribute definition
118
+ # The grammar definition.
119
+ #
120
+ # @return [String]
121
+ required :definition, String
122
+
123
+ # @!attribute syntax
124
+ # The syntax of the grammar definition. One of `lark` or `regex`.
125
+ #
126
+ # @return [Symbol, OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar::Syntax]
127
+ required :syntax,
128
+ enum: -> {
129
+ OpenAI::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar::Syntax
130
+ }
131
+
132
+ # @!method initialize(definition:, syntax:)
133
+ # Your chosen grammar.
134
+ #
135
+ # @param definition [String] The grammar definition.
136
+ #
137
+ # @param syntax [Symbol, OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar::Syntax] The syntax of the grammar definition. One of `lark` or `regex`.
138
+
139
+ # The syntax of the grammar definition. One of `lark` or `regex`.
140
+ #
141
+ # @see OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar::Grammar#syntax
142
+ module Syntax
143
+ extend OpenAI::Internal::Type::Enum
144
+
145
+ LARK = :lark
146
+ REGEX = :regex
147
+
148
+ # @!method self.values
149
+ # @return [Array<Symbol>]
150
+ end
151
+ end
152
+ end
153
+
154
+ # @!method self.variants
155
+ # @return [Array(OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Text, OpenAI::Models::Chat::ChatCompletionCustomTool::Custom::Format::Grammar)]
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ ChatCompletionCustomTool = Chat::ChatCompletionCustomTool
162
+ end
163
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Chat
6
+ class ChatCompletionFunctionTool < OpenAI::Internal::Type::BaseModel
7
+ # @!attribute function
8
+ #
9
+ # @return [OpenAI::Models::FunctionDefinition]
10
+ required :function, -> { OpenAI::FunctionDefinition }
11
+
12
+ # @!attribute type
13
+ # The type of the tool. Currently, only `function` is supported.
14
+ #
15
+ # @return [Symbol, :function]
16
+ required :type, const: :function
17
+
18
+ # @!method initialize(function:, type: :function)
19
+ # A function tool that can be used to generate a response.
20
+ #
21
+ # @param function [OpenAI::Models::FunctionDefinition]
22
+ #
23
+ # @param type [Symbol, :function] The type of the tool. Currently, only `function` is supported.
24
+ end
25
+ end
26
+
27
+ ChatCompletionFunctionTool = Chat::ChatCompletionFunctionTool
28
+ end
29
+ end
@@ -56,11 +56,9 @@ module OpenAI
56
56
  # @!attribute tool_calls
57
57
  # The tool calls generated by the model, such as function calls.
58
58
  #
59
- # @return [Array<OpenAI::Models::Chat::ChatCompletionMessageToolCall>, nil]
59
+ # @return [Array<OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall, OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall>, nil]
60
60
  optional :tool_calls,
61
- -> {
62
- OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionMessageToolCall]
63
- }
61
+ -> { OpenAI::Internal::Type::ArrayOf[union: OpenAI::Chat::ChatCompletionMessageToolCall] }
64
62
 
65
63
  # @!method initialize(content:, refusal:, annotations: nil, audio: nil, function_call: nil, tool_calls: nil, role: :assistant)
66
64
  # Some parameter documentations has been truncated, see
@@ -78,7 +76,7 @@ module OpenAI
78
76
  #
79
77
  # @param function_call [OpenAI::Models::Chat::ChatCompletionMessage::FunctionCall] Deprecated and replaced by `tool_calls`. The name and arguments of a function th
80
78
  #
81
- # @param tool_calls [Array<OpenAI::Models::Chat::ChatCompletionMessageToolCall>] The tool calls generated by the model, such as function calls.
79
+ # @param tool_calls [Array<OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall, OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall>] The tool calls generated by the model, such as function calls.
82
80
  #
83
81
  # @param role [Symbol, :assistant] The role of the author of this message.
84
82
 
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Chat
6
+ class ChatCompletionMessageCustomToolCall < OpenAI::Internal::Type::BaseModel
7
+ # @!attribute id
8
+ # The ID of the tool call.
9
+ #
10
+ # @return [String]
11
+ required :id, String
12
+
13
+ # @!attribute custom
14
+ # The custom tool that the model called.
15
+ #
16
+ # @return [OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall::Custom]
17
+ required :custom, -> { OpenAI::Chat::ChatCompletionMessageCustomToolCall::Custom }
18
+
19
+ # @!attribute type
20
+ # The type of the tool. Always `custom`.
21
+ #
22
+ # @return [Symbol, :custom]
23
+ required :type, const: :custom
24
+
25
+ # @!method initialize(id:, custom:, type: :custom)
26
+ # A call to a custom tool created by the model.
27
+ #
28
+ # @param id [String] The ID of the tool call.
29
+ #
30
+ # @param custom [OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall::Custom] The custom tool that the model called.
31
+ #
32
+ # @param type [Symbol, :custom] The type of the tool. Always `custom`.
33
+
34
+ # @see OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall#custom
35
+ class Custom < OpenAI::Internal::Type::BaseModel
36
+ # @!attribute input
37
+ # The input for the custom tool call generated by the model.
38
+ #
39
+ # @return [String]
40
+ required :input, String
41
+
42
+ # @!attribute name
43
+ # The name of the custom tool to call.
44
+ #
45
+ # @return [String]
46
+ required :name, String
47
+
48
+ # @!method initialize(input:, name:)
49
+ # The custom tool that the model called.
50
+ #
51
+ # @param input [String] The input for the custom tool call generated by the model.
52
+ #
53
+ # @param name [String] The name of the custom tool to call.
54
+ end
55
+ end
56
+ end
57
+
58
+ ChatCompletionMessageCustomToolCall = Chat::ChatCompletionMessageCustomToolCall
59
+ end
60
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Chat
6
+ class ChatCompletionMessageFunctionToolCall < OpenAI::Internal::Type::BaseModel
7
+ # @!attribute id
8
+ # The ID of the tool call.
9
+ #
10
+ # @return [String]
11
+ required :id, String
12
+
13
+ # @!attribute function
14
+ # The function that the model called.
15
+ #
16
+ # @return [OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall::Function]
17
+ required :function, -> { OpenAI::Chat::ChatCompletionMessageFunctionToolCall::Function }
18
+
19
+ # @!attribute type
20
+ # The type of the tool. Currently, only `function` is supported.
21
+ #
22
+ # @return [Symbol, :function]
23
+ required :type, const: :function
24
+
25
+ # @!method initialize(id:, function:, type: :function)
26
+ # A call to a function tool created by the model.
27
+ #
28
+ # @param id [String] The ID of the tool call.
29
+ #
30
+ # @param function [OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall::Function] The function that the model called.
31
+ #
32
+ # @param type [Symbol, :function] The type of the tool. Currently, only `function` is supported.
33
+
34
+ # @see OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall#function
35
+ class Function < OpenAI::Internal::Type::BaseModel
36
+ # @!attribute arguments
37
+ # The arguments to call the function with, as generated by the model in JSON
38
+ # format. Note that the model does not always generate valid JSON, and may
39
+ # hallucinate parameters not defined by your function schema. Validate the
40
+ # arguments in your code before calling your function.
41
+ #
42
+ # @return [String]
43
+ required :arguments, String
44
+
45
+ # @!attribute parsed
46
+ # The parsed contents of the arguments.
47
+ #
48
+ # @return [Object, nil]
49
+ required :parsed, OpenAI::StructuredOutput::ParsedJson
50
+
51
+ # @!attribute name
52
+ # The name of the function to call.
53
+ #
54
+ # @return [String]
55
+ required :name, String
56
+
57
+ # @!method initialize(arguments:, name:)
58
+ # Some parameter documentations has been truncated, see
59
+ # {OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall::Function} for more
60
+ # details.
61
+ #
62
+ # The function that the model called.
63
+ #
64
+ # @param arguments [String] The arguments to call the function with, as generated by the model in JSON forma
65
+ #
66
+ # @param name [String] The name of the function to call.
67
+ end
68
+ end
69
+ end
70
+
71
+ ChatCompletionMessageFunctionToolCall = Chat::ChatCompletionMessageFunctionToolCall
72
+ end
73
+ end
@@ -3,66 +3,20 @@
3
3
  module OpenAI
4
4
  module Models
5
5
  module Chat
6
- class ChatCompletionMessageToolCall < OpenAI::Internal::Type::BaseModel
7
- # @!attribute id
8
- # The ID of the tool call.
9
- #
10
- # @return [String]
11
- required :id, String
6
+ # A call to a function tool created by the model.
7
+ module ChatCompletionMessageToolCall
8
+ extend OpenAI::Internal::Type::Union
12
9
 
13
- # @!attribute function
14
- # The function that the model called.
15
- #
16
- # @return [OpenAI::Models::Chat::ChatCompletionMessageToolCall::Function]
17
- required :function, -> { OpenAI::Chat::ChatCompletionMessageToolCall::Function }
10
+ discriminator :type
18
11
 
19
- # @!attribute type
20
- # The type of the tool. Currently, only `function` is supported.
21
- #
22
- # @return [Symbol, :function]
23
- required :type, const: :function
12
+ # A call to a function tool created by the model.
13
+ variant :function, -> { OpenAI::Chat::ChatCompletionMessageFunctionToolCall }
24
14
 
25
- # @!method initialize(id:, function:, type: :function)
26
- # @param id [String] The ID of the tool call.
27
- #
28
- # @param function [OpenAI::Models::Chat::ChatCompletionMessageToolCall::Function] The function that the model called.
29
- #
30
- # @param type [Symbol, :function] The type of the tool. Currently, only `function` is supported.
15
+ # A call to a custom tool created by the model.
16
+ variant :custom, -> { OpenAI::Chat::ChatCompletionMessageCustomToolCall }
31
17
 
32
- # @see OpenAI::Models::Chat::ChatCompletionMessageToolCall#function
33
- class Function < OpenAI::Internal::Type::BaseModel
34
- # @!attribute arguments
35
- # The arguments to call the function with, as generated by the model in JSON
36
- # format. Note that the model does not always generate valid JSON, and may
37
- # hallucinate parameters not defined by your function schema. Validate the
38
- # arguments in your code before calling your function.
39
- #
40
- # @return [String]
41
- required :arguments, String
42
-
43
- # @!attribute parsed
44
- # The parsed contents of the arguments.
45
- #
46
- # @return [Object, nil]
47
- required :parsed, OpenAI::StructuredOutput::ParsedJson
48
-
49
- # @!attribute name
50
- # The name of the function to call.
51
- #
52
- # @return [String]
53
- required :name, String
54
-
55
- # @!method initialize(arguments:, name:)
56
- # Some parameter documentations has been truncated, see
57
- # {OpenAI::Models::Chat::ChatCompletionMessageToolCall::Function} for more
58
- # details.
59
- #
60
- # The function that the model called.
61
- #
62
- # @param arguments [String] The arguments to call the function with, as generated by the model in JSON forma
63
- #
64
- # @param name [String] The name of the function to call.
65
- end
18
+ # @!method self.variants
19
+ # @return [Array(OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall, OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall)]
66
20
  end
67
21
  end
68
22
 
@@ -10,7 +10,7 @@ module OpenAI
10
10
  required :function, -> { OpenAI::Chat::ChatCompletionNamedToolChoice::Function }
11
11
 
12
12
  # @!attribute type
13
- # The type of the tool. Currently, only `function` is supported.
13
+ # For function calling, the type is always `function`.
14
14
  #
15
15
  # @return [Symbol, :function]
16
16
  required :type, const: :function
@@ -21,7 +21,7 @@ module OpenAI
21
21
  #
22
22
  # @param function [OpenAI::Models::Chat::ChatCompletionNamedToolChoice::Function]
23
23
  #
24
- # @param type [Symbol, :function] The type of the tool. Currently, only `function` is supported.
24
+ # @param type [Symbol, :function] For function calling, the type is always `function`.
25
25
 
26
26
  # @see OpenAI::Models::Chat::ChatCompletionNamedToolChoice#function
27
27
  class Function < OpenAI::Internal::Type::BaseModel
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Chat
6
+ class ChatCompletionNamedToolChoiceCustom < OpenAI::Internal::Type::BaseModel
7
+ # @!attribute custom
8
+ #
9
+ # @return [OpenAI::Models::Chat::ChatCompletionNamedToolChoiceCustom::Custom]
10
+ required :custom, -> { OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::Custom }
11
+
12
+ # @!attribute type
13
+ # For custom tool calling, the type is always `custom`.
14
+ #
15
+ # @return [Symbol, :custom]
16
+ required :type, const: :custom
17
+
18
+ # @!method initialize(custom:, type: :custom)
19
+ # Specifies a tool the model should use. Use to force the model to call a specific
20
+ # custom tool.
21
+ #
22
+ # @param custom [OpenAI::Models::Chat::ChatCompletionNamedToolChoiceCustom::Custom]
23
+ #
24
+ # @param type [Symbol, :custom] For custom tool calling, the type is always `custom`.
25
+
26
+ # @see OpenAI::Models::Chat::ChatCompletionNamedToolChoiceCustom#custom
27
+ class Custom < OpenAI::Internal::Type::BaseModel
28
+ # @!attribute name
29
+ # The name of the custom tool to call.
30
+ #
31
+ # @return [String]
32
+ required :name, String
33
+
34
+ # @!method initialize(name:)
35
+ # @param name [String] The name of the custom tool to call.
36
+ end
37
+ end
38
+ end
39
+
40
+ ChatCompletionNamedToolChoiceCustom = Chat::ChatCompletionNamedToolChoiceCustom
41
+ end
42
+ end
@@ -10,10 +10,41 @@ module OpenAI
10
10
  # @return [String]
11
11
  required :id, String
12
12
 
13
- # @!method initialize(id:)
13
+ # @!attribute content_parts
14
+ # If a content parts array was provided, this is an array of `text` and
15
+ # `image_url` parts. Otherwise, null.
16
+ #
17
+ # @return [Array<OpenAI::Models::Chat::ChatCompletionContentPartText, OpenAI::Models::Chat::ChatCompletionContentPartImage>, nil]
18
+ optional :content_parts,
19
+ -> {
20
+ OpenAI::Internal::Type::ArrayOf[union: OpenAI::Chat::ChatCompletionStoreMessage::ContentPart]
21
+ },
22
+ nil?: true
23
+
24
+ # @!method initialize(id:, content_parts: nil)
25
+ # Some parameter documentations has been truncated, see
26
+ # {OpenAI::Models::Chat::ChatCompletionStoreMessage} for more details.
27
+ #
14
28
  # A chat completion message generated by the model.
15
29
  #
16
30
  # @param id [String] The identifier of the chat message.
31
+ #
32
+ # @param content_parts [Array<OpenAI::Models::Chat::ChatCompletionContentPartText, OpenAI::Models::Chat::ChatCompletionContentPartImage>, nil] If a content parts array was provided, this is an array of `text` and `image_url
33
+
34
+ # Learn about
35
+ # [text inputs](https://platform.openai.com/docs/guides/text-generation).
36
+ module ContentPart
37
+ extend OpenAI::Internal::Type::Union
38
+
39
+ # Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation).
40
+ variant -> { OpenAI::Chat::ChatCompletionContentPartText }
41
+
42
+ # Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
43
+ variant -> { OpenAI::Chat::ChatCompletionContentPartImage }
44
+
45
+ # @!method self.variants
46
+ # @return [Array(OpenAI::Models::Chat::ChatCompletionContentPartText, OpenAI::Models::Chat::ChatCompletionContentPartImage)]
47
+ end
17
48
  end
18
49
  end
19
50
 
@@ -4,6 +4,17 @@ module OpenAI
4
4
  module Models
5
5
  module Chat
6
6
  class ChatCompletionStreamOptions < OpenAI::Internal::Type::BaseModel
7
+ # @!attribute include_obfuscation
8
+ # When true, stream obfuscation will be enabled. Stream obfuscation adds random
9
+ # characters to an `obfuscation` field on streaming delta events to normalize
10
+ # payload sizes as a mitigation to certain side-channel attacks. These obfuscation
11
+ # fields are included by default, but add a small amount of overhead to the data
12
+ # stream. You can set `include_obfuscation` to false to optimize for bandwidth if
13
+ # you trust the network links between your application and the OpenAI API.
14
+ #
15
+ # @return [Boolean, nil]
16
+ optional :include_obfuscation, OpenAI::Internal::Type::Boolean
17
+
7
18
  # @!attribute include_usage
8
19
  # If set, an additional chunk will be streamed before the `data: [DONE]` message.
9
20
  # The `usage` field on this chunk shows the token usage statistics for the entire
@@ -16,12 +27,14 @@ module OpenAI
16
27
  # @return [Boolean, nil]
17
28
  optional :include_usage, OpenAI::Internal::Type::Boolean
18
29
 
19
- # @!method initialize(include_usage: nil)
30
+ # @!method initialize(include_obfuscation: nil, include_usage: nil)
20
31
  # Some parameter documentations has been truncated, see
21
32
  # {OpenAI::Models::Chat::ChatCompletionStreamOptions} for more details.
22
33
  #
23
34
  # Options for streaming response. Only set this when you set `stream: true`.
24
35
  #
36
+ # @param include_obfuscation [Boolean] When true, stream obfuscation will be enabled. Stream obfuscation adds
37
+ #
25
38
  # @param include_usage [Boolean] If set, an additional chunk will be streamed before the `data: [DONE]`
26
39
  end
27
40
  end
@@ -3,22 +3,20 @@
3
3
  module OpenAI
4
4
  module Models
5
5
  module Chat
6
- class ChatCompletionTool < OpenAI::Internal::Type::BaseModel
7
- # @!attribute function
8
- #
9
- # @return [OpenAI::Models::FunctionDefinition]
10
- required :function, -> { OpenAI::FunctionDefinition }
6
+ # A function tool that can be used to generate a response.
7
+ module ChatCompletionTool
8
+ extend OpenAI::Internal::Type::Union
11
9
 
12
- # @!attribute type
13
- # The type of the tool. Currently, only `function` is supported.
14
- #
15
- # @return [Symbol, :function]
16
- required :type, const: :function
10
+ discriminator :type
17
11
 
18
- # @!method initialize(function:, type: :function)
19
- # @param function [OpenAI::Models::FunctionDefinition]
20
- #
21
- # @param type [Symbol, :function] The type of the tool. Currently, only `function` is supported.
12
+ # A function tool that can be used to generate a response.
13
+ variant :function, -> { OpenAI::Chat::ChatCompletionFunctionTool }
14
+
15
+ # A custom tool that processes input using a specified format.
16
+ variant :custom, -> { OpenAI::Chat::ChatCompletionCustomTool }
17
+
18
+ # @!method self.variants
19
+ # @return [Array(OpenAI::Models::Chat::ChatCompletionFunctionTool, OpenAI::Models::Chat::ChatCompletionCustomTool)]
22
20
  end
23
21
  end
24
22
 
@@ -18,9 +18,15 @@ module OpenAI
18
18
  # `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools.
19
19
  variant enum: -> { OpenAI::Chat::ChatCompletionToolChoiceOption::Auto }
20
20
 
21
+ # Constrains the tools available to the model to a pre-defined set.
22
+ variant -> { OpenAI::Chat::ChatCompletionAllowedToolChoice }
23
+
21
24
  # Specifies a tool the model should use. Use to force the model to call a specific function.
22
25
  variant -> { OpenAI::Chat::ChatCompletionNamedToolChoice }
23
26
 
27
+ # Specifies a tool the model should use. Use to force the model to call a specific custom tool.
28
+ variant -> { OpenAI::Chat::ChatCompletionNamedToolChoiceCustom }
29
+
24
30
  # `none` means the model will not call any tool and instead generates a message.
25
31
  # `auto` means the model can pick between generating a message or calling one or
26
32
  # more tools. `required` means the model must call one or more tools.
@@ -36,7 +42,7 @@ module OpenAI
36
42
  end
37
43
 
38
44
  # @!method self.variants
39
- # @return [Array(Symbol, OpenAI::Models::Chat::ChatCompletionToolChoiceOption::Auto, OpenAI::Models::Chat::ChatCompletionNamedToolChoice)]
45
+ # @return [Array(Symbol, OpenAI::Models::Chat::ChatCompletionToolChoiceOption::Auto, OpenAI::Models::Chat::ChatCompletionAllowedToolChoice, OpenAI::Models::Chat::ChatCompletionNamedToolChoice, OpenAI::Models::Chat::ChatCompletionNamedToolChoiceCustom)]
40
46
  end
41
47
  end
42
48