You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: responses.md
+20-1
Original file line number
Diff line number
Diff line change
@@ -417,7 +417,18 @@ Route::get('/chat', function () {
417
417
});
418
418
```
419
419
420
-
This event stream may be consumed via an [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) object by your application's frontend. The `eventStream` method will automatically send a `</stream>` update to the event stream when the stream is complete:
420
+
If you would like to customize the name of the event, you may yield an instance of the `StreamedEvent` class:
421
+
422
+
```php
423
+
use Illuminate\Http\StreamedEvent;
424
+
425
+
yield new StreamedEvent(
426
+
event: 'update',
427
+
data: $response->choices[0],
428
+
);
429
+
```
430
+
431
+
Event streams may be consumed via an [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) object by your application's frontend. The `eventStream` method will automatically send a `</stream>` update to the event stream when the stream is complete:
To customize the final event that is sent to the event stream, you may provide a `StreamedEvent` instance to the `eventStream` method's `endStreamWith` argument:
448
+
449
+
```php
450
+
return response()->eventStream(function () {
451
+
// ...
452
+
}, endStreamWith: new StreamedEvent(event: 'update', data: '</stream>'));
0 commit comments