Skip to content

Commit 403e3f3

Browse files
committed
feat: infers prompt capability from model if provided
1 parent 7d007d1 commit 403e3f3

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/Builders/PromptBuilder.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,34 @@ private function inferCapabilityFromOutputModalities(): CapabilityEnum
519519
}
520520
}
521521

522+
/**
523+
* Infers the capability from a model's implemented interfaces.
524+
*
525+
* @since n.e.x.t
526+
*
527+
* @param ModelInterface $model The model to infer capability from.
528+
* @return CapabilityEnum|null The inferred capability, or null if none can be inferred.
529+
*/
530+
private function inferCapabilityFromModelInterfaces(ModelInterface $model): ?CapabilityEnum
531+
{
532+
// Check model interfaces in order of preference
533+
if ($model instanceof TextGenerationModelInterface) {
534+
return CapabilityEnum::textGeneration();
535+
}
536+
if ($model instanceof ImageGenerationModelInterface) {
537+
return CapabilityEnum::imageGeneration();
538+
}
539+
if ($model instanceof TextToSpeechConversionModelInterface) {
540+
return CapabilityEnum::textToSpeechConversion();
541+
}
542+
if ($model instanceof SpeechGenerationModelInterface) {
543+
return CapabilityEnum::speechGeneration();
544+
}
545+
546+
// No supported interface found
547+
return null;
548+
}
549+
522550
/**
523551
* Checks if the current prompt is supported by the selected model.
524552
*
@@ -655,9 +683,20 @@ public function generateResult(?CapabilityEnum $capability = null): GenerativeAi
655683
{
656684
$this->validateMessages();
657685

658-
// If capability is not provided, infer it from output modalities
686+
// If capability is not provided, infer it
659687
if ($capability === null) {
660-
$capability = $this->inferCapabilityFromOutputModalities();
688+
// First try to infer from a specific model if one is set
689+
if ($this->model !== null) {
690+
$inferredCapability = $this->inferCapabilityFromModelInterfaces($this->model);
691+
if ($inferredCapability !== null) {
692+
$capability = $inferredCapability;
693+
}
694+
}
695+
696+
// If still no capability, infer from output modalities
697+
if ($capability === null) {
698+
$capability = $this->inferCapabilityFromOutputModalities();
699+
}
661700
}
662701

663702
$model = $this->getConfiguredModel($capability);

0 commit comments

Comments
 (0)