Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chatbot v2 #9656

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Chatbot v2 #9656

wants to merge 8 commits into from

Conversation

Remg
Copy link
Contributor

@Remg Remg commented Jan 22, 2024

No description provided.

@Remg Remg force-pushed the chatbot-v2 branch 4 times, most recently from 87462a0 to 6db1b5b Compare January 23, 2024 02:46
@Remg Remg force-pushed the chatbot-v2 branch 6 times, most recently from 860934f to 3edf971 Compare February 5, 2024 13:51
@Remg Remg self-assigned this Feb 6, 2024
@Remg Remg requested a review from ottaviano February 6, 2024 12:49
@@ -87,6 +87,7 @@ LEGISLATIVES_AVECVOUS_HOST=legislatives.avecvous.code
RENAISSANCE_HOST=renaissance.code
APP_RENAISSANCE_HOST=renaissance.code
WEBHOOK_RENAISSANCE_HOST=webhook.renaissance.code
WEBHOOK_PROXY_HOST=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be in .env.dev file, no?

retry_strategy:
max_retries: 10
delay: 3000
multiplier: 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the default value

Comment on lines +58 to +61
App\Telegram\Webhook\UrlGenerator: ~
Tests\App\Telegram\Webhook\ProxyUrlGenerator:
decorates: App\Telegram\Webhook\UrlGenerator
arguments: ['@.inner']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service UrlGenerator will be auto created by main service config and you can decorate it here

Suggested change
App\Telegram\Webhook\UrlGenerator: ~
Tests\App\Telegram\Webhook\ProxyUrlGenerator:
decorates: App\Telegram\Webhook\UrlGenerator
arguments: ['@.inner']
Tests\App\Telegram\Webhook\ProxyUrlGenerator:
decorates: App\Telegram\Webhook\UrlGenerator
arguments: ['@.inner']

Comment on lines +21 to +31
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
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about moving this method into OpenAIRunStatusEnum to avoid to have all mappings in this class?


public function __construct(string $openAIApiKey)
{
$this->openAI = \OpenAI::client($openAIApiKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about injecting this like a service in construct ?

Comment on lines +24 to +48
public function handle(Request $request): JsonResponse
{
if (!$secret = $request->headers->get(self::SECRET_TOKEN_HEADER)) {
throw new BadRequestHttpException('The request has no secret token header.');
}

if (!$bot = $this->botProvider->findOneEnabledBySecret($secret)) {
throw new BadRequestHttpException('No bot found for given secret token.');
}

$this->logger->log($bot, 'Received webhook request.');

if (!$content = $request->getContent()) {
throw new BadRequestHttpException('No content in request');
}

try {
$data = BotApi::jsonValidate($content, true);
} catch (InvalidJsonException $e) {
throw new BadRequestHttpException('The request content is not a valid JSON payload.');
}

try {
$update = Update::fromResponse($data);
} catch (InvalidArgumentException $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO all this stuff can be moved into TelegramBotController because it's too related to the HTTP request. Actually I can't use this handler from Sf Command but I can use UpdateHandler. Wdyt?

Comment on lines +1484 to +1488
chatbot:
type:
telegram: Telegram
assistant_type:
openai: OpenAI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about making it in two lines ?

chatbot.type.telegram:
chatbot.assistant_type.openai:

it's easier to search when it's in one line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants