بث الاستجابات (Streaming)
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
send text to the client as it is produced.
الموضوعات المخطط لها
- A long reply can take seconds. Streaming sends pieces as they are generated.
- Spring AI offers
.stream().content(), which returns a reactiveFlux<String>(one piece at a time). - A Spring MVC endpoint can return it as server-sent events (
text/event-stream); verify the exact setup before recording. - Users see the first words sooner, though total time is the same.
- Structured output is awkward while streaming; stream plain text, validate whole results.
تفاصيل المخطط المبدئي
عرض عملي
@GetMapping(value = "/describe/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
Flux<String> stream(@RequestParam String name) {
return chatClient.prompt().user("Describe " + name).stream().content();
}اختبر فهمك
What type carries the pieces?
أظهر الإجابة
A Flux<String>.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.