Hi
I share the code of function that launches the stream query:
func lanzarPeticion() async{
defer{👎🔘lanzarConsulta.toggle()}
do {
let sessionStream = LanguageModelSession(model: modelStream, instructions: instructions)
let genOptions = generarSamplingMode(temperatura: temperatura, maxResponseTokens: maxResponseTokens, probabilityThreshold: probabilityThreshold, topK: topK, seed: semilla)
let responseStream = sessionStream.streamResponse(
to: prompt, options: genOptions)
for try await partial in responseStream {
withAnimation{
self.respuesta = partial.content
t.createPartialTime()
}
}
withAnimation{
t.stop()
}
} catch {
// all the logic for errors
}
}
Clarifications about the code:
First of all, English is dominant on code but sometimes use Spanish, my native language, specially when terms overlap swift or framework ones; I have my own emoji rules to avoid characters an improve readability (at this moment I'm indie developer so I set the rules)
The defer block is to "free" the button that launches the request to avoid double clicks that will generate 2 successive requests.
The t instance is a timer.
The function "generarSamplingMode" collects all the values of View and set the sampling mode.
I'm using Xcode Version 26.0 (17A324)
instructions and prompt instances are State attributes that takes the values in Screen, it's straight forward.
Other issue is the output tokens on stream mode.
Please, re-watch again between 0:29 and 0:56 I executed a batch of three runs on streaming mode and the output is always 2 tokens. With other apps the same result. My intuition is maybe it stops counting when its receives the first output or the counter isn't able to update with a continuous flow of updates.