diff --git a/Sources/OpenAI/Public/Models/Annotation.swift b/Sources/OpenAI/Public/Models/Annotation.swift new file mode 100644 index 00000000..7191a3d7 --- /dev/null +++ b/Sources/OpenAI/Public/Models/Annotation.swift @@ -0,0 +1,29 @@ +import Foundation + +public struct Annotation: Codable, Equatable, Sendable { + /// The type of the URL citation. Always `url_citation`. + public let type: String + /// A URL citation when using web search. + public let urlCitation: URLCitation + + public enum CodingKeys: String, CodingKey { + case type, urlCitation = "url_citation" + } + + public struct URLCitation: Codable, Equatable, Sendable { + /// The index of the last character of the URL citation in the message. + public let endIndex: Int + /// The index of the first character of the URL citation in the message. + public let startIndex: Int + /// The title of the web resource. + public let title: String + /// The URL of the web resource. + public let url: String + + public enum CodingKeys: String, CodingKey { + case endIndex = "end_index" + case startIndex = "start_index" + case title, url + } + } +} diff --git a/Sources/OpenAI/Public/Models/ChatResult.swift b/Sources/OpenAI/Public/Models/ChatResult.swift index 52b5773f..c6ed4eed 100644 --- a/Sources/OpenAI/Public/Models/ChatResult.swift +++ b/Sources/OpenAI/Public/Models/ChatResult.swift @@ -156,34 +156,6 @@ public struct ChatResult: Codable, Equatable, Sendable { case _reasoningContent = "reasoning_content" } - public struct Annotation: Codable, Equatable, Sendable { - /// The type of the URL citation. Always `url_citation`. - let type: String - /// A URL citation when using web search. - let urlCitation: URLCitation - - public enum CodingKeys: String, CodingKey { - case type, urlCitation = "url_citation" - } - - public struct URLCitation: Codable, Equatable, Sendable { - /// The index of the last character of the URL citation in the message. - let endIndex: Int - /// The index of the first character of the URL citation in the message. - let startIndex: Int - /// The title of the web resource. - let title: String - /// The URL of the web resource. - let url: String - - public enum CodingKeys: String, CodingKey { - case endIndex = "end_index" - case startIndex = "start_index" - case title, url - } - } - } - public struct Audio: Codable, Equatable, Sendable { /// Base64 encoded audio bytes generated by the model, in the format specified in the request. public let data: String diff --git a/Sources/OpenAI/Public/Models/ChatStreamResult.swift b/Sources/OpenAI/Public/Models/ChatStreamResult.swift index c1f30216..9e6cd54d 100644 --- a/Sources/OpenAI/Public/Models/ChatStreamResult.swift +++ b/Sources/OpenAI/Public/Models/ChatStreamResult.swift @@ -25,6 +25,9 @@ public struct ChatStreamResult: Codable, Equatable, Sendable { /// The role of the author of this message. public let role: Self.Role? public let toolCalls: [Self.ChoiceDeltaToolCall]? + /// Annotations for the message, when applicable, as when using the web search tool. + /// Web search tool: https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat + public let annotations: [Annotation]? /// Value for `reasoning` field in response. /// @@ -111,6 +114,7 @@ public struct ChatStreamResult: Codable, Equatable, Sendable { case content case audio case role + case annotations case toolCalls = "tool_calls" case _reasoning = "reasoning" case _reasoningContent = "reasoning_content"