Skip to content

Commit c534360

Browse files
committed
tweaks
1 parent 359e3fb commit c534360

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

src/LLM/Drivers/AnthropicChat.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,8 @@ protected function mapStreamResponse(StreamResponse $response): ChatStreamResult
185185
foreach ($response as $chunk) {
186186
$chunkDelta = null;
187187
$accumulatedToolCallsSoFar = null;
188-
189188
$finishReason = static::mapFinishReason($chunk->delta->stop_reason);
190189

191-
// Handle different event types
192190
switch ($chunk->type) {
193191
case 'message_start':
194192
$messageId = $chunk->message->id;

src/Prompts/Builders/Concerns/BuildsPrompts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function llm(
122122
}
123123

124124
/**
125-
* Convenience method to build and pipe the prompt template.
125+
* Convenience method to build and pipe the prompt template to a given pipeable.
126126
*/
127127
public function pipe(Pipeable|callable $pipeable): Pipeline
128128
{

src/Prompts/Contracts/PromptTemplate.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Closure;
88
use Cortex\Pipeline;
99
use Cortex\LLM\Contracts\LLM;
10+
use Cortex\Contracts\Pipeable;
1011
use Illuminate\Support\Collection;
1112

1213
interface PromptTemplate
@@ -26,7 +27,12 @@ public function format(?array $variables = null): mixed;
2627
public function variables(): Collection;
2728

2829
/**
29-
* Convenience method to pipe the prompt template to an LLM.
30+
* Convenience method to build and pipe the prompt template to an LLM.
3031
*/
3132
public function llm(LLM|string|null $provider = null, Closure|string|null $model = null): Pipeline;
33+
34+
/**
35+
* Convenience method to build and pipe the prompt template to a given pipeable.
36+
*/
37+
public function pipe(Pipeable|callable $pipeable): Pipeline;
3238
}

src/Prompts/Factories/LangfusePromptFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,21 @@ protected function getResponseContent(string $name, array $options = []): array
207207
protected static function defaultMetadataResolver(): Closure
208208
{
209209
return function (array $config): PromptMetadata {
210-
$structuredOutput = $config['structuredOutput'] ?? null;
210+
$structuredOutput = $config['structured_output'] ?? null;
211211

212212
if (is_string($structuredOutput) || is_array($structuredOutput)) {
213213
$structuredOutput = SchemaFactory::fromJson($structuredOutput);
214214
}
215215

216+
$structuredOutputMode = StructuredOutputMode::tryFrom($config['structured_output_mode'] ?? '');
217+
216218
return new PromptMetadata(
217219
$config['provider'] ?? null,
218220
$config['model'] ?? null,
219221
$config['parameters'] ?? [],
220222
$config['tools'] ?? [],
221223
$structuredOutput,
222-
StructuredOutputMode::tryFrom($config['structuredOutputMode'] ?? StructuredOutputMode::Auto->value) ?? StructuredOutputMode::Auto,
224+
$structuredOutputMode ?? StructuredOutputMode::Auto,
223225
$config['additional'] ?? [],
224226
);
225227
};

tests/Unit/Experimental/PlaygroundTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ enum Sentiment: string
438438
);
439439

440440
$result = $prompt->llm()->stream([
441-
'topic' => 'dragons',
441+
'topic' => 'trolls',
442442
]);
443443

444444
foreach ($result as $chunk) {
445-
dump($chunk->contentSoFar);
445+
dump($chunk->parsedOutput);
446446
}
447447

448448
dd('done');

tests/Unit/Prompts/Factories/LangfusePromptFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function createLangfuseFactory(
259259
'max_tokens' => 100,
260260
],
261261
'tools' => ['calculator', 'search'],
262-
'structuredOutput' => [
262+
'structured_output' => [
263263
'type' => 'object',
264264
'properties' => [
265265
'name' => [
@@ -268,7 +268,7 @@ function createLangfuseFactory(
268268
],
269269
'required' => ['name'],
270270
],
271-
'structuredOutputMode' => StructuredOutputMode::Tool->value,
271+
'structured_output_mode' => StructuredOutputMode::Tool->value,
272272
'additional' => [
273273
'custom_field' => 'custom_value',
274274
],

0 commit comments

Comments
 (0)