Skip to content

Commit b2cd5e1

Browse files
committed
new web search updates
1 parent 981f525 commit b2cd5e1

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/Models/Item.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,15 @@ import MetaCodable
436436
}
437437

438438
@Codable @CodedAt("type") public enum Action: Equatable, Hashable, Sendable {
439+
@Codable @CodedAt("type") public enum Source: Equatable, Hashable, Sendable {
440+
/// - Parameter url: The URL of the source.
441+
case url(url: URL)
442+
}
443+
439444
/// Performs a web search query.
440445
/// - Parameter query: The search query.
441-
case search(query: String)
446+
/// - Parameter sources: The sources used in the search.
447+
case search(query: String, sources: [Source]?)
442448

443449
/// Opens a specific URL from search results.
444450
/// - Parameter url: The URL opened by the model.

src/Models/Request.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import MetaCodable
2020
/// Include logprobs with assistant messages.
2121
case outputLogprobs = "message.output_text.logprobs"
2222

23+
/// Include the sources of the web search tool call.
24+
case webSearchSources = "web_search_call.action.sources"
25+
2326
/// Includes an encrypted version of reasoning tokens in reasoning item outputs.
2427
///
2528
/// 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).

src/Models/Tool.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,24 @@ import MetaCodable
245245
case medium
246246
}
247247

248+
@Codable @CodingKeys(.snake_case) public struct Filters: Equatable, Hashable, Sendable {
249+
/// Allowed domains for the search.
250+
///
251+
/// Subdomains of the provided domains are allowed as well.
252+
public var allowedDomains: [String]
253+
254+
/// Create a new `Filters` instance.
255+
///
256+
/// - Parameter allowedDomains: Allowed domains for the search.
257+
public init(allowedDomains: [String]) {
258+
self.allowedDomains = allowedDomains
259+
}
260+
261+
public static func allowedDomains(_ domains: [String]) -> Filters {
262+
return Filters(allowedDomains: domains)
263+
}
264+
}
265+
248266
/// Approximate location parameters for the search.
249267
public struct UserLocation: Equatable, Hashable, Codable, Sendable {
250268
/// The type of location approximation
@@ -289,11 +307,18 @@ import MetaCodable
289307
/// Approximate location parameters for the search.
290308
public var userLocation: UserLocation?
291309

310+
/// A filter defining allowed domains for the search.
311+
///
312+
/// If not provided, all domains are allowed.
313+
public var filters: Filters?
314+
292315
/// Create a new `WebSearch` instance.
293316
///
294317
/// - Parameter searchContextSize: High level guidance for the amount of context window space to use for the search.
295318
/// - Parameter userLocation: Approximate location parameters for the search.
296-
public init(searchContextSize: ContextSize = .medium, userLocation: UserLocation? = nil) {
319+
/// - Parameter filters: A filter defining allowed domains for the search.
320+
public init(searchContextSize: ContextSize = .medium, userLocation: UserLocation? = nil, filters: Filters? = nil) {
321+
self.filters = filters
297322
self.userLocation = userLocation
298323
self.searchContextSize = searchContextSize
299324
}
@@ -589,7 +614,7 @@ import MetaCodable
589614
/// This tool searches the web for relevant results to use in a response.
590615
///
591616
/// Learn more about the [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses).
592-
@CodedAs("web_search_preview")
617+
@CodedAs("web_search")
593618
case webSearch(WebSearch)
594619

595620
/// Give the model access to additional tools via remote Model Context Protocol (MCP) servers.
@@ -678,8 +703,9 @@ public extension Tool {
678703
/// Learn more about the [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses).
679704
/// - Parameter contextSize: High level guidance for the amount of context window space to use for the search.
680705
/// - Parameter userLocation: Approximate location parameters for the search.
681-
static func webSearch(contextSize: WebSearch.ContextSize = .medium, userLocation: WebSearch.UserLocation? = nil) -> Self {
682-
.webSearch(WebSearch(searchContextSize: contextSize, userLocation: userLocation))
706+
/// - Parameter filters: A filter defining allowed domains for the search.
707+
static func webSearch(contextSize: WebSearch.ContextSize = .medium, userLocation: WebSearch.UserLocation? = nil, filters: WebSearch.Filters? = nil) -> Self {
708+
.webSearch(WebSearch(searchContextSize: contextSize, userLocation: userLocation, filters: filters))
683709
}
684710

685711
// Give the model access to additional tools via remote Model Context Protocol (MCP) servers.

0 commit comments

Comments
 (0)