انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-056-L04

بث الاستجابات (Streaming)

  • الدرس 4 من 7
  • Junior
في هذا الدرس 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 reactive Flux<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.
تفاصيل المخطط المبدئي

عرض عملي

java
@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>.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.