searchResults
An asynchronous stream that delivers the results of a search to your app for processing.
Declaration
var searchResults: some AsyncSequence<SpotlightSearchTool.SearchReply, Never> { get }Mentioned in
Discussion
Use this property to monitor the search results as the tool generates them. Each time the model calls the Spotlight search tool’s call(arguments:) method, the tool generates one or more SpotlightSearchTool.SearchReply structures with information about the results. Use this information to track the tool’s behavior while responding to the model’s requests.
Monitor the asynchronous stream using a for await loop in a separate task, as shown in the following example:
let tool = SpotlightSearchTool()
let session = LanguageModelSession(tools: [tool])
Task {
for await result in tool.searchResults {
// Process each search result as it arrives.
}
}
let response = try await session.respond(to: "Show me recent emails from Shelly”)For more information about how to process search results, see Making your indexed content available to Foundation Models.