Skip to content

Commit d535cfb

Browse files
authored
Merge pull request #384 from zats/minimal-effort
2 parents 80045fc + b963a59 commit d535cfb

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

Sources/OpenAI/Public/Models/ChatQuery.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct ChatQuery: Equatable, Codable, Streamable, Sendable {
1515
public let messages: [Self.ChatCompletionMessageParam]
1616
/// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the [model guide](https://platform.openai.com/docs/models) to browse and compare available models.
1717
public let model: Model
18-
/// Constrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently supported values are low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
18+
/// Constrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently supported values are minimal, low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
1919
///
2020
/// - Note: o-series models only
2121
public let reasoningEffort: ReasoningEffort?
@@ -922,6 +922,7 @@ public struct ChatQuery: Equatable, Codable, Streamable, Sendable {
922922
}
923923

924924
public enum ReasoningEffort: Codable, Equatable, Sendable {
925+
case minimal
925926
case low
926927
case medium
927928
case high
@@ -934,6 +935,8 @@ public struct ChatQuery: Equatable, Codable, Streamable, Sendable {
934935
public func encode(to encoder: any Encoder) throws {
935936
var container = encoder.singleValueContainer()
936937
switch self {
938+
case .minimal:
939+
try container.encode("minimal")
937940
case .low:
938941
try container.encode("low")
939942
case .medium:
@@ -949,6 +952,8 @@ public struct ChatQuery: Equatable, Codable, Streamable, Sendable {
949952
let container = try decoder.singleValueContainer()
950953
let rawValue = try container.decode(String.self)
951954
switch rawValue {
955+
case "minimal":
956+
self = .minimal
952957
case "low":
953958
self = .low
954959
case "medium":

Sources/OpenAI/Public/Schemas/Generated/Components.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4861,13 +4861,14 @@ public enum Components {
48614861
///
48624862
/// Constrains effort on reasoning for
48634863
/// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
4864-
/// Currently supported values are `low`, `medium`, and `high`. Reducing
4864+
/// Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing
48654865
/// reasoning effort can result in faster responses and fewer tokens used
48664866
/// on reasoning in a response.
48674867
///
48684868
///
48694869
/// - Remark: Generated from `#/components/schemas/ReasoningEffort`.
48704870
@frozen public enum ReasoningEffort: String, Codable, Hashable, Sendable, CaseIterable {
4871+
case minimal = "minimal"
48714872
case low = "low"
48724873
case medium = "medium"
48734874
case high = "high"

Tests/OpenAITests/OpenAITestsDecoder.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,43 @@ class OpenAITestsDecoder: XCTestCase {
347347
XCTAssertEqual(chatQueryAsDict, expectedValueAsDict)
348348
}
349349

350+
func testChatQueryWithReasoningEffortMinimal() throws {
351+
let chatQuery = ChatQuery(
352+
messages: [
353+
.init(role: .user, content: "Who are you?")!
354+
],
355+
model: .gpt4,
356+
reasoningEffort: .minimal
357+
)
358+
let expectedValue = """
359+
{
360+
"model": "gpt-4",
361+
"messages": [
362+
{
363+
"role": "user",
364+
"content": "Who are you?"
365+
}
366+
],
367+
"reasoning_effort": "minimal",
368+
"stream": false
369+
}
370+
"""
371+
372+
let chatQueryAsDict = try jsonDataAsNSDictionary(JSONEncoder().encode(chatQuery))
373+
let expectedValueAsDict = try jsonDataAsNSDictionary(expectedValue.data(using: .utf8)!)
374+
375+
XCTAssertEqual(chatQueryAsDict, expectedValueAsDict)
376+
}
377+
378+
func testReasoningEffortDecodingMinimal() throws {
379+
let json = """
380+
{ "effort": "minimal" }
381+
"""
382+
let data = json.data(using: .utf8)!
383+
let decoded = try JSONDecoder().decode(Components.Schemas.Reasoning.self, from: data)
384+
XCTAssertEqual(decoded.effort, .minimal)
385+
}
386+
350387
func testEmbeddings() async throws {
351388
let data = """
352389
{

0 commit comments

Comments
 (0)