let description = "Retrieve the latest weather information for a city" @Generable struct Arguments { @Guide(description: "The city to fetch the weather for") var city: String } func call(arguments: Arguments) async throws -> ToolOutput { let places = try await CLGeocoder().geocodeAddressString(arguments.city) let weather = try await WeatherService.shared.weather(for: places.first!.location!) let temperature = weather.currentWeather.temperature.value let content = GeneratedContent(properties: ["temperature": temperature]) let output = ToolOutput(content) return output } } … let session = LanguageModelSession( tools: [GetWeatherTool()], instructions: "Help the user with weather forecasts." )
Code-along: Bring on-device AI to your app using the Foundation Models framework - Explore prompt design & safety for on-device foundation models - Explore large language models on Apple silicon with MLX ↑ Foundation Models Ͱͳ͘ɺΦϯσόΠεLLM ͰࣗલσʔλΛՃֶश͍ͤͨ͞έʔε