Skip to content

Commit 945833e

Browse files
Enhancement for system prompt
1 parent 0923f9e commit 945833e

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

locale/en.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ muhammedsaidckr-chatgpt:
1616
role_label: Role
1717
role_help: Select the role that will be used to generate the answer.
1818
prompt_label: Prompt
19-
prompt_help: Enter the prompt that will be used to generate the answer. [title] and [content] variables should be kept constant.
19+
prompt_help: Enter the prompt that will be used to generate the answer. [title] variable should be kept constant.
2020
enable_on_discussion_started_label: Enable on discussion started
2121
enable_on_discussion_started_help: The discussion will receive an answer based on content of first post when the discussion is started.
2222
enabled_tags_label: Enabled Tags

locale/tr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ muhammedsaidckr-chatgpt:
1616
role_label: Rol
1717
role_help: Yanıtı oluşturmak için kullanılacak rolü giriniz.
1818
prompt_label: İstek
19-
prompt_help: Yanıtı oluşturmak için kullanılacak isteği girin. [title] ve [content] değişkenlerini sabit bırakınız.
19+
prompt_help: Yanıtı oluşturmak için kullanılacak isteği girin. [title] değişkenini sabit bırakınız.
2020
enable_on_discussion_started_label: Tartışma başlatıldığında etkinleştir
2121
enable_on_discussion_started_help: Tartışma başlatıldığında, tartışmanın içeriğine dayalı bir yanıt alır.
2222
answer_duration_label: Cevap Verme Süresi

src/Agent.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function repliesToCommentPost(CommentPost $commentPost): void
7979
}
8080

8181
// add the last message with the prompt
82-
$messages[] = $this->createMessageForUserWithoutPrompt($commentPost->content);
82+
$messages[] = $this->createMessageForUser($commentPost->content);
8383

8484
// answer to the post
8585
$response = $this->sendCompletionRequest($messages);
@@ -173,24 +173,26 @@ private function saveResponse($response, $discussionId): bool
173173
private function createMessages($title, $content, $role, $prompt): array
174174
{
175175
return [
176-
['role' => 'system', 'content' => $role],
177-
$this->createMessageForUserWithPrompt($title, $content, $prompt)
176+
$this->createMessageForSystem($role, $prompt, $title),
177+
$this->createMessageForUser($content)
178178
];
179179
}
180180

181-
private function createMessageForUserWithPrompt($title, $content, $prompt): array
181+
private function createMessageForSystem($role, $prompt, $title): array
182182
{
183+
$prompt = str_replace(
184+
['[title]', '[content]'],
185+
[$title, ''],
186+
$prompt
187+
);
188+
$systemPrompt = $role . ' ' . $prompt;
183189
return [
184-
'role' => 'user',
185-
'content' => str_replace(
186-
['[title]', '[content]'],
187-
[$title, $content],
188-
$prompt
189-
)
190+
'role' => 'system',
191+
'content' => $systemPrompt
190192
];
191193
}
192194

193-
private function createMessageForUserWithoutPrompt($content): array
195+
private function createMessageForUser($content): array
194196
{
195197
return [
196198
'role' => 'user',

0 commit comments

Comments
 (0)