|
7 | 7 | use Closure; |
8 | 8 | use Cortex\Pipeline; |
9 | 9 | use Cortex\Facades\LLM; |
| 10 | +use Cortex\Support\Utils; |
10 | 11 | use Cortex\JsonSchema\Schema; |
11 | 12 | use Cortex\Contracts\Pipeable; |
12 | 13 | use Cortex\Pipeline\RuntimeConfig; |
@@ -37,7 +38,7 @@ public function handlePipeable(mixed $payload, RuntimeConfig $config, Closure $n |
37 | 38 |
|
38 | 39 | // If there is only one variable, and the input is a string, |
39 | 40 | // we can assume the user is passing the value directly. |
40 | | - if (is_string($payload) && $variables->containsOneItem()) { |
| 41 | + if (is_string($payload) && $variables->hasSole()) { |
41 | 42 | return $next($this->format([ |
42 | 43 | $variables->first() => $payload, |
43 | 44 | ]), $config); |
@@ -79,17 +80,7 @@ public function llm( |
79 | 80 | throw new PromptException('No LLM provider or metadata provided.'); |
80 | 81 | } |
81 | 82 |
|
82 | | - if ($provider instanceof LLMContract) { |
83 | | - $llm = $provider; |
84 | | - } elseif ($provider === null) { |
85 | | - if (is_string($this->metadata?->provider)) { |
86 | | - $llm = LLM::provider($this->metadata->provider); |
87 | | - } else { |
88 | | - $llm = $this->metadata->provider; |
89 | | - } |
90 | | - } else { |
91 | | - $llm = LLM::provider($provider); |
92 | | - } |
| 83 | + $llm = Utils::llm($provider ?? $this->metadata?->provider); |
93 | 84 |
|
94 | 85 | if (is_string($model)) { |
95 | 86 | $llm->withModel($model); |
@@ -128,6 +119,13 @@ public function llm( |
128 | 119 | return $this->pipe($llm); |
129 | 120 | } |
130 | 121 |
|
| 122 | + public function withMetadata(PromptMetadata $metadata): self |
| 123 | + { |
| 124 | + $this->metadata = $metadata; |
| 125 | + |
| 126 | + return $this; |
| 127 | + } |
| 128 | + |
131 | 129 | public function withCompiler(PromptCompiler $compiler): self |
132 | 130 | { |
133 | 131 | $this->compiler = $compiler; |
|
0 commit comments