BarcodeReaderTool
NewiOSmacOSwatchOSpublic struct BarcodeReaderTool : Tool, @unchecked SendableA tool that scans machine-readable codes in an image.
When the model encounters an image containing machine-readable codes, it can call this tool to decode them. The tool returns an array of Barcode results, each containing the decoded content and the symbology type.
To enable this tool, configure your LanguageModelSession with an instance of BarcodeReaderTool.
let barcodeTool = BarcodeReaderTool()
let session = LanguageModelSession(tools: [barcodeTool])You can override the default name and description to customize how the model identifies and uses the tool.
let customTool = BarcodeReaderTool(
name: "scanQRCode",
description: "Scan QR codes"
)Declaration
public struct BarcodeReaderTool : Tool, @unchecked Sendable {
/// A unique name for the tool, such as "get_weather", "toggleDarkMode", or "search contacts".
public let name: String
/// A natural language description of when and how to use the tool.
public let description: String
/// Creates a tool for decoding machine-readable codes.
///
/// - Parameters:
/// - name: The name of the tool as exposed to the model. If not provided, a default name is used.
/// - description: A description of what the tool does, used by the model to determine when to call it. If not provided, a default description is used.
public init(name: String? = nil, description: String? = nil)
/// The arguments that this tool should accept.
///
/// Typically arguments are either a ``Generable`` type or ``GeneratedContent``.
public struct Arguments {
/// An instance of the generation schema.
nonisolated public static var generationSchema: GenerationSchema { get }
/// This instance represented as generated content.
///
/// Conformance to this protocol is provided by the `@Generable` macro.
/// A manual implementation may be used to map values onto properties using
/// different names. Use the generated content property as shown below, to
/// manually return a new ``GeneratedContent`` with the properties you specify.
///
/// ```swift
/// struct Person: ConvertibleToGeneratedContent {
/// var name: String
/// var age: Int
///
/// var generatedContent: GeneratedContent {
/// GeneratedContent(properties: [
/// "firstName": name,
/// "ageInYears": age
/// ])
/// }
/// }
/// ```
///
/// - Important: If your type also conforms to ``ConvertibleFromGeneratedContent``,
/// it is critical that this implementation be symmetrical with ``ConvertibleFromGeneratedContent/init(_:)``.
nonisolated public var generatedContent: GeneratedContent { get }
/// A representation of partially generated content
nonisolated public struct PartiallyGenerated : Identifiable, nonisolated ConvertibleFromGeneratedContent {
/// The stable identity of the entity associated with this instance.
public var id: GenerationID
/// Creates an instance from content generated by a model.
///
/// Conformance to this protocol is provided by the `@Generable` macro.
/// A manual implementation may be used to map values onto properties using
/// different names. To manually initialize your type from generated content,
/// decode the values as shown below:
///
/// ```swift
/// struct Person: ConvertibleFromGeneratedContent {
/// var name: String
/// var age: Int
///
/// init(_ content: GeneratedContent) {
/// self.name = try content.value(forProperty: "firstName")
/// self.age = try content.value(forProperty: "ageInYears")
/// }
/// }
/// ```
///
/// - Important: If your type also conforms to ``ConvertibleToGeneratedContent``,
/// it is critical that this implementation be symmetrical with ``ConvertibleToGeneratedContent/generatedContent``.
///
/// - SeeAlso: `@Generable` macro ``Generable(description:)``
nonisolated public init(_ content: GeneratedContent) throws
/// A type representing the stable identity of the entity associated withTruncated.