generateStream<C> function
ActionStream<GenerateResponseChunk, GenerateResponse>
generateStream<C>({
- required Model<
C> model, - String? prompt,
- List<
Message> ? messages, - C? config,
- List<
Tool> ? tools, - String? toolChoice,
- bool? returnToolRequests,
- int? maxTurns,
- JsonExtensionType? outputSchema,
- String? outputFormat,
- bool? outputConstrained,
- String? outputInstructions,
- bool? outputNoInstructions,
- String? outputContentType,
- Map<
String, dynamic> ? context,
Implementation
ActionStream<GenerateResponseChunk, GenerateResponse> generateStream<C>({
required Model<C> model,
String? prompt,
List<Message>? messages,
C? config,
List<Tool>? tools,
String? toolChoice,
bool? returnToolRequests,
int? maxTurns,
JsonExtensionType? outputSchema,
String? outputFormat,
bool? outputConstrained,
String? outputInstructions,
bool? outputNoInstructions,
String? outputContentType,
Map<String, dynamic>? context,
}) {
final streamController = StreamController<GenerateResponseChunk>();
final actionStream = ActionStream<GenerateResponseChunk, GenerateResponse>(
streamController.stream,
);
generate(
prompt: prompt,
messages: messages,
model: model,
config: config,
tools: tools,
toolChoice: toolChoice,
returnToolRequests: returnToolRequests,
maxTurns: maxTurns,
outputSchema: outputSchema,
outputFormat: outputFormat,
outputConstrained: outputConstrained,
outputInstructions: outputInstructions,
outputNoInstructions: outputNoInstructions,
outputContentType: outputContentType,
context: context,
onChunk: (chunk) {
if (streamController.isClosed) return;
streamController.add(chunk);
},
)
.then((result) {
actionStream.setResult(result);
if (!streamController.isClosed) {
streamController.close();
}
})
.catchError((e, s) {
actionStream.setError(e, s);
if (!streamController.isClosed) {
streamController.addError(e, s);
streamController.close();
}
});
return actionStream;
}