Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrochabrun committed Oct 28, 2024
1 parent 35d4e64 commit f986986
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Tests/OpenAITests/OpenAITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ final class OpenAITests: XCTestCase {
// https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-response_format
func testResponseFormatIsDecodableFromStringOrObject() throws {
let expectedResponseMappings: [(String, ResponseFormat)] = [
("\"auto\"", .auto),
("{\"type\": \"json_object\"}", .type("json_object")),
("{\"type\": \"text\"}", .type("text"))
("{\"type\": \"json_object\"}", .jsonObject),
("{\"type\": \"text\"}", .text)
]
let decoder = JSONDecoder()
for (response, expectedResponseFormat) in expectedResponseMappings {
Expand All @@ -52,20 +51,20 @@ final class OpenAITests: XCTestCase {
// encode to {"type": "text"} to satisfy when response_format can only be an object, such as:
// https://platform.openai.com/docs/api-reference/chat/create#chat-create-response_format
func testAutoResponseFormatEncodesToText() throws {
let jsonData = try JSONEncoder().encode(ResponseFormat.auto)
let jsonData = try JSONEncoder().encode(ResponseFormat.text)
XCTAssertEqual(String(data: jsonData, encoding: .utf8), "{\"type\":\"text\"}")
}

// Verifies that our custom encoding of ResponseFormat supports the 'text' type:
func testTextResponseFormatIsEncodable() throws {
let jsonData = try JSONEncoder().encode(ResponseFormat.type("text"))
let jsonData = try JSONEncoder().encode(ResponseFormat.text)
XCTAssertEqual(String(data: jsonData, encoding: .utf8), "{\"type\":\"text\"}")

}

// Verifies that our custom encoding of ResponseFormat supports the 'json_object' type:
func testJSONResponseFormatIsEncodable() throws {
let jsonData = try JSONEncoder().encode(ResponseFormat.type("json_object"))
let jsonData = try JSONEncoder().encode(ResponseFormat.jsonObject)
XCTAssertEqual(String(data: jsonData, encoding: .utf8), "{\"type\":\"json_object\"}")
}

Expand Down

0 comments on commit f986986

Please sign in to comment.