openai 0.16.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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +14 -20
  4. data/lib/openai/internal/transport/base_client.rb +1 -1
  5. data/lib/openai/internal/type/enum.rb +6 -6
  6. data/lib/openai/internal/type/union.rb +13 -17
  7. data/lib/openai/models/beta/assistant_create_params.rb +4 -5
  8. data/lib/openai/models/beta/assistant_update_params.rb +22 -5
  9. data/lib/openai/models/beta/threads/run_create_params.rb +4 -5
  10. data/lib/openai/models/chat/chat_completion_allowed_tool_choice.rb +33 -0
  11. data/lib/openai/models/chat/chat_completion_allowed_tools.rb +64 -0
  12. data/lib/openai/models/chat/chat_completion_assistant_message_param.rb +3 -5
  13. data/lib/openai/models/chat/chat_completion_custom_tool.rb +163 -0
  14. data/lib/openai/models/chat/chat_completion_function_tool.rb +29 -0
  15. data/lib/openai/models/chat/chat_completion_message.rb +3 -5
  16. data/lib/openai/models/chat/chat_completion_message_custom_tool_call.rb +60 -0
  17. data/lib/openai/models/chat/chat_completion_message_function_tool_call.rb +73 -0
  18. data/lib/openai/models/chat/chat_completion_message_tool_call.rb +10 -56
  19. data/lib/openai/models/chat/chat_completion_named_tool_choice.rb +2 -2
  20. data/lib/openai/models/chat/chat_completion_named_tool_choice_custom.rb +42 -0
  21. data/lib/openai/models/chat/chat_completion_stream_options.rb +14 -1
  22. data/lib/openai/models/chat/chat_completion_tool.rb +12 -14
  23. data/lib/openai/models/chat/chat_completion_tool_choice_option.rb +7 -1
  24. data/lib/openai/models/chat/completion_create_params.rb +35 -12
  25. data/lib/openai/models/chat_model.rb +7 -0
  26. data/lib/openai/models/custom_tool_input_format.rb +76 -0
  27. data/lib/openai/models/evals/create_eval_completions_run_data_source.rb +3 -3
  28. data/lib/openai/models/evals/run_cancel_response.rb +2 -2
  29. data/lib/openai/models/evals/run_create_params.rb +2 -2
  30. data/lib/openai/models/evals/run_create_response.rb +2 -2
  31. data/lib/openai/models/evals/run_list_response.rb +2 -2
  32. data/lib/openai/models/evals/run_retrieve_response.rb +2 -2
  33. data/lib/openai/models/reasoning.rb +4 -5
  34. data/lib/openai/models/reasoning_effort.rb +4 -4
  35. data/lib/openai/models/response_format_text_grammar.rb +27 -0
  36. data/lib/openai/models/response_format_text_python.rb +20 -0
  37. data/lib/openai/models/responses/custom_tool.rb +48 -0
  38. data/lib/openai/models/responses/response.rb +20 -12
  39. data/lib/openai/models/responses/response_create_params.rb +48 -10
  40. data/lib/openai/models/responses/response_custom_tool_call.rb +55 -0
  41. data/lib/openai/models/responses/response_custom_tool_call_input_delta_event.rb +52 -0
  42. data/lib/openai/models/responses/response_custom_tool_call_input_done_event.rb +52 -0
  43. data/lib/openai/models/responses/response_custom_tool_call_output.rb +47 -0
  44. data/lib/openai/models/responses/response_input_item.rb +7 -1
  45. data/lib/openai/models/responses/response_output_item.rb +4 -1
  46. data/lib/openai/models/responses/response_output_item_added_event.rb +2 -2
  47. data/lib/openai/models/responses/response_output_item_done_event.rb +2 -2
  48. data/lib/openai/models/responses/response_reasoning_item.rb +36 -5
  49. data/lib/openai/models/responses/response_reasoning_text_delta_event.rb +63 -0
  50. data/lib/openai/models/responses/response_reasoning_text_done_event.rb +63 -0
  51. data/lib/openai/models/responses/response_retrieve_params.rb +14 -1
  52. data/lib/openai/models/responses/response_stream_event.rb +13 -11
  53. data/lib/openai/models/responses/response_text_config.rb +27 -1
  54. data/lib/openai/models/responses/tool.rb +5 -1
  55. data/lib/openai/models/responses/tool_choice_allowed.rb +73 -0
  56. data/lib/openai/models/responses/tool_choice_custom.rb +28 -0
  57. data/lib/openai/models/vector_store_search_params.rb +6 -1
  58. data/lib/openai/models.rb +6 -0
  59. data/lib/openai/resources/beta/assistants.rb +2 -2
  60. data/lib/openai/resources/beta/threads/runs.rb +2 -2
  61. data/lib/openai/resources/chat/completions.rb +16 -10
  62. data/lib/openai/resources/responses.rb +38 -22
  63. data/lib/openai/version.rb +1 -1
  64. data/lib/openai.rb +19 -2
  65. data/rbi/openai/internal/transport/base_client.rbi +1 -1
  66. data/rbi/openai/models/beta/assistant_create_params.rbi +6 -8
  67. data/rbi/openai/models/beta/assistant_update_params.rbi +36 -8
  68. data/rbi/openai/models/beta/threads/run_create_params.rbi +6 -8
  69. data/rbi/openai/models/chat/chat_completion_allowed_tool_choice.rbi +60 -0
  70. data/rbi/openai/models/chat/chat_completion_allowed_tools.rbi +118 -0
  71. data/rbi/openai/models/chat/chat_completion_assistant_message_param.rbi +27 -4
  72. data/rbi/openai/models/chat/chat_completion_custom_tool.rbi +335 -0
  73. data/rbi/openai/models/chat/chat_completion_function_tool.rbi +51 -0
  74. data/rbi/openai/models/chat/chat_completion_message.rbi +17 -4
  75. data/rbi/openai/models/chat/chat_completion_message_custom_tool_call.rbi +105 -0
  76. data/rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi +118 -0
  77. data/rbi/openai/models/chat/chat_completion_message_tool_call.rbi +9 -92
  78. data/rbi/openai/models/chat/chat_completion_named_tool_choice.rbi +2 -2
  79. data/rbi/openai/models/chat/chat_completion_named_tool_choice_custom.rbi +89 -0
  80. data/rbi/openai/models/chat/chat_completion_stream_options.rbi +30 -2
  81. data/rbi/openai/models/chat/chat_completion_tool.rbi +11 -30
  82. data/rbi/openai/models/chat/chat_completion_tool_choice_option.rbi +3 -1
  83. data/rbi/openai/models/chat/completion_create_params.rbi +106 -25
  84. data/rbi/openai/models/chat_model.rbi +11 -0
  85. data/rbi/openai/models/custom_tool_input_format.rbi +136 -0
  86. data/rbi/openai/models/evals/create_eval_completions_run_data_source.rbi +8 -4
  87. data/rbi/openai/models/evals/run_cancel_response.rbi +2 -0
  88. data/rbi/openai/models/evals/run_create_params.rbi +4 -0
  89. data/rbi/openai/models/evals/run_create_response.rbi +2 -0
  90. data/rbi/openai/models/evals/run_list_response.rbi +2 -0
  91. data/rbi/openai/models/evals/run_retrieve_response.rbi +2 -0
  92. data/rbi/openai/models/reasoning.rbi +6 -8
  93. data/rbi/openai/models/reasoning_effort.rbi +4 -4
  94. data/rbi/openai/models/response_format_text_grammar.rbi +35 -0
  95. data/rbi/openai/models/response_format_text_python.rbi +30 -0
  96. data/rbi/openai/models/responses/custom_tool.rbi +96 -0
  97. data/rbi/openai/models/responses/response.rbi +15 -5
  98. data/rbi/openai/models/responses/response_create_params.rbi +94 -7
  99. data/rbi/openai/models/responses/response_custom_tool_call.rbi +78 -0
  100. data/rbi/openai/models/responses/response_custom_tool_call_input_delta_event.rbi +75 -0
  101. data/rbi/openai/models/responses/response_custom_tool_call_input_done_event.rbi +75 -0
  102. data/rbi/openai/models/responses/response_custom_tool_call_output.rbi +65 -0
  103. data/rbi/openai/models/responses/response_input_item.rbi +2 -0
  104. data/rbi/openai/models/responses/response_output_item.rbi +2 -1
  105. data/rbi/openai/models/responses/response_output_item_added_event.rbi +2 -1
  106. data/rbi/openai/models/responses/response_output_item_done_event.rbi +2 -1
  107. data/rbi/openai/models/responses/response_reasoning_item.rbi +63 -4
  108. data/rbi/openai/models/responses/response_reasoning_text_delta_event.rbi +83 -0
  109. data/rbi/openai/models/responses/{response_reasoning_summary_done_event.rbi → response_reasoning_text_done_event.rbi} +20 -20
  110. data/rbi/openai/models/responses/response_retrieve_params.rbi +21 -0
  111. data/rbi/openai/models/responses/response_stream_event.rbi +4 -2
  112. data/rbi/openai/models/responses/response_text_config.rbi +64 -1
  113. data/rbi/openai/models/responses/tool.rbi +1 -0
  114. data/rbi/openai/models/responses/tool_choice_allowed.rbi +124 -0
  115. data/rbi/openai/models/responses/tool_choice_custom.rbi +39 -0
  116. data/rbi/openai/models/vector_store_search_params.rbi +12 -1
  117. data/rbi/openai/models.rbi +6 -0
  118. data/rbi/openai/resources/beta/assistants.rbi +6 -8
  119. data/rbi/openai/resources/beta/threads/runs.rbi +8 -10
  120. data/rbi/openai/resources/chat/completions.rbi +44 -19
  121. data/rbi/openai/resources/responses.rbi +215 -41
  122. data/sig/openai/internal/transport/base_client.rbs +1 -1
  123. data/sig/openai/models/beta/assistant_update_params.rbs +12 -0
  124. data/sig/openai/models/chat/chat_completion_allowed_tool_choice.rbs +29 -0
  125. data/sig/openai/models/chat/chat_completion_allowed_tools.rbs +38 -0
  126. data/sig/openai/models/chat/chat_completion_assistant_message_param.rbs +6 -6
  127. data/sig/openai/models/chat/chat_completion_custom_tool.rbs +137 -0
  128. data/sig/openai/models/chat/chat_completion_function_tool.rbs +26 -0
  129. data/sig/openai/models/chat/chat_completion_message.rbs +6 -6
  130. data/sig/openai/models/chat/chat_completion_message_custom_tool_call.rbs +46 -0
  131. data/sig/openai/models/chat/chat_completion_message_function_tool_call.rbs +46 -0
  132. data/sig/openai/models/chat/chat_completion_message_tool_call.rbs +6 -35
  133. data/sig/openai/models/chat/chat_completion_named_tool_choice_custom.rbs +39 -0
  134. data/sig/openai/models/chat/chat_completion_stream_options.rbs +11 -3
  135. data/sig/openai/models/chat/chat_completion_tool.rbs +6 -15
  136. data/sig/openai/models/chat/chat_completion_tool_choice_option.rbs +2 -0
  137. data/sig/openai/models/chat/completion_create_params.rbs +23 -6
  138. data/sig/openai/models/chat_model.rbs +15 -1
  139. data/sig/openai/models/custom_tool_input_format.rbs +61 -0
  140. data/sig/openai/models/evals/create_eval_completions_run_data_source.rbs +6 -6
  141. data/sig/openai/models/reasoning_effort.rbs +2 -1
  142. data/sig/openai/models/response_format_text_grammar.rbs +15 -0
  143. data/sig/openai/models/response_format_text_python.rbs +13 -0
  144. data/sig/openai/models/responses/custom_tool.rbs +43 -0
  145. data/sig/openai/models/responses/response.rbs +2 -0
  146. data/sig/openai/models/responses/response_create_params.rbs +19 -0
  147. data/sig/openai/models/responses/response_custom_tool_call.rbs +44 -0
  148. data/sig/openai/models/responses/response_custom_tool_call_input_delta_event.rbs +42 -0
  149. data/sig/openai/models/responses/response_custom_tool_call_input_done_event.rbs +42 -0
  150. data/sig/openai/models/responses/response_custom_tool_call_output.rbs +39 -0
  151. data/sig/openai/models/responses/response_input_item.rbs +2 -0
  152. data/sig/openai/models/responses/response_output_item.rbs +1 -0
  153. data/sig/openai/models/responses/response_reasoning_item.rbs +21 -0
  154. data/sig/openai/models/responses/{response_reasoning_summary_delta_event.rbs → response_reasoning_text_delta_event.rbs} +15 -15
  155. data/sig/openai/models/responses/{response_reasoning_summary_done_event.rbs → response_reasoning_text_done_event.rbs} +11 -11
  156. data/sig/openai/models/responses/response_retrieve_params.rbs +7 -0
  157. data/sig/openai/models/responses/response_stream_event.rbs +4 -2
  158. data/sig/openai/models/responses/response_text_config.rbs +22 -3
  159. data/sig/openai/models/responses/tool.rbs +1 -0
  160. data/sig/openai/models/responses/tool_choice_allowed.rbs +43 -0
  161. data/sig/openai/models/responses/tool_choice_custom.rbs +17 -0
  162. data/sig/openai/models/vector_store_search_params.rbs +2 -1
  163. data/sig/openai/models.rbs +6 -0
  164. data/sig/openai/resources/chat/completions.rbs +4 -2
  165. data/sig/openai/resources/responses.rbs +32 -0
  166. metadata +59 -8
  167. data/lib/openai/models/responses/response_reasoning_summary_delta_event.rb +0 -65
  168. data/lib/openai/models/responses/response_reasoning_summary_done_event.rb +0 -60
  169. data/rbi/openai/models/responses/response_reasoning_summary_delta_event.rbi +0 -85
@@ -0,0 +1,51 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ ChatCompletionFunctionTool = Chat::ChatCompletionFunctionTool
6
+
7
+ module Chat
8
+ class ChatCompletionFunctionTool < OpenAI::Internal::Type::BaseModel
9
+ OrHash =
10
+ T.type_alias do
11
+ T.any(
12
+ OpenAI::Chat::ChatCompletionFunctionTool,
13
+ OpenAI::Internal::AnyHash
14
+ )
15
+ end
16
+
17
+ sig { returns(OpenAI::FunctionDefinition) }
18
+ attr_reader :function
19
+
20
+ sig { params(function: OpenAI::FunctionDefinition::OrHash).void }
21
+ attr_writer :function
22
+
23
+ # The type of the tool. Currently, only `function` is supported.
24
+ sig { returns(Symbol) }
25
+ attr_accessor :type
26
+
27
+ # A function tool that can be used to generate a response.
28
+ sig do
29
+ params(
30
+ function: OpenAI::FunctionDefinition::OrHash,
31
+ type: Symbol
32
+ ).returns(T.attached_class)
33
+ end
34
+ def self.new(
35
+ function:,
36
+ # The type of the tool. Currently, only `function` is supported.
37
+ type: :function
38
+ )
39
+ end
40
+
41
+ sig do
42
+ override.returns(
43
+ { function: OpenAI::FunctionDefinition, type: Symbol }
44
+ )
45
+ end
46
+ def to_hash
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -78,7 +78,9 @@ module OpenAI
78
78
  # The tool calls generated by the model, such as function calls.
79
79
  sig do
80
80
  returns(
81
- T.nilable(T::Array[OpenAI::Chat::ChatCompletionMessageToolCall])
81
+ T.nilable(
82
+ T::Array[OpenAI::Chat::ChatCompletionMessageToolCall::Variants]
83
+ )
82
84
  )
83
85
  end
84
86
  attr_reader :tool_calls
@@ -86,7 +88,12 @@ module OpenAI
86
88
  sig do
87
89
  params(
88
90
  tool_calls:
89
- T::Array[OpenAI::Chat::ChatCompletionMessageToolCall::OrHash]
91
+ T::Array[
92
+ T.any(
93
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall::OrHash,
94
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall::OrHash
95
+ )
96
+ ]
90
97
  ).void
91
98
  end
92
99
  attr_writer :tool_calls
@@ -102,7 +109,12 @@ module OpenAI
102
109
  function_call:
103
110
  OpenAI::Chat::ChatCompletionMessage::FunctionCall::OrHash,
104
111
  tool_calls:
105
- T::Array[OpenAI::Chat::ChatCompletionMessageToolCall::OrHash],
112
+ T::Array[
113
+ T.any(
114
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall::OrHash,
115
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall::OrHash
116
+ )
117
+ ],
106
118
  role: Symbol
107
119
  ).returns(T.attached_class)
108
120
  end
@@ -138,7 +150,8 @@ module OpenAI
138
150
  T::Array[OpenAI::Chat::ChatCompletionMessage::Annotation],
139
151
  audio: T.nilable(OpenAI::Chat::ChatCompletionAudio),
140
152
  function_call: OpenAI::Chat::ChatCompletionMessage::FunctionCall,
141
- tool_calls: T::Array[OpenAI::Chat::ChatCompletionMessageToolCall]
153
+ tool_calls:
154
+ T::Array[OpenAI::Chat::ChatCompletionMessageToolCall::Variants]
142
155
  }
143
156
  )
144
157
  end
@@ -0,0 +1,105 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ ChatCompletionMessageCustomToolCall =
6
+ Chat::ChatCompletionMessageCustomToolCall
7
+
8
+ module Chat
9
+ class ChatCompletionMessageCustomToolCall < OpenAI::Internal::Type::BaseModel
10
+ OrHash =
11
+ T.type_alias do
12
+ T.any(
13
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall,
14
+ OpenAI::Internal::AnyHash
15
+ )
16
+ end
17
+
18
+ # The ID of the tool call.
19
+ sig { returns(String) }
20
+ attr_accessor :id
21
+
22
+ # The custom tool that the model called.
23
+ sig do
24
+ returns(OpenAI::Chat::ChatCompletionMessageCustomToolCall::Custom)
25
+ end
26
+ attr_reader :custom
27
+
28
+ sig do
29
+ params(
30
+ custom:
31
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall::Custom::OrHash
32
+ ).void
33
+ end
34
+ attr_writer :custom
35
+
36
+ # The type of the tool. Always `custom`.
37
+ sig { returns(Symbol) }
38
+ attr_accessor :type
39
+
40
+ # A call to a custom tool created by the model.
41
+ sig do
42
+ params(
43
+ id: String,
44
+ custom:
45
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall::Custom::OrHash,
46
+ type: Symbol
47
+ ).returns(T.attached_class)
48
+ end
49
+ def self.new(
50
+ # The ID of the tool call.
51
+ id:,
52
+ # The custom tool that the model called.
53
+ custom:,
54
+ # The type of the tool. Always `custom`.
55
+ type: :custom
56
+ )
57
+ end
58
+
59
+ sig do
60
+ override.returns(
61
+ {
62
+ id: String,
63
+ custom: OpenAI::Chat::ChatCompletionMessageCustomToolCall::Custom,
64
+ type: Symbol
65
+ }
66
+ )
67
+ end
68
+ def to_hash
69
+ end
70
+
71
+ class Custom < OpenAI::Internal::Type::BaseModel
72
+ OrHash =
73
+ T.type_alias do
74
+ T.any(
75
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall::Custom,
76
+ OpenAI::Internal::AnyHash
77
+ )
78
+ end
79
+
80
+ # The input for the custom tool call generated by the model.
81
+ sig { returns(String) }
82
+ attr_accessor :input
83
+
84
+ # The name of the custom tool to call.
85
+ sig { returns(String) }
86
+ attr_accessor :name
87
+
88
+ # The custom tool that the model called.
89
+ sig { params(input: String, name: String).returns(T.attached_class) }
90
+ def self.new(
91
+ # The input for the custom tool call generated by the model.
92
+ input:,
93
+ # The name of the custom tool to call.
94
+ name:
95
+ )
96
+ end
97
+
98
+ sig { override.returns({ input: String, name: String }) }
99
+ def to_hash
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,118 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ ChatCompletionMessageFunctionToolCall =
6
+ Chat::ChatCompletionMessageFunctionToolCall
7
+
8
+ module Chat
9
+ class ChatCompletionMessageFunctionToolCall < OpenAI::Internal::Type::BaseModel
10
+ OrHash =
11
+ T.type_alias do
12
+ T.any(
13
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall,
14
+ OpenAI::Internal::AnyHash
15
+ )
16
+ end
17
+
18
+ # The ID of the tool call.
19
+ sig { returns(String) }
20
+ attr_accessor :id
21
+
22
+ # The function that the model called.
23
+ sig do
24
+ returns(OpenAI::Chat::ChatCompletionMessageFunctionToolCall::Function)
25
+ end
26
+ attr_reader :function
27
+
28
+ sig do
29
+ params(
30
+ function:
31
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall::Function::OrHash
32
+ ).void
33
+ end
34
+ attr_writer :function
35
+
36
+ # The type of the tool. Currently, only `function` is supported.
37
+ sig { returns(Symbol) }
38
+ attr_accessor :type
39
+
40
+ # A call to a function tool created by the model.
41
+ sig do
42
+ params(
43
+ id: String,
44
+ function:
45
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall::Function::OrHash,
46
+ type: Symbol
47
+ ).returns(T.attached_class)
48
+ end
49
+ def self.new(
50
+ # The ID of the tool call.
51
+ id:,
52
+ # The function that the model called.
53
+ function:,
54
+ # The type of the tool. Currently, only `function` is supported.
55
+ type: :function
56
+ )
57
+ end
58
+
59
+ sig do
60
+ override.returns(
61
+ {
62
+ id: String,
63
+ function:
64
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall::Function,
65
+ type: Symbol
66
+ }
67
+ )
68
+ end
69
+ def to_hash
70
+ end
71
+
72
+ class Function < OpenAI::Internal::Type::BaseModel
73
+ OrHash =
74
+ T.type_alias do
75
+ T.any(
76
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall::Function,
77
+ OpenAI::Internal::AnyHash
78
+ )
79
+ end
80
+
81
+ # The arguments to call the function with, as generated by the model in JSON
82
+ # format. Note that the model does not always generate valid JSON, and may
83
+ # hallucinate parameters not defined by your function schema. Validate the
84
+ # arguments in your code before calling your function.
85
+ sig { returns(String) }
86
+ attr_accessor :arguments
87
+
88
+ # The parsed contents of the arguments.
89
+ sig { returns(T.anything) }
90
+ attr_accessor :parsed
91
+
92
+ # The name of the function to call.
93
+ sig { returns(String) }
94
+ attr_accessor :name
95
+
96
+ # The function that the model called.
97
+ sig do
98
+ params(arguments: String, name: String).returns(T.attached_class)
99
+ end
100
+ def self.new(
101
+ # The arguments to call the function with, as generated by the model in JSON
102
+ # format. Note that the model does not always generate valid JSON, and may
103
+ # hallucinate parameters not defined by your function schema. Validate the
104
+ # arguments in your code before calling your function.
105
+ arguments:,
106
+ # The name of the function to call.
107
+ name:
108
+ )
109
+ end
110
+
111
+ sig { override.returns({ arguments: String, name: String }) }
112
+ def to_hash
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -5,107 +5,24 @@ module OpenAI
5
5
  ChatCompletionMessageToolCall = Chat::ChatCompletionMessageToolCall
6
6
 
7
7
  module Chat
8
- class ChatCompletionMessageToolCall < OpenAI::Internal::Type::BaseModel
9
- OrHash =
8
+ # A call to a function tool created by the model.
9
+ module ChatCompletionMessageToolCall
10
+ extend OpenAI::Internal::Type::Union
11
+
12
+ Variants =
10
13
  T.type_alias do
11
14
  T.any(
12
- OpenAI::Chat::ChatCompletionMessageToolCall,
13
- OpenAI::Internal::AnyHash
15
+ OpenAI::Chat::ChatCompletionMessageFunctionToolCall,
16
+ OpenAI::Chat::ChatCompletionMessageCustomToolCall
14
17
  )
15
18
  end
16
19
 
17
- # The ID of the tool call.
18
- sig { returns(String) }
19
- attr_accessor :id
20
-
21
- # The function that the model called.
22
- sig { returns(OpenAI::Chat::ChatCompletionMessageToolCall::Function) }
23
- attr_reader :function
24
-
25
- sig do
26
- params(
27
- function:
28
- OpenAI::Chat::ChatCompletionMessageToolCall::Function::OrHash
29
- ).void
30
- end
31
- attr_writer :function
32
-
33
- # The type of the tool. Currently, only `function` is supported.
34
- sig { returns(Symbol) }
35
- attr_accessor :type
36
-
37
- sig do
38
- params(
39
- id: String,
40
- function:
41
- OpenAI::Chat::ChatCompletionMessageToolCall::Function::OrHash,
42
- type: Symbol
43
- ).returns(T.attached_class)
44
- end
45
- def self.new(
46
- # The ID of the tool call.
47
- id:,
48
- # The function that the model called.
49
- function:,
50
- # The type of the tool. Currently, only `function` is supported.
51
- type: :function
52
- )
53
- end
54
-
55
20
  sig do
56
21
  override.returns(
57
- {
58
- id: String,
59
- function: OpenAI::Chat::ChatCompletionMessageToolCall::Function,
60
- type: Symbol
61
- }
22
+ T::Array[OpenAI::Chat::ChatCompletionMessageToolCall::Variants]
62
23
  )
63
24
  end
64
- def to_hash
65
- end
66
-
67
- class Function < OpenAI::Internal::Type::BaseModel
68
- OrHash =
69
- T.type_alias do
70
- T.any(
71
- OpenAI::Chat::ChatCompletionMessageToolCall::Function,
72
- OpenAI::Internal::AnyHash
73
- )
74
- end
75
-
76
- # The arguments to call the function with, as generated by the model in JSON
77
- # format. Note that the model does not always generate valid JSON, and may
78
- # hallucinate parameters not defined by your function schema. Validate the
79
- # arguments in your code before calling your function.
80
- sig { returns(String) }
81
- attr_accessor :arguments
82
-
83
- # The parsed contents of the arguments.
84
- sig { returns(T.anything) }
85
- attr_accessor :parsed
86
-
87
- # The name of the function to call.
88
- sig { returns(String) }
89
- attr_accessor :name
90
-
91
- # The function that the model called.
92
- sig do
93
- params(arguments: String, name: String).returns(T.attached_class)
94
- end
95
- def self.new(
96
- # The arguments to call the function with, as generated by the model in JSON
97
- # format. Note that the model does not always generate valid JSON, and may
98
- # hallucinate parameters not defined by your function schema. Validate the
99
- # arguments in your code before calling your function.
100
- arguments:,
101
- # The name of the function to call.
102
- name:
103
- )
104
- end
105
-
106
- sig { override.returns({ arguments: String, name: String }) }
107
- def to_hash
108
- end
25
+ def self.variants
109
26
  end
110
27
  end
111
28
  end
@@ -25,7 +25,7 @@ module OpenAI
25
25
  end
26
26
  attr_writer :function
27
27
 
28
- # The type of the tool. Currently, only `function` is supported.
28
+ # For function calling, the type is always `function`.
29
29
  sig { returns(Symbol) }
30
30
  attr_accessor :type
31
31
 
@@ -40,7 +40,7 @@ module OpenAI
40
40
  end
41
41
  def self.new(
42
42
  function:,
43
- # The type of the tool. Currently, only `function` is supported.
43
+ # For function calling, the type is always `function`.
44
44
  type: :function
45
45
  )
46
46
  end
@@ -0,0 +1,89 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ ChatCompletionNamedToolChoiceCustom =
6
+ Chat::ChatCompletionNamedToolChoiceCustom
7
+
8
+ module Chat
9
+ class ChatCompletionNamedToolChoiceCustom < OpenAI::Internal::Type::BaseModel
10
+ OrHash =
11
+ T.type_alias do
12
+ T.any(
13
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom,
14
+ OpenAI::Internal::AnyHash
15
+ )
16
+ end
17
+
18
+ sig do
19
+ returns(OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::Custom)
20
+ end
21
+ attr_reader :custom
22
+
23
+ sig do
24
+ params(
25
+ custom:
26
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::Custom::OrHash
27
+ ).void
28
+ end
29
+ attr_writer :custom
30
+
31
+ # For custom tool calling, the type is always `custom`.
32
+ sig { returns(Symbol) }
33
+ attr_accessor :type
34
+
35
+ # Specifies a tool the model should use. Use to force the model to call a specific
36
+ # custom tool.
37
+ sig do
38
+ params(
39
+ custom:
40
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::Custom::OrHash,
41
+ type: Symbol
42
+ ).returns(T.attached_class)
43
+ end
44
+ def self.new(
45
+ custom:,
46
+ # For custom tool calling, the type is always `custom`.
47
+ type: :custom
48
+ )
49
+ end
50
+
51
+ sig do
52
+ override.returns(
53
+ {
54
+ custom: OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::Custom,
55
+ type: Symbol
56
+ }
57
+ )
58
+ end
59
+ def to_hash
60
+ end
61
+
62
+ class Custom < OpenAI::Internal::Type::BaseModel
63
+ OrHash =
64
+ T.type_alias do
65
+ T.any(
66
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::Custom,
67
+ OpenAI::Internal::AnyHash
68
+ )
69
+ end
70
+
71
+ # The name of the custom tool to call.
72
+ sig { returns(String) }
73
+ attr_accessor :name
74
+
75
+ sig { params(name: String).returns(T.attached_class) }
76
+ def self.new(
77
+ # The name of the custom tool to call.
78
+ name:
79
+ )
80
+ end
81
+
82
+ sig { override.returns({ name: String }) }
83
+ def to_hash
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -14,6 +14,18 @@ module OpenAI
14
14
  )
15
15
  end
16
16
 
17
+ # When true, stream obfuscation will be enabled. Stream obfuscation adds random
18
+ # characters to an `obfuscation` field on streaming delta events to normalize
19
+ # payload sizes as a mitigation to certain side-channel attacks. These obfuscation
20
+ # fields are included by default, but add a small amount of overhead to the data
21
+ # stream. You can set `include_obfuscation` to false to optimize for bandwidth if
22
+ # you trust the network links between your application and the OpenAI API.
23
+ sig { returns(T.nilable(T::Boolean)) }
24
+ attr_reader :include_obfuscation
25
+
26
+ sig { params(include_obfuscation: T::Boolean).void }
27
+ attr_writer :include_obfuscation
28
+
17
29
  # If set, an additional chunk will be streamed before the `data: [DONE]` message.
18
30
  # The `usage` field on this chunk shows the token usage statistics for the entire
19
31
  # request, and the `choices` field will always be an empty array.
@@ -28,8 +40,20 @@ module OpenAI
28
40
  attr_writer :include_usage
29
41
 
30
42
  # Options for streaming response. Only set this when you set `stream: true`.
31
- sig { params(include_usage: T::Boolean).returns(T.attached_class) }
43
+ sig do
44
+ params(
45
+ include_obfuscation: T::Boolean,
46
+ include_usage: T::Boolean
47
+ ).returns(T.attached_class)
48
+ end
32
49
  def self.new(
50
+ # When true, stream obfuscation will be enabled. Stream obfuscation adds random
51
+ # characters to an `obfuscation` field on streaming delta events to normalize
52
+ # payload sizes as a mitigation to certain side-channel attacks. These obfuscation
53
+ # fields are included by default, but add a small amount of overhead to the data
54
+ # stream. You can set `include_obfuscation` to false to optimize for bandwidth if
55
+ # you trust the network links between your application and the OpenAI API.
56
+ include_obfuscation: nil,
33
57
  # If set, an additional chunk will be streamed before the `data: [DONE]` message.
34
58
  # The `usage` field on this chunk shows the token usage statistics for the entire
35
59
  # request, and the `choices` field will always be an empty array.
@@ -41,7 +65,11 @@ module OpenAI
41
65
  )
42
66
  end
43
67
 
44
- sig { override.returns({ include_usage: T::Boolean }) }
68
+ sig do
69
+ override.returns(
70
+ { include_obfuscation: T::Boolean, include_usage: T::Boolean }
71
+ )
72
+ end
45
73
  def to_hash
46
74
  end
47
75
  end
@@ -5,41 +5,22 @@ module OpenAI
5
5
  ChatCompletionTool = Chat::ChatCompletionTool
6
6
 
7
7
  module Chat
8
- class ChatCompletionTool < OpenAI::Internal::Type::BaseModel
9
- OrHash =
8
+ # A function tool that can be used to generate a response.
9
+ module ChatCompletionTool
10
+ extend OpenAI::Internal::Type::Union
11
+
12
+ Variants =
10
13
  T.type_alias do
11
- T.any(OpenAI::Chat::ChatCompletionTool, OpenAI::Internal::AnyHash)
14
+ T.any(
15
+ OpenAI::Chat::ChatCompletionFunctionTool,
16
+ OpenAI::Chat::ChatCompletionCustomTool
17
+ )
12
18
  end
13
19
 
14
- sig { returns(OpenAI::FunctionDefinition) }
15
- attr_reader :function
16
-
17
- sig { params(function: OpenAI::FunctionDefinition::OrHash).void }
18
- attr_writer :function
19
-
20
- # The type of the tool. Currently, only `function` is supported.
21
- sig { returns(Symbol) }
22
- attr_accessor :type
23
-
24
- sig do
25
- params(
26
- function: OpenAI::FunctionDefinition::OrHash,
27
- type: Symbol
28
- ).returns(T.attached_class)
29
- end
30
- def self.new(
31
- function:,
32
- # The type of the tool. Currently, only `function` is supported.
33
- type: :function
34
- )
35
- end
36
-
37
20
  sig do
38
- override.returns(
39
- { function: OpenAI::FunctionDefinition, type: Symbol }
40
- )
21
+ override.returns(T::Array[OpenAI::Chat::ChatCompletionTool::Variants])
41
22
  end
42
- def to_hash
23
+ def self.variants
43
24
  end
44
25
  end
45
26
  end
@@ -21,7 +21,9 @@ module OpenAI
21
21
  T.type_alias do
22
22
  T.any(
23
23
  OpenAI::Chat::ChatCompletionToolChoiceOption::Auto::TaggedSymbol,
24
- OpenAI::Chat::ChatCompletionNamedToolChoice
24
+ OpenAI::Chat::ChatCompletionAllowedToolChoice,
25
+ OpenAI::Chat::ChatCompletionNamedToolChoice,
26
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom
25
27
  )
26
28
  end
27
29