Skip to content

Commit 4895981

Browse files
Audio mulit turn
1 parent f986986 commit 4895981

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Sources/OpenAI/Public/Parameters/Chat/ChatCompletionParameters.swift

+22-2
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,16 @@ public struct ChatCompletionParameters: Encodable {
9090

9191
public struct Message: Encodable {
9292

93-
/// The role of the messages author. One of system, user, assistant, or tool message.
94-
public let role: String
9593
/// The contents of the message. content is required for all messages, and may be null for assistant messages with function calls.
9694
public let content: ContentType
95+
/// The refusal message by the assistant.
96+
public let refusal: String?
97+
/// The role of the messages author. One of system, user, assistant, or tool message.
98+
public let role: String
9799
/// The name of the author of this message. name is required if role is function, and it should be the name of the function whose response is in the content. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
98100
public let name: String?
101+
/// Data about a previous audio response from the model. [Learn more.](https://platform.openai.com/docs/guides/audio)
102+
public let audio: Audio?
99103
/// The name and arguments of a function that should be called, as generated by the model.
100104
@available(*, deprecated, message: "Deprecated and replaced by `tool_calls`")
101105
let functionCall: FunctionCall?
@@ -222,10 +226,22 @@ public struct ChatCompletionParameters: Encodable {
222226
case tool // content, role, tool_call_id
223227
}
224228

229+
public struct Audio: Encodable {
230+
231+
/// Unique identifier for a previous audio response from the model.
232+
public let id: String
233+
234+
public init(id: String) {
235+
self.id = id
236+
}
237+
}
238+
225239
enum CodingKeys: String, CodingKey {
226240
case role
227241
case content
242+
case refusal
228243
case name
244+
case audio
229245
case functionCall = "function_call"
230246
case toolCalls = "tool_calls"
231247
case toolCallID = "tool_call_id"
@@ -234,14 +250,18 @@ public struct ChatCompletionParameters: Encodable {
234250
public init(
235251
role: Role,
236252
content: ContentType,
253+
refusal: String? = nil,
237254
name: String? = nil,
255+
audio: Audio? = nil,
238256
functionCall: FunctionCall? = nil,
239257
toolCalls: [ToolCall]? = nil,
240258
toolCallID: String? = nil)
241259
{
242260
self.role = role.rawValue
243261
self.content = content
262+
self.refusal = refusal
244263
self.name = name
264+
self.audio = audio
245265
self.functionCall = functionCall
246266
self.toolCalls = toolCalls
247267
self.toolCallID = toolCallID

Sources/OpenAI/Public/ResponseModels/Chat/ChatCompletionObject.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public struct ChatCompletionObject: Decodable {
6666
/// Unique identifier for this audio response.
6767
public let id: String
6868
/// The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
69-
public let expiresAt: Int
69+
public let expiresAt: Int?
7070
/// Base64 encoded audio bytes generated by the model, in the format specified in the request.
71-
public let data: String
71+
public let data: String?
7272
/// Transcript of the audio generated by the model.
73-
public let transcript: String
73+
public let transcript: String?
7474

7575
enum CodingKeys: String, CodingKey {
7676
case id

0 commit comments

Comments
 (0)