isResponding
A Boolean value that indicates a response is being generated.
Declaration
final var isResponding: Bool { get }Mentioned in
Discussion
Disable buttons and other interactions to prevent users from submitting a second prompt while the model is responding to their first prompt.
struct ShopView: View {
@State var session = LanguageModelSession()
@State var joke = ""
var body: some View {
Text(joke)
Button("Generate joke") {
Task {
assert(!session.isResponding, "It should not be possible to tap this button while the model is responding")
joke = try await session.respond(to: "Tell me a joke").content
}
}
.disabled(session.isResponding) // Prevent concurrent calls to respond
}
}