Skip to content

Commit 0923f9e

Browse files
Updated conversation history in a chat. Using just content of last message
1 parent 4bb6e8f commit 0923f9e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Agent.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
use Flarum\Discussion\Discussion;
66
use Flarum\Post\CommentPost;
7-
use Flarum\Post\Post;
87
use Flarum\Settings\SettingsRepositoryInterface;
98
use Flarum\User\User;
109
use Illuminate\Support\Arr;
11-
use Illuminate\Support\Facades\Log;
1210
use OpenAI;
1311
use OpenAI\Client;
1412

@@ -81,7 +79,7 @@ public function repliesToCommentPost(CommentPost $commentPost): void
8179
}
8280

8381
// add the last message with the prompt
84-
$messages[] = $this->createMessageForUserWithPrompt($title, $commentPost->content, $prompt);
82+
$messages[] = $this->createMessageForUserWithoutPrompt($commentPost->content);
8583

8684
// answer to the post
8785
$response = $this->sendCompletionRequest($messages);
@@ -129,8 +127,6 @@ public function checkModeration(string $title, string $content): bool
129127

130128
// convert results to array
131129
$res = json_decode(json_encode($results), true);
132-
resolve('log')->info('Results', $res);
133-
resolve('log')->info($results->flagged);
134130

135131
return !!$results->flagged;
136132
}
@@ -194,6 +190,14 @@ private function createMessageForUserWithPrompt($title, $content, $prompt): arra
194190
];
195191
}
196192

193+
private function createMessageForUserWithoutPrompt($content): array
194+
{
195+
return [
196+
'role' => 'user',
197+
'content' => $content
198+
];
199+
}
200+
197201
private function checkIfAssistantCanReplyToPost($commentPost): bool
198202
{
199203
$discussion = $commentPost->discussion;

0 commit comments

Comments
 (0)