|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module OpenAI |
| 4 | + module Resources |
| 5 | + class Realtime |
| 6 | + class Calls |
| 7 | + # Some parameter documentations has been truncated, see |
| 8 | + # {OpenAI::Models::Realtime::CallAcceptParams} for more details. |
| 9 | + # |
| 10 | + # Accept an incoming SIP call and configure the realtime session that will handle |
| 11 | + # it. |
| 12 | + # |
| 13 | + # @overload accept(call_id, audio: nil, include: nil, instructions: nil, max_output_tokens: nil, model: nil, output_modalities: nil, prompt: nil, tool_choice: nil, tools: nil, tracing: nil, truncation: nil, type: :realtime, request_options: {}) |
| 14 | + # |
| 15 | + # @param call_id [String] The identifier for the call provided in the |
| 16 | + # |
| 17 | + # @param audio [OpenAI::Models::Realtime::RealtimeAudioConfig] Configuration for input and output audio. |
| 18 | + # |
| 19 | + # @param include [Array<Symbol, OpenAI::Models::Realtime::RealtimeSessionCreateRequest::Include>] Additional fields to include in server outputs. |
| 20 | + # |
| 21 | + # @param instructions [String] The default system instructions (i.e. system message) prepended to model calls. |
| 22 | + # |
| 23 | + # @param max_output_tokens [Integer, Symbol, :inf] Maximum number of output tokens for a single assistant response, |
| 24 | + # |
| 25 | + # @param model [String, Symbol, OpenAI::Models::Realtime::RealtimeSessionCreateRequest::Model] The Realtime model used for this session. |
| 26 | + # |
| 27 | + # @param output_modalities [Array<Symbol, OpenAI::Models::Realtime::RealtimeSessionCreateRequest::OutputModality>] The set of modalities the model can respond with. It defaults to `["audio"]`, in |
| 28 | + # |
| 29 | + # @param prompt [OpenAI::Models::Responses::ResponsePrompt, nil] Reference to a prompt template and its variables. |
| 30 | + # |
| 31 | + # @param tool_choice [Symbol, OpenAI::Models::Responses::ToolChoiceOptions, OpenAI::Models::Responses::ToolChoiceFunction, OpenAI::Models::Responses::ToolChoiceMcp] How the model chooses tools. Provide one of the string modes or force a specific |
| 32 | + # |
| 33 | + # @param tools [Array<OpenAI::Models::Realtime::RealtimeFunctionTool, OpenAI::Models::Realtime::RealtimeToolsConfigUnion::Mcp>] Tools available to the model. |
| 34 | + # |
| 35 | + # @param tracing [Symbol, :auto, OpenAI::Models::Realtime::RealtimeTracingConfig::TracingConfiguration, nil] Realtime API can write session traces to the [Traces Dashboard](/logs?api=traces |
| 36 | + # |
| 37 | + # @param truncation [Symbol, OpenAI::Models::Realtime::RealtimeTruncation::RealtimeTruncationStrategy, OpenAI::Models::Realtime::RealtimeTruncationRetentionRatio] Controls how the realtime conversation is truncated prior to model inference. |
| 38 | + # |
| 39 | + # @param type [Symbol, :realtime] The type of session to create. Always `realtime` for the Realtime API. |
| 40 | + # |
| 41 | + # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil] |
| 42 | + # |
| 43 | + # @return [nil] |
| 44 | + # |
| 45 | + # @see OpenAI::Models::Realtime::CallAcceptParams |
| 46 | + def accept(call_id, params) |
| 47 | + parsed, options = OpenAI::Realtime::CallAcceptParams.dump_request(params) |
| 48 | + @client.request( |
| 49 | + method: :post, |
| 50 | + path: ["realtime/calls/%1$s/accept", call_id], |
| 51 | + body: parsed, |
| 52 | + model: NilClass, |
| 53 | + options: options |
| 54 | + ) |
| 55 | + end |
| 56 | + |
| 57 | + # Some parameter documentations has been truncated, see |
| 58 | + # {OpenAI::Models::Realtime::CallHangupParams} for more details. |
| 59 | + # |
| 60 | + # End an active Realtime API call, whether it was initiated over SIP or WebRTC. |
| 61 | + # |
| 62 | + # @overload hangup(call_id, request_options: {}) |
| 63 | + # |
| 64 | + # @param call_id [String] The identifier for the call. For SIP calls, use the value provided in the |
| 65 | + # |
| 66 | + # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil] |
| 67 | + # |
| 68 | + # @return [nil] |
| 69 | + # |
| 70 | + # @see OpenAI::Models::Realtime::CallHangupParams |
| 71 | + def hangup(call_id, params = {}) |
| 72 | + @client.request( |
| 73 | + method: :post, |
| 74 | + path: ["realtime/calls/%1$s/hangup", call_id], |
| 75 | + model: NilClass, |
| 76 | + options: params[:request_options] |
| 77 | + ) |
| 78 | + end |
| 79 | + |
| 80 | + # Some parameter documentations has been truncated, see |
| 81 | + # {OpenAI::Models::Realtime::CallReferParams} for more details. |
| 82 | + # |
| 83 | + # Transfer an active SIP call to a new destination using the SIP REFER verb. |
| 84 | + # |
| 85 | + # @overload refer(call_id, target_uri:, request_options: {}) |
| 86 | + # |
| 87 | + # @param call_id [String] The identifier for the call provided in the |
| 88 | + # |
| 89 | + # @param target_uri [String] URI that should appear in the SIP Refer-To header. Supports values like |
| 90 | + # |
| 91 | + # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil] |
| 92 | + # |
| 93 | + # @return [nil] |
| 94 | + # |
| 95 | + # @see OpenAI::Models::Realtime::CallReferParams |
| 96 | + def refer(call_id, params) |
| 97 | + parsed, options = OpenAI::Realtime::CallReferParams.dump_request(params) |
| 98 | + @client.request( |
| 99 | + method: :post, |
| 100 | + path: ["realtime/calls/%1$s/refer", call_id], |
| 101 | + body: parsed, |
| 102 | + model: NilClass, |
| 103 | + options: options |
| 104 | + ) |
| 105 | + end |
| 106 | + |
| 107 | + # Some parameter documentations has been truncated, see |
| 108 | + # {OpenAI::Models::Realtime::CallRejectParams} for more details. |
| 109 | + # |
| 110 | + # Decline an incoming SIP call by returning a SIP status code to the caller. |
| 111 | + # |
| 112 | + # @overload reject(call_id, status_code: nil, request_options: {}) |
| 113 | + # |
| 114 | + # @param call_id [String] The identifier for the call provided in the |
| 115 | + # |
| 116 | + # @param status_code [Integer] SIP response code to send back to the caller. Defaults to `603` (Decline) |
| 117 | + # |
| 118 | + # @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil] |
| 119 | + # |
| 120 | + # @return [nil] |
| 121 | + # |
| 122 | + # @see OpenAI::Models::Realtime::CallRejectParams |
| 123 | + def reject(call_id, params = {}) |
| 124 | + parsed, options = OpenAI::Realtime::CallRejectParams.dump_request(params) |
| 125 | + @client.request( |
| 126 | + method: :post, |
| 127 | + path: ["realtime/calls/%1$s/reject", call_id], |
| 128 | + body: parsed, |
| 129 | + model: NilClass, |
| 130 | + options: options |
| 131 | + ) |
| 132 | + end |
| 133 | + |
| 134 | + # @api private |
| 135 | + # |
| 136 | + # @param client [OpenAI::Client] |
| 137 | + def initialize(client:) |
| 138 | + @client = client |
| 139 | + end |
| 140 | + end |
| 141 | + end |
| 142 | + end |
| 143 | +end |
0 commit comments