-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63118c2
commit 3b9889b
Showing
8 changed files
with
176 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// AudioFileFormat.swift | ||
// OpenAIDemo | ||
// | ||
// Created by Gusakovsky, Sergey on 5.03.23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum AudioFileFormat: String { | ||
case mp3, mp4, mpeg, mpga, m4a, wav, webm | ||
|
||
public var mimeType: String { | ||
switch self { | ||
case .mp3, .mpeg, .mpga: | ||
return "audio/mpeg" | ||
case .mp4, .m4a: | ||
return "audio/mp4" | ||
case .wav: | ||
return "audio/x-wav" | ||
case .webm: | ||
return "audio/webm" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Sources/OpenAIService/Models/Audio/OpenAIAudioResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// OpenAIAudioResponse.swift | ||
// OpenAIDemo | ||
// | ||
// Created by Gusakovsky, Sergey on 5.03.23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct OpenAIAudioResponse: Codable { | ||
public let text: String | ||
} |
14 changes: 14 additions & 0 deletions
14
Sources/OpenAIService/Models/Audio/Transcriptions/OpenAIAudioModelType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// OpenAIAudioModelType.swift | ||
// OpenAIDemo | ||
// | ||
// Created by Gusakovsky, Sergey on 5.03.23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum OpenAIAudioModelType: String, Encodable { | ||
|
||
/// > Model Name: whisper | ||
case whisper = "whisper-1" | ||
} |
50 changes: 50 additions & 0 deletions
50
Sources/OpenAIService/Models/Audio/Transcriptions/OpenAIAudioTranscriptionBody.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// OpenAIAudioTranscriptionBody.swift | ||
// OpenAIDemo | ||
// | ||
// Created by Gusakovsky, Sergey on 5.03.23. | ||
// | ||
|
||
import Foundation | ||
|
||
/// https://platform.openai.com/docs/api-reference/audio/create | ||
public struct OpenAIAudioTranscriptionBody { | ||
public let file: FormData | ||
public let model: OpenAIAudioModelType | ||
public let prompt: String? | ||
public let temperature: Double | ||
public let language: String? | ||
|
||
public init( | ||
file: Data, | ||
fileFormat: AudioFileFormat, | ||
model: OpenAIAudioModelType = .whisper, | ||
prompt: String? = nil, | ||
temperature: Double = 0, | ||
language: String? = nil | ||
) { | ||
self.file = FormData(data: file, mimeType: fileFormat.mimeType, fileName: "aiduo.\(fileFormat.rawValue)") | ||
self.model = model | ||
self.prompt = prompt | ||
self.temperature = temperature | ||
self.language = language | ||
} | ||
|
||
public var body: [String: Any] { | ||
var result: [String: Any] = [ | ||
"file": self.file, | ||
"model": self.model.rawValue, | ||
"temperature": self.temperature | ||
] | ||
|
||
if let prompt = self.prompt { | ||
result["prompt"] = prompt | ||
} | ||
|
||
if let language = self.language { | ||
result["language"] = language | ||
} | ||
|
||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters