-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds agent executor and prompt generator with interceptors
- Loading branch information
1 parent
0292400
commit bfc9121
Showing
7 changed files
with
94 additions
and
8,732 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Chat\PromptGenerator; | ||
|
||
use LLM\Agents\LLM\Prompt\Chat\PromptInterface; | ||
use LLM\Agents\PromptGenerator\InterceptorHandler; | ||
use LLM\Agents\PromptGenerator\PromptGeneratorInput; | ||
use LLM\Agents\PromptGenerator\PromptInterceptorInterface; | ||
|
||
final class Dump implements PromptInterceptorInterface | ||
{ | ||
public function generate( | ||
PromptGeneratorInput $input, | ||
InterceptorHandler $next, | ||
): PromptInterface { | ||
dump($input->prompt->format()); | ||
|
||
return $next($input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Chat\PromptGenerator; | ||
|
||
use LLM\Agents\LLM\Prompt\Chat\MessagePrompt; | ||
use LLM\Agents\LLM\Prompt\Chat\Prompt; | ||
use LLM\Agents\LLM\Prompt\Chat\PromptInterface; | ||
use LLM\Agents\PromptGenerator\Context; | ||
use LLM\Agents\PromptGenerator\InterceptorHandler; | ||
use LLM\Agents\PromptGenerator\PromptGeneratorInput; | ||
use LLM\Agents\PromptGenerator\PromptInterceptorInterface; | ||
|
||
final class SessionContextInjector implements PromptInterceptorInterface | ||
{ | ||
public function generate( | ||
PromptGeneratorInput $input, | ||
InterceptorHandler $next, | ||
): PromptInterface { | ||
\assert($input->prompt instanceof Prompt); | ||
|
||
if ( | ||
(!$input->context instanceof Context) | ||
|| $input->context->getAuthContext() === null | ||
) { | ||
return $next($input); | ||
} | ||
|
||
return $next( | ||
input: $input->withPrompt( | ||
$input->prompt | ||
->withAddedMessage( | ||
MessagePrompt::system( | ||
prompt: 'Session context: {active_context}', | ||
), | ||
)->withValues( | ||
values: [ | ||
'active_context' => \json_encode($input->context->getAuthContext()), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.