Skip to content
Closed
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
Expand Up @@ -24,8 +24,7 @@ extension Components.Schemas.ModelResponseProperties: CustomStringConvertible {
let parts: [String] = [
"metadata: \(metadata.map(String.init(describing:)) ?? "nil")",
"temperature: \(temperature.map(String.init(describing:)) ?? "nil")",
"topP: \(topP.map(String.init(describing:)) ?? "nil")",
"user: \(user.map { "\"\($0)\"" } ?? "nil")"
"topP: \(topP.map(String.init(describing:)) ?? "nil")"
]

return "ModelResponseProperties(\(parts.joined(separator: ", ")))"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

public protocol JSONSchemaConvertible: Codable {
public protocol JSONSchemaConvertible: Codable, Sendable {
static var example: Self { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct CreateModelResponseQuery: Codable, Equatable, Sendable {
/// - `computer_call_output.output.image_url`: Include image urls from the computer call output.
/// - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in reasoning item outputs. This enables reasoning items to be used in multi-turn conversations when using the Responses API statelessly (like when the `store` parameter is set to `false`, or when an organization is enrolled in the zero data retention program).
/// - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code interpreter tool call items.
public let include: [Schemas.Includable]?
public let include: [Schemas.IncludeEnum]?

/// Whether to run the model response in the background. [Learn more](https://platform.openai.com/docs/guides/background).
public let background: Bool?
Expand Down Expand Up @@ -105,7 +105,7 @@ public struct CreateModelResponseQuery: Codable, Equatable, Sendable {

/// How the model should select which tool (or tools) to use when generating a response.
/// See the `tools` parameter to see how to specify which tools the model can call.
public let toolChoice: ResponseProperties.ToolChoicePayload?
public let toolChoice: Schemas.ToolChoiceParam?

/// An array of tools the model may call while generating a response. You can specify which tool to use by setting the `toolChoice` parameter.
///
Expand Down Expand Up @@ -133,7 +133,7 @@ public struct CreateModelResponseQuery: Codable, Equatable, Sendable {
public init(
input: Input,
model: String,
include: [Schemas.Includable]? = nil,
include: [Schemas.IncludeEnum]? = nil,
background: Bool? = nil,
instructions: String? = nil,
maxOutputTokens: Int? = nil,
Expand All @@ -148,7 +148,7 @@ public struct CreateModelResponseQuery: Codable, Equatable, Sendable {
stream: Bool? = nil,
temperature: Double? = nil,
text: TextResponseConfigurationOptions? = nil,
toolChoice: ResponseProperties.ToolChoicePayload? = nil,
toolChoice: Schemas.ToolChoiceParam? = nil,
tools: [Tool]? = nil,
topP: Double? = nil,
truncation: String? = nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct GetModelResponseQuery: Codable, Equatable, Sendable {
/// * `file_search_call.results`: Include the search results of the file search tool call.
/// * `message.input_image.image_url`: Include image urls from the input message.
/// * `computer_call_output.output.image_url`: Include image urls from the computer call output.
public let include: [Components.Schemas.Includable]?
public let include: [Components.Schemas.IncludeEnum]?

private enum CodingKeys: String, CodingKey {
case responseId = "response_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct ResponseObject: Codable, Equatable, Sendable {
/// An array of content items generated by the model.
/// * The length and order of items in the `output` array is dependent on the model's response.
/// * Rather than accessing the first item in the `output` array and assuming it's an `assistant` message with the content generated by the model, you might consider using the `output_text` property where supported in SDKs.
public let output: [OutputItem]
public let output: [Schemas.OutputItem]

/// Whether to allow the model to run tool calls in parallel.
public let parallelToolCalls: Bool
Expand All @@ -70,10 +70,10 @@ public struct ResponseObject: Codable, Equatable, Sendable {
/// Configuration options for a text response from the model. Can be plain text or structured JSON data. Learn more:
/// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
/// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
public let text: ResponseProperties.TextPayload
public let text: Schemas.ResponseTextParam

/// How the model should select which tool (or tools) to use when generating a response. See the `tools` parameter to see how to specify which tools the model can call.
public let toolChoice: ResponseProperties.ToolChoicePayload
public let toolChoice: Schemas.ToolChoiceParam

/// An array of tools the model may call while generating a response. You can specify which tool to use by setting the `tool_choice` parameter.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct ResponseOutputItemAddedEvent: Codable, Hashable, Sendable {
/// The index of the output item that was added.
public let outputIndex: Int
/// The output item that was added.
public let item: OutputItem
public let item: Components.Schemas.OutputItem
/// Creates a new `ResponseOutputItemAddedEvent`.
///
/// - Parameters:
Expand All @@ -22,7 +22,7 @@ public struct ResponseOutputItemAddedEvent: Codable, Hashable, Sendable {
public init(
type: String = "response.output_item.added",
outputIndex: Int,
item: OutputItem
item: Components.Schemas.OutputItem
) {
self.type = type
self.outputIndex = outputIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct ResponseOutputItemDoneEvent: Codable, Hashable, Sendable {
/// The index of the output item that was marked done.
public let outputIndex: Int
/// The output item that was marked done.
public let item: OutputItem
public let item: Components.Schemas.OutputItem
/// Creates a new `ResponseOutputItemDoneEvent`.
///
/// - Parameters:
Expand All @@ -22,7 +22,7 @@ public struct ResponseOutputItemDoneEvent: Codable, Hashable, Sendable {
public init(
type: String = "response.output_item.done",
outputIndex: Int,
item: OutputItem
item: Components.Schemas.OutputItem
) {
self.type = type
self.outputIndex = outputIndex
Expand Down
87 changes: 78 additions & 9 deletions Sources/OpenAI/Public/Schemas/Edited/Tool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
@_spi(Generated) import OpenAPIRuntime

/// Reason for editing: Generated FunctionTool type is not user friendly.
/// When editing the list of tool - also check OutputItem type if the list of tool calls should be updated
@frozen public enum Tool: Codable, Hashable, Sendable {
public typealias Schemas = Components.Schemas

/// A tool that searches for relevant content from uploaded files.
/// Learn more about the [file search tool](/docs/guides/tools-file-search).
case fileSearchTool(Schemas.FileSearchTool)
Expand All @@ -20,20 +19,34 @@
case functionTool(FunctionTool)
/// A tool that controls a virtual computer. Learn more about the
/// [computer tool](/docs/guides/tools-computer-use).
case computerTool(Schemas.ComputerUsePreviewTool)
case computerTool(Schemas.ComputerTool)
/// A tool that controls a virtual computer (preview version).
case computerUsePreviewTool(Schemas.ComputerUsePreviewTool)
/// This tool searches the web for relevant results to use in a response.
/// Learn more about the [web search tool](/docs/guides/tools-web-search).
case webSearchTool(Schemas.WebSearchPreviewTool)
case webSearchTool(Schemas.WebSearchTool)
/// This tool searches the web for relevant results to use in a response (preview version).
case webSearchPreviewTool(Schemas.WebSearchPreviewTool)
/// Give the model access to additional tools via remote Model Context Protocol (MCP) servers.
/// [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp)
case mcpTool(Schemas.MCPTool)
/// A tool that runs Python code to help generate a response to a prompt.
case codeInterpreter(Schemas.CodeInterpreterTool)
case codeInterpreterTool(Schemas.CodeInterpreterTool)
/// A tool that generates images using a model like `gpt-image-1`.
case imageGenerationTool(Schemas.ImageGenTool)
/// A tool that allows the model to execute shell commands in a local environment.
case localShellTool(Schemas.LocalShellTool)

case localShellTool(Schemas.LocalShellToolParam)
/// A tool that allows the model to execute shell commands via a function.
case functionShellTool(Schemas.FunctionShellToolParam)
/// A custom tool defined by the user.
case customTool(Schemas.CustomToolParam)
/// A namespace-scoped tool.
case namespaceTool(Schemas.NamespaceToolParam)
/// A tool that performs tool searches.
case toolSearchTool(Schemas.ToolSearchToolParam)
/// A tool that applies patches.
case applyPatchTool(Schemas.ApplyPatchToolParam)

public init(from decoder: any Decoder) throws {
var errors: [any Error] = []
do {
Expand All @@ -54,20 +67,32 @@
} catch {
errors.append(error)
}
do {
self = .computerUsePreviewTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .webSearchTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .webSearchPreviewTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .mcpTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .codeInterpreter(try .init(from: decoder))
self = .codeInterpreterTool(try .init(from: decoder))
return
} catch {
errors.append(error)
Expand All @@ -84,6 +109,36 @@
} catch {
errors.append(error)
}
do {
self = .functionShellTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .customTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .namespaceTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .toolSearchTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
do {
self = .applyPatchTool(try .init(from: decoder))
return
} catch {
errors.append(error)
}
throw Swift.DecodingError.failedToDecodeOneOfSchema(
type: Self.self,
codingPath: decoder.codingPath,
Expand All @@ -98,16 +153,30 @@
try value.encode(to: encoder)
case let .computerTool(value):
try value.encode(to: encoder)
case let .computerUsePreviewTool(value):
try value.encode(to: encoder)
case let .webSearchTool(value):
try value.encode(to: encoder)
case let .webSearchPreviewTool(value):
try value.encode(to: encoder)
case let .mcpTool(value):
try value.encode(to: encoder)
case let .codeInterpreter(value):
case let .codeInterpreterTool(value):
try value.encode(to: encoder)
case let .imageGenerationTool(value):
try value.encode(to: encoder)
case let .localShellTool(value):
try value.encode(to: encoder)
case let .functionShellTool(value):
try value.encode(to: encoder)
case let .customTool(value):
try value.encode(to: encoder)
case let .namespaceTool(value):
try value.encode(to: encoder)
case let .toolSearchTool(value):
try value.encode(to: encoder)
case let .applyPatchTool(value):
try value.encode(to: encoder)
}
}
}
79 changes: 0 additions & 79 deletions Sources/OpenAI/Public/Schemas/Facade/OutputItem.swift

This file was deleted.

Loading
Loading