Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Transcriptions Tests #32

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import XCTest
@testable import SwiftOpenAI

final class CreateTranscriptionEndpointSpec: XCTestCase {
func testEndpointCreateSpeech_WithModelTTS() throws {
let model: OpenAITranscriptionModelType = .whisper
let language = "en"
let responseFormat: OpenAIAudioResponseType = .mp3
let temperature = 1.0

let sut = OpenAIEndpoints.createTranscription(
file: Data(),
model: model,
language: language,
prompt: "",
responseFormat: responseFormat,
temperature: temperature
).endpoint

let modelParameter = sut.parameters!["model"] as! String
let languageParameter = sut.parameters!["language"] as! String
let responseFormatParameter = sut.parameters!["response_format"] as! String
let temperatureFormatParameter = sut.parameters!["temperature"] as! Double

XCTAssertEqual(sut.path, "audio/transcriptions")
XCTAssertEqual(sut.method, .POST)
XCTAssertEqual(sut.parameters?.count, 5)
XCTAssertEqual(modelParameter, model.rawValue)
XCTAssertEqual(languageParameter, language)
XCTAssertEqual(responseFormatParameter, responseFormat.rawValue)
XCTAssertEqual(temperatureFormatParameter, temperature)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import XCTest
@testable import SwiftOpenAI

final class CreateTranscriptionRequestSpec: XCTestCase {
private let api = API()

func testRequest_CreatedWithCorrectHeaders() throws {
let apiKey = "1234567890"
let model: OpenAITranscriptionModelType = .whisper
let language = "en"
let responseFormat: OpenAIAudioResponseType = .mp3
let temperature = 1.0

var endpoint = OpenAIEndpoints.createTranscription(
file: Data(),
model: model,
language: language,
prompt: "",
responseFormat: responseFormat,
temperature: temperature
).endpoint

api.routeEndpoint(&endpoint, environment: OpenAIEnvironmentV1())

var sut = api.buildURLRequest(endpoint: endpoint)
api.addHeaders(urlRequest: &sut,
headers: ["Content-Type" : "application/json",
"Authorization" : "Bearer \(apiKey)"])

XCTAssertEqual(sut.allHTTPHeaderFields?.count, 2)
XCTAssertEqual(sut.allHTTPHeaderFields?["Content-Type"], "application/json")
XCTAssertEqual(sut.allHTTPHeaderFields?["Authorization"], "Bearer 1234567890")
}
}