Closed dekdynamics closed 1 month ago
To address the issue of the agent stalling mid-reply, follow these steps:
Check sendMessage
Method in Chat.php
:
sendMessage
method./app/Livewire/Chat.php
public function sendMessage(): void
{
// Existing code...
try {
// Your logic here
} catch (Exception $e) {
$this->alert('error', 'An error occurred, please try again later');
Log::error($e);
$this->pending = false;
}
}
Review AI Gateway Inference Methods:
inference
methods of the various AI gateways./app/AI/OpenAIGateway.php
/app/AI/ReplicateAIGateway.php
/app/AI/PerplexityAIGateway.php
/app/AI/TogetherAIGateway.php
/app/AI/AnthropicAIGateway.php
/app/AI/HuggingfaceAIGateway.php
/app/AI/CohereAIGateway.php
/app/AI/GroqAIGateway.php
/app/AI/MistralAIGateway.php
public function inference(array $params): array
{
// Existing code...
try {
// Your logic here
} catch (Exception $e) {
Log::error($e);
return ['content' => 'An error occurred, please try again later', 'input_tokens' => 0, 'output_tokens' => 0];
}
}
Add Logging for Debugging:
Log::debug('Debug message');
Handle Streaming Callback:
Chat.php
is properly handling exceptions.
private function getStreamingCallback(): callable
{
return function ($content, bool $replace = false) {
try {
$this->stream(
to: 'streamtext'.$this->thread->id,
content: $content,
replace: $replace,
);
} catch (Exception $e) {
Log::error($e);
$this->pending = false;
}
};
}
/app/Livewire/Chat.php /app/AI/NostrRag.php /app/AI/OpenAIGateway.php /app/AI/ReplicateAIGateway.php /app/AI/PerplexityAIGateway.php /app/AI/TogetherAIGateway.php /app/AI/AnthropicAIGateway.php /app/AI/HuggingfaceAIGateway.php /app/AI/CohereAIGateway.php /app/AI/GroqAIGateway.php /app/AI/MistralAIGateway.php
We are limited by how livewire streaming works here. See https://github.com/livewire/livewire/discussions/7882
Perhaps in this specific case there is a simpler answer, but we would have to replicate the issue locally first.
Try the same question for the Fast Talking Man agent. It happens to me every time I ask this question.
I just tried again right now and its been stuck here for over 2 minutes:
Hi Team,
I get this behaviour very often:
While this is happening, I can't stop the reply or say anything new in the chat.
This one has been stuck for ~10 minutes, but typically it never returns and I start a new chat.