-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
972 additions
and
247 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Admin\OpenAI; | ||
|
||
use Sonata\AdminBundle\Admin\AbstractAdmin; | ||
use Sonata\AdminBundle\Datagrid\DatagridMapper; | ||
use Sonata\AdminBundle\Datagrid\ListMapper; | ||
use Sonata\AdminBundle\Form\FormMapper; | ||
use Sonata\AdminBundle\Route\RouteCollectionInterface; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
|
||
class AssistantAdmin extends AbstractAdmin | ||
{ | ||
protected function configureRoutes(RouteCollectionInterface $collection): void | ||
{ | ||
$collection->remove('show'); | ||
} | ||
|
||
protected function configureFormFields(FormMapper $form): void | ||
{ | ||
$form | ||
->with('Metadonnées 🧱', ['class' => 'col-md-6']) | ||
->add('name', TextType::class, [ | ||
'label' => 'Nom', | ||
]) | ||
->add('openAiId', TextType::class, [ | ||
'label' => 'ID OpenAI', | ||
]) | ||
->end() | ||
; | ||
} | ||
|
||
protected function configureDatagridFilters(DatagridMapper $filter): void | ||
{ | ||
$filter | ||
->add('name', null, [ | ||
'label' => 'Nom', | ||
'show_filter' => true, | ||
]) | ||
->add('openAiId', null, [ | ||
'label' => 'ID OpenAI', | ||
'show_filter' => true, | ||
]) | ||
; | ||
} | ||
|
||
protected function configureListFields(ListMapper $list): void | ||
{ | ||
$list | ||
->addIdentifier('name', null, [ | ||
'label' => 'Code', | ||
]) | ||
->add('openAiId', null, [ | ||
'label' => 'ID OpenAI', | ||
]) | ||
->add(ListMapper::NAME_ACTIONS, null, [ | ||
'virtual_field' => true, | ||
'actions' => [ | ||
'edit' => [], | ||
], | ||
]) | ||
; | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace App\Chatbot\Enum; | ||
|
||
use App\OpenAI\Enum\RunStatusEnum as OpenAIRunStatusEnum; | ||
|
||
enum RunStatusEnum: string | ||
{ | ||
case QUEUED = 'queued'; | ||
case IN_PROGRESS = 'in_progress'; | ||
case CANCELLED = 'cancelled'; | ||
case FAILED = 'failed'; | ||
case COMPLETED = 'completed'; | ||
case UNKNOWN = 'unknown'; | ||
|
||
public const NEED_REFRESH = [ | ||
self::QUEUED, | ||
self::IN_PROGRESS, | ||
]; | ||
|
||
public static function fromOpenAI(OpenAIRunStatusEnum $runStatus): self | ||
{ | ||
return match ($runStatus) { | ||
OpenAIRunStatusEnum::QUEUED => self::QUEUED, | ||
OpenAIRunStatusEnum::IN_PROGRESS => self::IN_PROGRESS, | ||
OpenAIRunStatusEnum::COMPLETED => self::COMPLETED, | ||
OpenAIRunStatusEnum::CANCELLING, OpenAIRunStatusEnum::CANCELLED => self::CANCELLED, | ||
OpenAIRunStatusEnum::REQUIRES_ACTION, OpenAIRunStatusEnum::EXPIRED, OpenAIRunStatusEnum::FAILED => self::FAILED, | ||
default => self::UNKNOWN | ||
}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Chatbot/EventListener/OpenAIAssistantMessageListener.php
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,28 @@ | ||
<?php | ||
|
||
namespace App\Chatbot\EventListener; | ||
|
||
use App\Chatbot\Event\AssistantMessageEvent; | ||
use App\Entity\Chatbot\Message; | ||
use App\OpenAI\Event\AssistantMessageEvent as OpenAIAssistantMessageEvent; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
#[AsEventListener] | ||
class OpenAIAssistantMessageListener | ||
{ | ||
public function __construct(private readonly EventDispatcherInterface $dispatcher) | ||
{ | ||
} | ||
|
||
public function __invoke(OpenAIAssistantMessageEvent $event): void | ||
{ | ||
$message = $event->message; | ||
|
||
if (!$message instanceof Message) { | ||
return; | ||
} | ||
|
||
$this->dispatcher->dispatch(new AssistantMessageEvent($message)); | ||
} | ||
} |
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.