Skip to content

Commit 819b027

Browse files
committed
updates
1 parent 67aef26 commit 819b027

File tree

8 files changed

+39
-16
lines changed

8 files changed

+39
-16
lines changed

scratchpad.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Cortex\Cortex;
66
use Cortex\Prompts\Prompt;
77
use Cortex\JsonSchema\SchemaFactory;
8-
use Cortex\Prompts\Enums\PromptType;
98
use Cortex\LLM\Data\Messages\UserMessage;
109
use Cortex\LLM\Data\Messages\SystemMessage;
1110

@@ -45,13 +44,13 @@
4544
$prompt = Cortex::prompt()->factory('langfuse')->make('test-prompt');
4645

4746
// Get a chat prompt builder
48-
$prompt = Cortex::prompt()->builder(PromptType::Chat)->messages([
47+
$prompt = Cortex::prompt()->builder('chat')->messages([
4948
new SystemMessage('You are an expert at geography.'),
5049
new UserMessage('What is the capital of {country}?'),
5150
]);
5251

5352
// Get a text prompt builder
54-
$prompt = Cortex::prompt()->builder(PromptType::Text);
53+
$prompt = Cortex::prompt()->builder('text');
5554

5655
$prompt = Prompt::factory()->make('test-prompt');
5756
$prompt = Prompt::builder()->messages([

src/Cortex.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Cortex\Prompts\Prompt;
99
use Cortex\Facades\Embeddings;
1010
use Cortex\Tasks\Enums\TaskType;
11-
use Cortex\Prompts\Enums\PromptType;
1211
use Cortex\Tasks\Builders\TextTaskBuilder;
1312
use Cortex\Prompts\Contracts\PromptBuilder;
1413
use Cortex\LLM\Contracts\LLM as LLMContract;
@@ -21,7 +20,7 @@ class Cortex
2120
/**
2221
* Create a prompt builder or factory.
2322
*
24-
* @param \Cortex\LLM\Data\Messages\MessageCollection|array<int, \Cortex\LLM\Contracts\Message>|string|null $messages
23+
* @param \Cortex\LLM\Data\Messages\MessageCollection|array<int, \Cortex\LLM\Contracts\Message|\Cortex\LLM\Data\Messages\MessagePlaceholder>|string|null $messages
2524
*
2625
* @return ($messages is null ? \Cortex\Prompts\Prompt : ($messages is string ? \Cortex\Prompts\Builders\TextPromptBuilder : \Cortex\Prompts\Builders\ChatPromptBuilder))
2726
*/
@@ -33,8 +32,8 @@ public static function prompt(
3332
}
3433

3534
return is_string($messages)
36-
? Prompt::builder(PromptType::Text)->text($messages)
37-
: Prompt::builder(PromptType::Chat)->messages($messages);
35+
? Prompt::builder('text')->text($messages)
36+
: Prompt::builder('chat')->messages($messages);
3837
}
3938

4039
/**

src/LLM/LLMManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function createDriver($driver): LLM // @pest-ignore-type
6262
/**
6363
* Create an OpenAI LLM driver instance.
6464
*
65-
* @param array<string, mixed> $config
65+
* @param array{default_model?: string, model_provider?: string, default_parameters: array<string, mixed>, options: array{api_key?: string, organization?: string, base_uri?: string, headers?: array<string, string>, query_params?: array<string, string>}} $config
6666
*/
6767
public function createOpenAIDriver(array $config, string $name): OpenAIChat|CacheDecorator
6868
{
@@ -142,7 +142,7 @@ public function createAnthropicDriver(array $config, string $name): AnthropicCha
142142
}
143143

144144
/**
145-
* @param array<string, mixed> $config
145+
* @param array{model_provider?: string} $config
146146
*
147147
* @throws \InvalidArgumentException
148148
*/

src/Prompts/Enums/PromptType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Cortex\Prompts\Enums;
66

7+
use Cortex\Prompts\Contracts\PromptBuilder;
78
use Cortex\Prompts\Builders\ChatPromptBuilder;
89
use Cortex\Prompts\Builders\TextPromptBuilder;
910

@@ -12,7 +13,12 @@ enum PromptType: string
1213
case Chat = 'chat';
1314
case Text = 'text';
1415

15-
public function builder(): ChatPromptBuilder|TextPromptBuilder
16+
/**
17+
* Get the prompt builder for the given type.
18+
*
19+
* @return ($this is \Cortex\Prompts\Enums\PromptType::Chat ? \Cortex\Prompts\Builders\ChatPromptBuilder : \Cortex\Prompts\Builders\TextPromptBuilder)
20+
*/
21+
public function builder(): PromptBuilder
1622
{
1723
return match ($this) {
1824
self::Chat => new ChatPromptBuilder(),

src/Prompts/Factories/LangfusePromptFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class LangfusePromptFactory implements PromptFactory
6363
{
6464
use DiscoversPsrImplementations;
6565

66+
/**
67+
* @param \Closure(array<string, mixed>): \Cortex\Prompts\Data\PromptMetadata $metadataResolver
68+
*/
6669
public function __construct(
6770
#[SensitiveParameter]
6871
protected string $username,

src/Prompts/Factories/McpPromptFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
*/
1414
class McpPromptFactory implements PromptFactory
1515
{
16+
public function __construct(
17+
protected string $baseUri,
18+
) {}
19+
1620
public function make(string $name, array $config = []): PromptTemplate
1721
{
1822
// TODO: Implement

src/Prompts/Prompt.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
use Cortex\Facades\PromptFactory;
88
use Cortex\Prompts\Enums\PromptType;
9-
use Cortex\Prompts\Builders\ChatPromptBuilder;
10-
use Cortex\Prompts\Builders\TextPromptBuilder;
9+
use Cortex\Prompts\Contracts\PromptBuilder;
1110
use Cortex\Prompts\Contracts\PromptFactory as PromptFactoryContract;
1211

1312
class Prompt
1413
{
1514
/**
1615
* Get the prompt builder for the given type.
1716
*
18-
* @return ($type is \Cortex\Prompts\Enums\PromptType::Chat ? \Cortex\Prompts\Builders\ChatPromptBuilder : \Cortex\Prompts\Builders\TextPromptBuilder)
17+
* @param value-of<\Cortex\Prompts\Enums\PromptType> $type
18+
*
19+
* @return ($type is 'chat' ? \Cortex\Prompts\Builders\ChatPromptBuilder : \Cortex\Prompts\Builders\TextPromptBuilder)
1920
*/
20-
public static function builder(PromptType $type = PromptType::Chat): ChatPromptBuilder|TextPromptBuilder
21+
public static function builder(string $type = 'chat'): PromptBuilder
2122
{
22-
return $type->builder();
23+
return PromptType::from($type)->builder();
2324
}
2425

2526
/**

src/Prompts/PromptFactoryManager.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Cortex\Prompts;
66

77
use Illuminate\Support\Manager;
8+
use Cortex\Prompts\Factories\McpPromptFactory;
89
use Cortex\Prompts\Factories\LangfusePromptFactory;
910

1011
class PromptFactoryManager extends Manager
@@ -16,7 +17,7 @@ public function getDefaultDriver(): string
1617

1718
public function createLangfuseDriver(): LangfusePromptFactory
1819
{
19-
/** @var array<string, mixed> $config */
20+
/** @var array{username?: string, password?: string, base_uri?: string} $config */
2021
$config = $this->config->get('cortex.prompt_factory.langfuse');
2122

2223
return new LangfusePromptFactory(
@@ -25,4 +26,14 @@ public function createLangfuseDriver(): LangfusePromptFactory
2526
$config['base_uri'] ?? 'https://cloud.langfuse.com',
2627
);
2728
}
29+
30+
public function createMcpDriver(): McpPromptFactory
31+
{
32+
/** @var array{base_uri?: string} $config */
33+
$config = $this->config->get('cortex.prompt_factory.mcp');
34+
35+
return new McpPromptFactory(
36+
$config['base_uri'] ?? 'http://localhost:3000',
37+
);
38+
}
2839
}

0 commit comments

Comments
 (0)