-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathActionConfigurationCreateCommand.php
More file actions
75 lines (62 loc) · 3.25 KB
/
Copy pathActionConfigurationCreateCommand.php
File metadata and controls
75 lines (62 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\ConnectorAi\Action\DataType\Text;
use Ibexa\Contracts\ConnectorAi\Action\RefineTextAction;
use Ibexa\Contracts\ConnectorAi\ActionConfiguration\ActionConfigurationCreateStruct;
use Ibexa\Contracts\ConnectorAi\ActionConfigurationServiceInterface;
use Ibexa\Contracts\ConnectorAi\ActionServiceInterface;
use Ibexa\Contracts\ConnectorAi\ActionType\ActionTypeRegistryInterface;
use Ibexa\Contracts\Core\Collection\ArrayMap;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'app:action-configuration-create'
)]
final readonly class ActionConfigurationCreateCommand
{
public function __construct(
private ActionConfigurationServiceInterface $actionConfigurationService,
private PermissionResolver $permissionResolver,
private UserService $userService,
private ActionServiceInterface $actionService,
private ActionTypeRegistryInterface $actionTypeRegistry
) {
}
public function __invoke(
#[Argument(name: 'user', description: 'Login of the user executing the actions')] string $user,
OutputInterface $output
): int {
$user = $user;
$this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin($user));
$refineTextActionType = $this->actionTypeRegistry->getActionType('refine_text');
$actionConfigurationCreateStruct = new ActionConfigurationCreateStruct('rewrite_casual');
$actionConfigurationCreateStruct->setType($refineTextActionType);
$actionConfigurationCreateStruct->setName('eng-GB', 'Rewrite in casual tone');
$actionConfigurationCreateStruct->setDescription('eng-GB', 'Rewrites the text using a casual tone');
$actionConfigurationCreateStruct->setActionHandler('openai-text-to-text');
$actionConfigurationCreateStruct->setActionHandlerOptions(new ArrayMap([
'max_tokens' => 4000,
'temperature' => 1,
'prompt' => 'Rewrite this content to improve readability. Preserve meaning and crucial information but use casual language accessible to a broader audience.',
'model' => 'gpt-4-turbo',
]));
$actionConfigurationCreateStruct->setEnabled(true);
$this->actionConfigurationService->createActionConfiguration($actionConfigurationCreateStruct);
$action = new RefineTextAction(new Text([
<<<TEXT
Proteins differ from one another primarily in their sequence of amino acids, which is dictated by the nucleotide sequence of their genes,
and which usually results in protein folding into a specific 3D structure that determines its activity.
TEXT
]));
$actionConfiguration = $this->actionConfigurationService->getActionConfiguration('rewrite_casual');
$actionResponse = $this->actionService->execute($action, $actionConfiguration)->getOutput();
assert($actionResponse instanceof Text);
$output->writeln($actionResponse->getText());
return Command::SUCCESS;
}
}