Skip to content

Commit a7f1e28

Browse files
Add support for custom model names in audio transcription and translation APIs
1 parent 78ac617 commit a7f1e28

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ public struct AudioTranscriptionParameters: Encodable {
194194
/// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. Defaults to 0
195195
let temperature: Double?
196196

197-
public enum Model: String {
198-
case whisperOne = "whisper-1"
197+
public enum Model {
198+
case whisperOne
199+
case custom(model: String)
199200
}
200201

201202
public init(
@@ -252,8 +253,9 @@ public struct AudioTranslationParameters: Encodable {
252253
/// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. Defaults to 0
253254
let temperature: Double?
254255

255-
public enum Model: String {
256-
case whisperOne = "whisper-1"
256+
public enum Model {
257+
case whisperOne
258+
case custom(model: String)
257259
}
258260

259261
public init(

Sources/OpenAI/Public/Parameters/Audio/AudioTranscriptionParameters.swift

+12-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ public struct AudioTranscriptionParameters: Encodable {
2828
/// The timestamp granularities to populate for this transcription. response_format must be set verbose_json to use timestamp granularities. Either or both of these options are supported: word, or segment. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency.
2929
let timestampGranularities: [String]?
3030

31-
public enum Model: String {
32-
case whisperOne = "whisper-1"
31+
public enum Model {
32+
case whisperOne
33+
case custom(model: String)
34+
var value: String {
35+
switch self {
36+
case .whisperOne:
37+
"whisper-1"
38+
case .custom(let model):
39+
model
40+
}
41+
}
3342
}
3443

3544
enum CodingKeys: String, CodingKey {
@@ -54,7 +63,7 @@ public struct AudioTranscriptionParameters: Encodable {
5463
{
5564
self.fileName = fileName
5665
self.file = file
57-
self.model = model.rawValue
66+
self.model = model.value
5867
self.prompt = prompt
5968
self.responseFormat = responseFormat
6069
self.temperature = temperature

Sources/OpenAI/Public/Parameters/Audio/AudioTranslationParameters.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ public struct AudioTranslationParameters: Encodable {
2323
/// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. Defaults to 0
2424
let temperature: Double?
2525

26-
public enum Model: String {
27-
case whisperOne = "whisper-1"
26+
public enum Model {
27+
case whisperOne
28+
case custom(model: String)
29+
30+
var value: String {
31+
switch self {
32+
case .whisperOne:
33+
"whisper-1"
34+
case .custom(let model):
35+
model
36+
}
37+
}
2838
}
2939

3040
enum CodingKeys: String, CodingKey {
@@ -45,7 +55,7 @@ public struct AudioTranslationParameters: Encodable {
4555
{
4656
self.fileName = fileName
4757
self.file = file
48-
self.model = model.rawValue
58+
self.model = model.value
4959
self.prompt = prompt
5060
self.responseFormat = responseFormat
5161
self.temperature = temperature

0 commit comments

Comments
 (0)