Skip to content

Commit 35ff1a5

Browse files
authored
Merge pull request #399 from batanus/add-annotations-to-chat-stream-result
Add annotations to chat stream result
2 parents 9485472 + bbc4792 commit 35ff1a5

3 files changed

Lines changed: 33 additions & 28 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
public struct Annotation: Codable, Equatable, Sendable {
4+
/// The type of the URL citation. Always `url_citation`.
5+
public let type: String
6+
/// A URL citation when using web search.
7+
public let urlCitation: URLCitation
8+
9+
public enum CodingKeys: String, CodingKey {
10+
case type, urlCitation = "url_citation"
11+
}
12+
13+
public struct URLCitation: Codable, Equatable, Sendable {
14+
/// The index of the last character of the URL citation in the message.
15+
public let endIndex: Int
16+
/// The index of the first character of the URL citation in the message.
17+
public let startIndex: Int
18+
/// The title of the web resource.
19+
public let title: String
20+
/// The URL of the web resource.
21+
public let url: String
22+
23+
public enum CodingKeys: String, CodingKey {
24+
case endIndex = "end_index"
25+
case startIndex = "start_index"
26+
case title, url
27+
}
28+
}
29+
}

Sources/OpenAI/Public/Models/ChatResult.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -156,34 +156,6 @@ public struct ChatResult: Codable, Equatable, Sendable {
156156
case _reasoningContent = "reasoning_content"
157157
}
158158

159-
public struct Annotation: Codable, Equatable, Sendable {
160-
/// The type of the URL citation. Always `url_citation`.
161-
let type: String
162-
/// A URL citation when using web search.
163-
let urlCitation: URLCitation
164-
165-
public enum CodingKeys: String, CodingKey {
166-
case type, urlCitation = "url_citation"
167-
}
168-
169-
public struct URLCitation: Codable, Equatable, Sendable {
170-
/// The index of the last character of the URL citation in the message.
171-
let endIndex: Int
172-
/// The index of the first character of the URL citation in the message.
173-
let startIndex: Int
174-
/// The title of the web resource.
175-
let title: String
176-
/// The URL of the web resource.
177-
let url: String
178-
179-
public enum CodingKeys: String, CodingKey {
180-
case endIndex = "end_index"
181-
case startIndex = "start_index"
182-
case title, url
183-
}
184-
}
185-
}
186-
187159
public struct Audio: Codable, Equatable, Sendable {
188160
/// Base64 encoded audio bytes generated by the model, in the format specified in the request.
189161
public let data: String

Sources/OpenAI/Public/Models/ChatStreamResult.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public struct ChatStreamResult: Codable, Equatable, Sendable {
2727
/// The role of the author of this message.
2828
public let role: Self.Role?
2929
public let toolCalls: [Self.ChoiceDeltaToolCall]?
30+
/// Annotations for the message, when applicable, as when using the web search tool.
31+
/// Web search tool: https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat
32+
public let annotations: [Annotation]?
3033

3134
/// Value for `reasoning` field in response.
3235
///
@@ -123,6 +126,7 @@ public struct ChatStreamResult: Codable, Equatable, Sendable {
123126
case refusal
124127
case audio
125128
case role
129+
case annotations
126130
case toolCalls = "tool_calls"
127131
case _reasoning = "reasoning"
128132
case _reasoningContent = "reasoning_content"

0 commit comments

Comments
 (0)