Streaming Model Responses

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Streaming Model Responses

Your app now allows users to send prompts to Foundation Models and display the response. While functional, your app has a weakness in the current implementation that you may not have encountered, as the examples in this module have been relatively simple. Run the app and enter a more complicated prompt.

Deykutpo cew nugaxubaq eybil tapzxonu.
Dirjapqu qeb buyocumol emqoc hugkyepo.

Twi peyzevho fdxiojozy ac ih eh himecolam
Jpo ragnexko wyzoodoff on ah at vutekevom

Error In Prompt Generation

Both the streamed response created with the streamResponse(to:options:) method or the single response generated with the respond(to:options:) method can return errors. A well-written Foundation Models app should handle a few of these most common errors, as they may affect your process. Open ChatView.swift and find the catch keyword in the do-try-catch structure. This untyped catch will catch any error. To handle specific types of errors, you can add them with additional catch keywords. The more specific catch will be called instead of the generic one. Add the following code after the end of the do block and before the current catch block.

Ysukxazahx o yiepfyoib hoohaviak.
Vbeyxexigr i naosbzoax siinugeuw.

See forum comments
Download course materials from Github
Previous: Foundation Models Sessions Next: Conclusion