openai 0.106.0 → 0.108.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 (111) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -0
  3. data/README.md +49 -1
  4. data/examples/chat/tool_runner.rb +33 -0
  5. data/lib/openai/client.rb +2 -2
  6. data/lib/openai/helpers/chat/tool_runner.rb +259 -0
  7. data/lib/openai/helpers/live/websocket.rb +12 -141
  8. data/lib/openai/helpers/local_audio/process.rb +13 -3
  9. data/lib/openai/helpers/models/embedding.rb +42 -0
  10. data/lib/openai/helpers/realtime/connection.rb +22 -5
  11. data/lib/openai/helpers/realtime/recovery.rb +19 -7
  12. data/lib/openai/helpers/realtime/translation.rb +37 -169
  13. data/lib/openai/helpers/realtime/unknown_server_event.rb +5 -12
  14. data/lib/openai/helpers/responses_websocket/connection.rb +56 -35
  15. data/lib/openai/helpers/responses_websocket/incremental.rb +5 -1
  16. data/lib/openai/helpers/responses_websocket/session.rb +11 -4
  17. data/lib/openai/helpers/responses_websocket/unknown_server_event.rb +2 -14
  18. data/lib/openai/helpers/streaming/chat_completion_resource.rb +52 -0
  19. data/lib/openai/helpers/websocket/async_websocket_transport.rb +8 -6
  20. data/lib/openai/helpers/websocket/client_request.rb +1 -1
  21. data/lib/openai/helpers/websocket/connection.rb +21 -10
  22. data/lib/openai/helpers/websocket/connection_manager.rb +2 -1
  23. data/lib/openai/helpers/websocket/protocol.rb +160 -0
  24. data/lib/openai/helpers/websocket/typed_connection.rb +22 -16
  25. data/lib/openai/helpers/websocket/typed_resource.rb +15 -0
  26. data/lib/openai/internal/transport/base_client.rb +1 -1
  27. data/lib/openai/models/admin/organization/usage_audio_speeches_response.rb +16 -5
  28. data/lib/openai/models/admin/organization/usage_audio_transcriptions_response.rb +16 -5
  29. data/lib/openai/models/admin/organization/usage_code_interpreter_sessions_response.rb +16 -5
  30. data/lib/openai/models/admin/organization/usage_completions_response.rb +16 -5
  31. data/lib/openai/models/admin/organization/usage_costs_response.rb +16 -5
  32. data/lib/openai/models/admin/organization/usage_decisions_response.rb +14 -3
  33. data/lib/openai/models/admin/organization/usage_embeddings_response.rb +16 -5
  34. data/lib/openai/models/admin/organization/usage_file_search_calls_response.rb +16 -5
  35. data/lib/openai/models/admin/organization/usage_images_response.rb +16 -5
  36. data/lib/openai/models/admin/organization/usage_moderations_response.rb +16 -5
  37. data/lib/openai/models/admin/organization/usage_vector_stores_response.rb +16 -5
  38. data/lib/openai/models/admin/organization/usage_web_search_calls_response.rb +16 -5
  39. data/lib/openai/models/audio/voice_consent.rb +58 -0
  40. data/lib/openai/models/audio/voice_consent_create_params.rb +57 -0
  41. data/lib/openai/models/audio/voice_consent_delete_params.rb +22 -0
  42. data/lib/openai/models/audio/voice_consent_deleted.rb +34 -0
  43. data/lib/openai/models/audio/voice_consent_list_params.rb +42 -0
  44. data/lib/openai/models/audio/voice_consent_retrieve_params.rb +22 -0
  45. data/lib/openai/models/audio/voice_consent_update_params.rb +32 -0
  46. data/lib/openai/models/beta/beta_response_input_item.rb +10 -1
  47. data/lib/openai/models/responses/response_input_item.rb +10 -1
  48. data/lib/openai/resources/audio/voice_consents.rb +163 -0
  49. data/lib/openai/resources/audio.rb +5 -0
  50. data/lib/openai/version.rb +1 -1
  51. data/lib/openai.rb +9 -0
  52. data/rbi/openai/client.rbi +1 -8
  53. data/rbi/openai/helpers/chat/tool_runner.rbi +74 -0
  54. data/rbi/openai/helpers/realtime/translation.rbi +0 -5
  55. data/rbi/openai/helpers/realtime/unknown_server_event.rbi +6 -0
  56. data/rbi/openai/helpers/websocket.rbi +44 -6
  57. data/rbi/openai/internal/transport/base_client.rbi +2 -6
  58. data/rbi/openai/models/admin/organization/usage_audio_speeches_response.rbi +14 -2
  59. data/rbi/openai/models/admin/organization/usage_audio_transcriptions_response.rbi +14 -2
  60. data/rbi/openai/models/admin/organization/usage_code_interpreter_sessions_response.rbi +14 -2
  61. data/rbi/openai/models/admin/organization/usage_completions_response.rbi +14 -2
  62. data/rbi/openai/models/admin/organization/usage_costs_response.rbi +14 -2
  63. data/rbi/openai/models/admin/organization/usage_decisions_response.rbi +12 -0
  64. data/rbi/openai/models/admin/organization/usage_embeddings_response.rbi +14 -2
  65. data/rbi/openai/models/admin/organization/usage_file_search_calls_response.rbi +14 -2
  66. data/rbi/openai/models/admin/organization/usage_images_response.rbi +14 -2
  67. data/rbi/openai/models/admin/organization/usage_moderations_response.rbi +14 -2
  68. data/rbi/openai/models/admin/organization/usage_vector_stores_response.rbi +14 -2
  69. data/rbi/openai/models/admin/organization/usage_web_search_calls_response.rbi +14 -2
  70. data/rbi/openai/models/audio/voice_consent.rbi +86 -0
  71. data/rbi/openai/models/audio/voice_consent_create_params.rbi +92 -0
  72. data/rbi/openai/models/audio/voice_consent_delete_params.rbi +53 -0
  73. data/rbi/openai/models/audio/voice_consent_deleted.rbi +62 -0
  74. data/rbi/openai/models/audio/voice_consent_list_params.rbi +78 -0
  75. data/rbi/openai/models/audio/voice_consent_retrieve_params.rbi +53 -0
  76. data/rbi/openai/models/audio/voice_consent_update_params.rbi +62 -0
  77. data/rbi/openai/models/beta/beta_response_input_item.rbi +14 -1
  78. data/rbi/openai/models/response_format_json_schema.rbi +13 -11
  79. data/rbi/openai/models/responses/response_input_item.rbi +10 -1
  80. data/rbi/openai/resources/audio/voice_consents.rbi +108 -0
  81. data/rbi/openai/resources/audio.rbi +4 -0
  82. data/realtime.md +22 -3
  83. data/sig/openai/client.rbs +1 -1
  84. data/sig/openai/helpers/chat/tool_runner.rbs +48 -0
  85. data/sig/openai/helpers/realtime/translation.rbs +0 -2
  86. data/sig/openai/helpers/realtime/unknown_server_event.rbs +2 -0
  87. data/sig/openai/helpers/websocket.rbs +23 -6
  88. data/sig/openai/models/admin/organization/usage_audio_speeches_response.rbs +15 -5
  89. data/sig/openai/models/admin/organization/usage_audio_transcriptions_response.rbs +15 -5
  90. data/sig/openai/models/admin/organization/usage_code_interpreter_sessions_response.rbs +15 -5
  91. data/sig/openai/models/admin/organization/usage_completions_response.rbs +15 -5
  92. data/sig/openai/models/admin/organization/usage_costs_response.rbs +15 -5
  93. data/sig/openai/models/admin/organization/usage_decisions_response.rbs +11 -1
  94. data/sig/openai/models/admin/organization/usage_embeddings_response.rbs +15 -5
  95. data/sig/openai/models/admin/organization/usage_file_search_calls_response.rbs +15 -5
  96. data/sig/openai/models/admin/organization/usage_images_response.rbs +15 -5
  97. data/sig/openai/models/admin/organization/usage_moderations_response.rbs +15 -5
  98. data/sig/openai/models/admin/organization/usage_vector_stores_response.rbs +15 -5
  99. data/sig/openai/models/admin/organization/usage_web_search_calls_response.rbs +15 -5
  100. data/sig/openai/models/audio/voice_consent.rbs +57 -0
  101. data/sig/openai/models/audio/voice_consent_create_params.rbs +61 -0
  102. data/sig/openai/models/audio/voice_consent_delete_params.rbs +25 -0
  103. data/sig/openai/models/audio/voice_consent_deleted.rbs +31 -0
  104. data/sig/openai/models/audio/voice_consent_list_params.rbs +57 -0
  105. data/sig/openai/models/audio/voice_consent_retrieve_params.rbs +25 -0
  106. data/sig/openai/models/audio/voice_consent_update_params.rbs +36 -0
  107. data/sig/openai/models/beta/beta_response_input_item.rbs +8 -0
  108. data/sig/openai/models/responses/response_input_item.rbs +8 -3
  109. data/sig/openai/resources/audio/voice_consents.rbs +38 -0
  110. data/sig/openai/resources/audio.rbs +2 -0
  111. metadata +31 -1
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Audio
6
+ # @see OpenAI::Resources::Audio::VoiceConsents#list
7
+ class VoiceConsentListParams < OpenAI::Internal::Type::BaseModel
8
+ extend OpenAI::Internal::Type::RequestParameters::Converter
9
+ include OpenAI::Internal::Type::RequestParameters
10
+
11
+ # @!attribute after
12
+ # A cursor for use in pagination. `after` is an object ID that defines your place
13
+ # in the list. For instance, if you make a list request and receive 100 objects,
14
+ # ending with obj_foo, your subsequent call can include after=obj_foo in order to
15
+ # fetch the next page of the list.
16
+ #
17
+ # @return [String, nil]
18
+ optional :after, String
19
+
20
+ # @!attribute limit
21
+ # A limit on the number of objects to be returned. Limit can range between 1 and
22
+ # 100, and the default is 20.
23
+ #
24
+ # @return [Integer, nil]
25
+ optional :limit, Integer
26
+
27
+ # @!method initialize(after: nil, limit: nil, request_options: {})
28
+ # @param after [String]
29
+ # A cursor for use in pagination. `after` is an object ID that defines your place
30
+ # in the list. For instance, if you make a list request and receive 100 objects,
31
+ # ending with obj_foo, your subsequent call can include after=obj_foo in order to
32
+ # fetch the next page of the list.
33
+ #
34
+ # @param limit [Integer]
35
+ # A limit on the number of objects to be returned. Limit can range between 1 and
36
+ # 100, and the default is 20.
37
+ #
38
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Audio
6
+ # @see OpenAI::Resources::Audio::VoiceConsents#retrieve
7
+ class VoiceConsentRetrieveParams < OpenAI::Internal::Type::BaseModel
8
+ extend OpenAI::Internal::Type::RequestParameters::Converter
9
+ include OpenAI::Internal::Type::RequestParameters
10
+
11
+ # @!attribute consent_id
12
+ #
13
+ # @return [String]
14
+ required :consent_id, String
15
+
16
+ # @!method initialize(consent_id:, request_options: {})
17
+ # @param consent_id [String]
18
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Audio
6
+ # @see OpenAI::Resources::Audio::VoiceConsents#update
7
+ class VoiceConsentUpdateParams < OpenAI::Internal::Type::BaseModel
8
+ extend OpenAI::Internal::Type::RequestParameters::Converter
9
+ include OpenAI::Internal::Type::RequestParameters
10
+
11
+ # @!attribute consent_id
12
+ #
13
+ # @return [String]
14
+ required :consent_id, String
15
+
16
+ # @!attribute name
17
+ # The updated label for this consent recording.
18
+ #
19
+ # @return [String]
20
+ required :name, String
21
+
22
+ # @!method initialize(consent_id:, name:, request_options: {})
23
+ # @param consent_id [String]
24
+ #
25
+ # @param name [String]
26
+ # The updated label for this consent recording.
27
+ #
28
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3082,15 +3082,24 @@ module OpenAI
3082
3082
  # @return [Symbol, :compaction_trigger]
3083
3083
  required :type, const: :compaction_trigger
3084
3084
 
3085
+ # @!attribute id
3086
+ # The unique ID of this compaction trigger.
3087
+ #
3088
+ # @return [String, nil]
3089
+ optional :id, String, nil?: true
3090
+
3085
3091
  # @!attribute agent
3086
3092
  # The agent that produced this item.
3087
3093
  #
3088
3094
  # @return [OpenAI::Models::Beta::BetaResponseInputItem::CompactionTrigger::Agent, nil]
3089
3095
  optional :agent, -> { OpenAI::Beta::BetaResponseInputItem::CompactionTrigger::Agent }, nil?: true
3090
3096
 
3091
- # @!method initialize(agent: nil, type: :compaction_trigger)
3097
+ # @!method initialize(id: nil, agent: nil, type: :compaction_trigger)
3092
3098
  # Compacts the current context. Must be the final input item.
3093
3099
  #
3100
+ # @param id [String, nil]
3101
+ # The unique ID of this compaction trigger.
3102
+ #
3094
3103
  # @param agent [OpenAI::Models::Beta::BetaResponseInputItem::CompactionTrigger::Agent, nil]
3095
3104
  # The agent that produced this item.
3096
3105
  #
@@ -2177,9 +2177,18 @@ module OpenAI
2177
2177
  # @return [Symbol, :compaction_trigger]
2178
2178
  required :type, const: :compaction_trigger
2179
2179
 
2180
- # @!method initialize(type: :compaction_trigger)
2180
+ # @!attribute id
2181
+ # The unique ID of this compaction trigger.
2182
+ #
2183
+ # @return [String, nil]
2184
+ optional :id, String, nil?: true
2185
+
2186
+ # @!method initialize(id: nil, type: :compaction_trigger)
2181
2187
  # Compacts the current context. Must be the final input item.
2182
2188
  #
2189
+ # @param id [String, nil]
2190
+ # The unique ID of this compaction trigger.
2191
+ #
2183
2192
  # @param type [Symbol, :compaction_trigger]
2184
2193
  # The type of the item. Always `compaction_trigger`.
2185
2194
  end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenAI
4
+ module Resources
5
+ class Audio
6
+ # Turn audio into text or text into audio.
7
+ class VoiceConsents
8
+ # Upload a voice consent recording.
9
+ #
10
+ # `String`, `StringIO`, and pathless `IO` inputs are sent with generic upload
11
+ # metadata. Use `OpenAI::FilePart` when you need to override the filename or
12
+ # content type.
13
+ #
14
+ # @overload create(language:, name:, recording:, request_options: {})
15
+ #
16
+ # @param language [String]
17
+ # The BCP 47 language tag for the consent phrase (for example, `en-US`).
18
+ #
19
+ # @param name [String]
20
+ # The label to use for this consent recording.
21
+ #
22
+ # @param recording [Pathname, StringIO, IO, String, OpenAI::FilePart]
23
+ # The consent audio recording file. Maximum size is 10 MiB.
24
+ #
25
+ # Supported MIME types: `audio/mpeg`, `audio/wav`, `audio/x-wav`, `audio/ogg`,
26
+ # `audio/aac`, `audio/flac`, `audio/webm`, `audio/mp4`.
27
+ #
28
+ # `String`, `StringIO`, and pathless `IO` inputs are sent with generic upload
29
+ # metadata. Use `OpenAI::FilePart` when you need to override the filename or
30
+ # content type.
31
+ #
32
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
33
+ #
34
+ # @return [OpenAI::Models::Audio::VoiceConsent]
35
+ #
36
+ # @see OpenAI::Models::Audio::VoiceConsentCreateParams
37
+ def create(params)
38
+ parsed, options = OpenAI::Audio::VoiceConsentCreateParams.dump_request(params)
39
+ @client.request(
40
+ method: :post,
41
+ path: "audio/voice_consents",
42
+ headers: {"content-type" => "multipart/form-data"},
43
+ body: parsed,
44
+ model: OpenAI::Audio::VoiceConsent,
45
+ security: {bearer_auth: true},
46
+ options: options
47
+ )
48
+ end
49
+
50
+ # Retrieves a voice consent recording.
51
+ #
52
+ # @overload retrieve(consent_id, request_options: {})
53
+ #
54
+ # @param consent_id [String]
55
+ # The ID of the consent recording to retrieve.
56
+ #
57
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
58
+ #
59
+ # @return [OpenAI::Models::Audio::VoiceConsent]
60
+ #
61
+ # @see OpenAI::Models::Audio::VoiceConsentRetrieveParams
62
+ def retrieve(consent_id, params = {})
63
+ @client.request(
64
+ method: :get,
65
+ path: ["audio/voice_consents/%1$s", consent_id],
66
+ model: OpenAI::Audio::VoiceConsent,
67
+ security: {bearer_auth: true},
68
+ options: params[:request_options]
69
+ )
70
+ end
71
+
72
+ # Updates a voice consent recording (metadata only).
73
+ #
74
+ # @overload update(consent_id, name:, request_options: {})
75
+ #
76
+ # @param consent_id [String]
77
+ # The ID of the consent recording to update.
78
+ #
79
+ # @param name [String]
80
+ # The updated label for this consent recording.
81
+ #
82
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
83
+ #
84
+ # @return [OpenAI::Models::Audio::VoiceConsent]
85
+ #
86
+ # @see OpenAI::Models::Audio::VoiceConsentUpdateParams
87
+ def update(consent_id, params)
88
+ parsed, options = OpenAI::Audio::VoiceConsentUpdateParams.dump_request(params)
89
+ @client.request(
90
+ method: :post,
91
+ path: ["audio/voice_consents/%1$s", consent_id],
92
+ body: parsed,
93
+ model: OpenAI::Audio::VoiceConsent,
94
+ security: {bearer_auth: true},
95
+ options: options
96
+ )
97
+ end
98
+
99
+ # Returns a list of voice consent recordings.
100
+ #
101
+ # @overload list(after: nil, limit: nil, request_options: {})
102
+ #
103
+ # @param after [String]
104
+ # A cursor for use in pagination. `after` is an object ID that defines your place
105
+ # in the list. For instance, if you make a list request and receive 100 objects,
106
+ # ending with obj_foo, your subsequent call can include after=obj_foo in order to
107
+ # fetch the next page of the list.
108
+ #
109
+ # @param limit [Integer]
110
+ # A limit on the number of objects to be returned. Limit can range between 1 and
111
+ # 100, and the default is 20.
112
+ #
113
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
114
+ #
115
+ # @return [OpenAI::Internal::CursorPage<OpenAI::Models::Audio::VoiceConsent>]
116
+ #
117
+ # @see OpenAI::Models::Audio::VoiceConsentListParams
118
+ def list(params = {})
119
+ parsed, options = OpenAI::Audio::VoiceConsentListParams.dump_request(params)
120
+ query = OpenAI::Internal::Util.encode_query_params(parsed)
121
+ @client.request(
122
+ method: :get,
123
+ path: "audio/voice_consents",
124
+ query: query,
125
+ page: OpenAI::Internal::CursorPage,
126
+ model: OpenAI::Audio::VoiceConsent,
127
+ security: {bearer_auth: true},
128
+ options: options
129
+ )
130
+ end
131
+
132
+ # Deletes a voice consent recording.
133
+ #
134
+ # @overload delete(consent_id, request_options: {})
135
+ #
136
+ # @param consent_id [String]
137
+ # The ID of the consent recording to delete.
138
+ #
139
+ # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
140
+ #
141
+ # @return [OpenAI::Models::Audio::VoiceConsentDeleted]
142
+ #
143
+ # @see OpenAI::Models::Audio::VoiceConsentDeleteParams
144
+ def delete(consent_id, params = {})
145
+ @client.request(
146
+ method: :delete,
147
+ path: ["audio/voice_consents/%1$s", consent_id],
148
+ model: OpenAI::Audio::VoiceConsentDeleted,
149
+ security: {bearer_auth: true},
150
+ options: params[:request_options]
151
+ )
152
+ end
153
+
154
+ # @api private
155
+ #
156
+ # @param client [OpenAI::Client]
157
+ def initialize(client:)
158
+ @client = client
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -19,6 +19,10 @@ module OpenAI
19
19
  # @return [OpenAI::Resources::Audio::Voices]
20
20
  attr_reader :voices
21
21
 
22
+ # Turn audio into text or text into audio.
23
+ # @return [OpenAI::Resources::Audio::VoiceConsents]
24
+ attr_reader :voice_consents
25
+
22
26
  # @api private
23
27
  #
24
28
  # @param client [OpenAI::Client]
@@ -28,6 +32,7 @@ module OpenAI
28
32
  @translations = OpenAI::Resources::Audio::Translations.new(client: client)
29
33
  @speech = OpenAI::Resources::Audio::Speech.new(client: client)
30
34
  @voices = OpenAI::Resources::Audio::Voices.new(client: client)
35
+ @voice_consents = OpenAI::Resources::Audio::VoiceConsents.new(client: client)
31
36
  end
32
37
  end
33
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenAI
4
- VERSION = "0.106.0"
4
+ VERSION = "0.108.0"
5
5
  end
data/lib/openai.rb CHANGED
@@ -462,6 +462,13 @@ require_relative "openai/models/audio/translation_create_params"
462
462
  require_relative "openai/models/audio/translation_create_response"
463
463
  require_relative "openai/models/audio/translation_verbose"
464
464
  require_relative "openai/models/audio/voice"
465
+ require_relative "openai/models/audio/voice_consent"
466
+ require_relative "openai/models/audio/voice_consent_create_params"
467
+ require_relative "openai/models/audio/voice_consent_deleted"
468
+ require_relative "openai/models/audio/voice_consent_delete_params"
469
+ require_relative "openai/models/audio/voice_consent_list_params"
470
+ require_relative "openai/models/audio/voice_consent_retrieve_params"
471
+ require_relative "openai/models/audio/voice_consent_update_params"
465
472
  require_relative "openai/models/audio/voice_create_params"
466
473
  require_relative "openai/models/audio_model"
467
474
  require_relative "openai/models/audio_response_format"
@@ -1558,6 +1565,7 @@ require_relative "openai/resources/audio"
1558
1565
  require_relative "openai/resources/audio/speech"
1559
1566
  require_relative "openai/resources/audio/transcriptions"
1560
1567
  require_relative "openai/resources/audio/translations"
1568
+ require_relative "openai/resources/audio/voice_consents"
1561
1569
  require_relative "openai/resources/audio/voices"
1562
1570
  require_relative "openai/resources/batches"
1563
1571
  require_relative "openai/resources/beta"
@@ -1647,6 +1655,7 @@ require_relative "openai/resources/vector_stores/files"
1647
1655
  require_relative "openai/resources/videos"
1648
1656
  require_relative "openai/resources/webhooks"
1649
1657
  require_relative "openai/resources/webhooks/event_types"
1658
+ require_relative "openai/helpers/models/embedding"
1650
1659
  require_relative "openai/helpers/models/responses/response"
1651
1660
  require_relative "openai/helpers/files"
1652
1661
  require_relative "openai/helpers/vector_stores/file_batches"
@@ -127,14 +127,7 @@ module OpenAI
127
127
 
128
128
  # @api private
129
129
  sig do
130
- override
131
- .params(
132
- security: {
133
- bearer_auth?: T::Boolean,
134
- admin_api_key_auth?: T::Boolean
135
- }
136
- )
137
- .returns(T::Hash[String, String])
130
+ override.params(security: T::Hash[Symbol, T::Boolean]).returns(T::Hash[String, String])
138
131
  end
139
132
  private def auth_headers(security:)
140
133
  end
@@ -0,0 +1,74 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Helpers
5
+ module Chat
6
+ class ToolRunner
7
+ Handler = T.type_alias { T.proc.params(arguments: T::Hash[String, T.untyped]).returns(T.untyped) }
8
+
9
+ class Error < StandardError
10
+ end
11
+
12
+ class MaxRoundsError < Error
13
+ end
14
+
15
+ # @api private
16
+ sig do
17
+ params(
18
+ completions: OpenAI::Resources::Chat::Completions,
19
+ params: T::Hash[Symbol, T.untyped],
20
+ tool_handlers: T::Hash[String, Handler],
21
+ max_rounds: Integer
22
+ )
23
+ .void
24
+ end
25
+ def initialize(completions:, params:, tool_handlers:, max_rounds:)
26
+ end
27
+
28
+ # @api private
29
+ sig { returns(OpenAI::Chat::ChatCompletion) }
30
+ def run
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ module Resources
37
+ class Chat
38
+ class Completions
39
+ # @api private
40
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(OpenAI::Chat::ChatCompletion) }
41
+ def create_for_tool_runner(params)
42
+ end
43
+
44
+ sig do
45
+ params(
46
+ model: T.any(String, OpenAI::ChatModel::OrSymbol),
47
+ messages: T::Array[
48
+ T.any(
49
+ OpenAI::Chat::ChatCompletionDeveloperMessageParam::OrHash,
50
+ OpenAI::Chat::ChatCompletionSystemMessageParam::OrHash,
51
+ OpenAI::Chat::ChatCompletionUserMessageParam::OrHash,
52
+ OpenAI::Chat::ChatCompletionAssistantMessageParam::OrHash,
53
+ OpenAI::Chat::ChatCompletionToolMessageParam::OrHash,
54
+ OpenAI::Chat::ChatCompletionFunctionMessageParam::OrHash
55
+ )
56
+ ],
57
+ tools: T::Array[
58
+ T.any(
59
+ OpenAI::StructuredOutput::JsonSchemaConverter,
60
+ OpenAI::Chat::ChatCompletionFunctionTool::OrHash
61
+ )
62
+ ],
63
+ tool_handlers: T::Hash[String, OpenAI::Helpers::Chat::ToolRunner::Handler],
64
+ max_rounds: Integer,
65
+ params: T.untyped
66
+ )
67
+ .returns(OpenAI::Chat::ChatCompletion)
68
+ end
69
+ def run_tools(model:, messages:, tools:, tool_handlers:, max_rounds: 10, **params)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -36,11 +36,6 @@ module OpenAI
36
36
  module Models
37
37
  module Realtime
38
38
  class UnknownTranslationServerEvent < OpenAI::Realtime::UnknownServerEvent
39
- sig { returns(String) }
40
- def inspect
41
- end
42
-
43
- alias to_s inspect
44
39
  end
45
40
 
46
41
  class TranslationConnection
@@ -20,6 +20,12 @@ module OpenAI
20
20
  sig { returns(T::Hash[Symbol, T.untyped]) }
21
21
  def to_h
22
22
  end
23
+
24
+ sig { returns(String) }
25
+ def inspect
26
+ end
27
+
28
+ alias to_s inspect
23
29
  end
24
30
  end
25
31
  end
@@ -33,7 +33,42 @@ module OpenAI
33
33
  request_options: T.untyped,
34
34
  transport: T.untyped,
35
35
  transport_options: T::Hash[T.untyped, T.untyped],
36
- block: T.proc.params(connection: TypedConnection).returns(T.untyped)
36
+ block: T.proc.params(connection: TypedConnection[T.untyped, T.untyped]).returns(T.untyped)
37
+ )
38
+ .returns(T.untyped)
39
+ end
40
+ def connect(
41
+ *path_arguments,
42
+ query: {},
43
+ websocket_base_url: nil,
44
+ request_options: nil,
45
+ transport: nil,
46
+ transport_options: {},
47
+ &block
48
+ )
49
+ end
50
+ end
51
+
52
+ # @api private
53
+ module TypedResource
54
+ extend T::Generic
55
+ include Resource
56
+
57
+ WebSocketClientEvent = type_member
58
+ WebSocketServerEvent = type_member
59
+
60
+ sig do
61
+ params(
62
+ path_arguments: T.untyped,
63
+ query: T::Hash[T.untyped, T.untyped],
64
+ websocket_base_url: T.nilable(String),
65
+ request_options: T.untyped,
66
+ transport: T.untyped,
67
+ transport_options: T::Hash[T.untyped, T.untyped],
68
+ block: T
69
+ .proc
70
+ .params(connection: TypedConnection[WebSocketClientEvent, WebSocketServerEvent])
71
+ .returns(T.untyped)
37
72
  )
38
73
  .returns(T.untyped)
39
74
  end
@@ -51,23 +86,26 @@ module OpenAI
51
86
 
52
87
  # @api private
53
88
  class TypedConnection
89
+ extend T::Generic
54
90
  include Enumerable
55
- Elem = type_member { {fixed: T.untyped} }
91
+
92
+ ClientEvent = type_member(:in)
93
+ Elem = type_member(:out)
56
94
 
57
95
  sig { returns(URI::Generic) }
58
96
  attr_reader :url
59
97
 
60
- sig { returns(T.untyped) }
98
+ sig { returns(T.nilable(Elem)) }
61
99
  def receive
62
100
  end
63
101
 
64
- sig { params(event: T.untyped).void }
102
+ sig { params(event: T.any(ClientEvent, T::Hash[T.any(String, Symbol), T.untyped])).void }
65
103
  def send_event(event)
66
104
  end
67
105
 
68
106
  sig do
69
- params(block: T.nilable(T.proc.params(event: T.untyped).void)).returns(
70
- T.any(TypedConnection, T::Enumerator[T.untyped])
107
+ params(block: T.nilable(T.proc.params(event: Elem).void)).returns(
108
+ T.any(TypedConnection[ClientEvent, Elem], T::Enumerator[Elem])
71
109
  )
72
110
  end
73
111
  def each(&block)
@@ -53,9 +53,7 @@ module OpenAI
53
53
  ]
54
54
  ),
55
55
  model: T.nilable(OpenAI::Internal::Type::Converter::Input),
56
- security: T.nilable(
57
- {bearer_auth?: T::Boolean, admin_api_key_auth?: T::Boolean}
58
- ),
56
+ security: T.nilable(T::Hash[Symbol, T::Boolean]),
59
57
  options: T.nilable(OpenAI::RequestOptions::OrHash)
60
58
  }
61
59
  end
@@ -387,9 +385,7 @@ module OpenAI
387
385
  ]
388
386
  ),
389
387
  model: T.nilable(OpenAI::Internal::Type::Converter::Input),
390
- security: T.nilable(
391
- {bearer_auth?: T::Boolean, admin_api_key_auth?: T::Boolean}
392
- ),
388
+ security: T.nilable(T::Hash[Symbol, T::Boolean]),
393
389
  options: T.nilable(OpenAI::RequestOptions::OrHash)
394
390
  )
395
391
  .returns(T.anything)
@@ -228,7 +228,12 @@ module OpenAI
228
228
  attr_writer :input_cache_write_12h_tokens
229
229
 
230
230
  # The aggregated number of input tokens written to the cache with a 30-minute
231
- # retention period.
231
+ # retention period. May be absent or null for older responses.
232
+ sig { returns(T.nilable(Integer)) }
233
+ attr_accessor :input_cache_write_30m_tokens
234
+
235
+ # The aggregated number of input tokens written to the cache across 30-minute and
236
+ # 12-hour retention periods.
232
237
  sig { returns(T.nilable(Integer)) }
233
238
  attr_reader :input_cache_write_tokens
234
239
 
@@ -350,6 +355,8 @@ module OpenAI
350
355
 
351
356
  input_cache_write_12h_tokens: Integer,
352
357
 
358
+ input_cache_write_30m_tokens: T.nilable(Integer),
359
+
353
360
  input_cache_write_tokens: Integer,
354
361
 
355
362
  input_cached_audio_tokens: Integer,
@@ -421,7 +428,11 @@ module OpenAI
421
428
  input_cache_write_12h_tokens: nil,
422
429
 
423
430
  # The aggregated number of input tokens written to the cache with a 30-minute
424
- # retention period.
431
+ # retention period. May be absent or null for older responses.
432
+ input_cache_write_30m_tokens: nil,
433
+
434
+ # The aggregated number of input tokens written to the cache across 30-minute and
435
+ # 12-hour retention periods.
425
436
  input_cache_write_tokens: nil,
426
437
 
427
438
  # The aggregated number of cached audio input tokens used.
@@ -491,6 +502,7 @@ module OpenAI
491
502
  batch: T.nilable(T::Boolean),
492
503
  input_audio_tokens: Integer,
493
504
  input_cache_write_12h_tokens: Integer,
505
+ input_cache_write_30m_tokens: T.nilable(Integer),
494
506
  input_cache_write_tokens: Integer,
495
507
  input_cached_audio_tokens: Integer,
496
508
  input_cached_image_tokens: Integer,
@@ -230,7 +230,12 @@ module OpenAI
230
230
  attr_writer :input_cache_write_12h_tokens
231
231
 
232
232
  # The aggregated number of input tokens written to the cache with a 30-minute
233
- # retention period.
233
+ # retention period. May be absent or null for older responses.
234
+ sig { returns(T.nilable(Integer)) }
235
+ attr_accessor :input_cache_write_30m_tokens
236
+
237
+ # The aggregated number of input tokens written to the cache across 30-minute and
238
+ # 12-hour retention periods.
234
239
  sig { returns(T.nilable(Integer)) }
235
240
  attr_reader :input_cache_write_tokens
236
241
 
@@ -352,6 +357,8 @@ module OpenAI
352
357
 
353
358
  input_cache_write_12h_tokens: Integer,
354
359
 
360
+ input_cache_write_30m_tokens: T.nilable(Integer),
361
+
355
362
  input_cache_write_tokens: Integer,
356
363
 
357
364
  input_cached_audio_tokens: Integer,
@@ -423,7 +430,11 @@ module OpenAI
423
430
  input_cache_write_12h_tokens: nil,
424
431
 
425
432
  # The aggregated number of input tokens written to the cache with a 30-minute
426
- # retention period.
433
+ # retention period. May be absent or null for older responses.
434
+ input_cache_write_30m_tokens: nil,
435
+
436
+ # The aggregated number of input tokens written to the cache across 30-minute and
437
+ # 12-hour retention periods.
427
438
  input_cache_write_tokens: nil,
428
439
 
429
440
  # The aggregated number of cached audio input tokens used.
@@ -493,6 +504,7 @@ module OpenAI
493
504
  batch: T.nilable(T::Boolean),
494
505
  input_audio_tokens: Integer,
495
506
  input_cache_write_12h_tokens: Integer,
507
+ input_cache_write_30m_tokens: T.nilable(Integer),
496
508
  input_cache_write_tokens: Integer,
497
509
  input_cached_audio_tokens: Integer,
498
510
  input_cached_image_tokens: Integer,