generateFor function
Future<GenerationResult>
generateFor(
- GenerativeSource source, {
- required ProviderRegistry registry,
- required ProviderCredentials credentials,
- Client? httpClient,
- void onProgress(
- GenerationProgress progress
Calls the ai_abstracted generator that matches source's kind through
registry, authenticated with credentials.
The provider-specific options live in GenerativeSource.params; this maps
them onto the typed request for each capability. Reports provider progress
through onProgress.
Implementation
Future<GenerationResult> generateFor(
GenerativeSource source, {
required ProviderRegistry registry,
required ProviderCredentials credentials,
http.Client? httpClient,
void Function(GenerationProgress progress)? onProgress,
}) {
final id = providerIdFor(source.providerId);
switch (source.kind) {
case GenerativeKind.image:
return registry
.imageGenerator(id, credentials, httpClient: httpClient)
.generateImage(_imageRequest(source), onProgress: onProgress);
case GenerativeKind.video:
return registry
.videoGenerator(id, credentials, httpClient: httpClient)
.generateVideo(_videoRequest(source), onProgress: onProgress);
case GenerativeKind.music:
return registry
.musicGenerator(id, credentials, httpClient: httpClient)
.generateMusic(_musicRequest(source), onProgress: onProgress);
case GenerativeKind.speech:
return registry
.speechGenerator(id, credentials, httpClient: httpClient)
.generateSpeech(_speechRequest(source), onProgress: onProgress);
case GenerativeKind.soundEffect:
return registry
.soundEffectGenerator(id, credentials, httpClient: httpClient)
.generateSoundEffect(_soundEffectRequest(source), onProgress: onProgress);
}
}