Implement task-specific assistants
Different assistants are now specialized for various tasks within the
same thread. This commit introduces an assistant specialized in handling
reviews and another dedicated to managing requests directed at ChatGPT.
Additionally, this commit modifies the instantiation of the review
assistant, which previously occurred upon patchset creation. It is now
initialized during the run creation process, aligning with the setup for
the requests assistant.
Change-Id: I50aa362fa56dbb095f653eeedb4a6788befc52e9
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
index c1a50ec..47715d5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
@@ -17,6 +17,7 @@
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.review.ReviewBatch;
import com.googlesource.gerrit.plugins.chatgpt.mode.interfaces.client.api.chatgpt.IChatGptClient;
+import com.googlesource.gerrit.plugins.chatgpt.settings.Settings;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -65,7 +66,7 @@
commentProperties = gerritClient.getClientData(change).getCommentProperties();
gerritCommentRange = new GerritCommentRange(gerritClient, change);
String patchSet = gerritClient.getPatchSet(change);
- if (patchSet.isEmpty()) {
+ if (patchSet.isEmpty() && config.getGptMode() == Settings.MODES.stateless) {
log.info("No file to review has been found in the PatchSet");
return;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistant.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantBase.java
similarity index 86%
rename from src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistant.java
rename to src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantBase.java
index e2548d5..cc11000 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistant.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantBase.java
@@ -8,10 +8,12 @@
import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.chatgpt.ChatGptTools;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptTool;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.UriResourceLocatorStateful;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.git.GitRepoFiles;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.prompt.ChatGptPromptStateful;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.model.api.chatgpt.*;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
@@ -23,33 +25,38 @@
import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
@Slf4j
-public class ChatGptAssistant extends ClientBase {
- public static final String KEY_ASSISTANT_ID = "assistantId";
+public class ChatGptAssistantBase extends ClientBase {
+ @Getter
+ protected String keyAssistantId;
private final ChatGptHttpClient httpClient = new ChatGptHttpClient();
+ private final ChangeSetData changeSetData;
private final GerritChange change;
private final GitRepoFiles gitRepoFiles;
private final PluginDataHandler projectDataHandler;
- public ChatGptAssistant(
+ public ChatGptAssistantBase(
Configuration config,
+ ChangeSetData changeSetData,
GerritChange change,
GitRepoFiles gitRepoFiles,
PluginDataHandlerProvider pluginDataHandlerProvider
) {
super(config);
+ this.changeSetData = changeSetData;
this.change = change;
this.gitRepoFiles = gitRepoFiles;
this.projectDataHandler = pluginDataHandlerProvider.getProjectScope();
}
public void setupAssistant() {
- String assistantId = projectDataHandler.getValue(KEY_ASSISTANT_ID);
+ String assistantId = projectDataHandler.getValue(keyAssistantId);
if (assistantId == null || config.getForceCreateAssistant()) {
+ log.debug("Setup Assistant for project {}", change.getProjectNameKey());
String fileId = uploadRepoFiles();
projectDataHandler.setValue(KEY_FILE_ID, fileId);
assistantId = createAssistant(fileId);
- projectDataHandler.setValue(KEY_ASSISTANT_ID, assistantId);
+ projectDataHandler.setValue(keyAssistantId, assistantId);
log.info("Project assistant created with ID: {}", assistantId);
}
else {
@@ -79,7 +86,7 @@
private Request createRequest(String fileId) {
URI uri = URI.create(config.getGptDomain() + UriResourceLocatorStateful.assistantCreateUri());
log.debug("ChatGPT Create Assistant request URI: {}", uri);
- ChatGptPromptStateful chatGptPromptStateful = new ChatGptPromptStateful(config, change);
+ ChatGptPromptStateful chatGptPromptStateful = new ChatGptPromptStateful(config, changeSetData, change);
ChatGptParameters chatGptParameters = new ChatGptParameters(config, change.getIsCommentEvent());
ChatGptTool[] tools = new ChatGptTool[] {
ChatGptTools.retrieveFormatRepliesTool()
@@ -94,6 +101,7 @@
.tools(tools)
.toolResources(toolResources)
.build();
+ log.debug("ChatGPT Create Assistant request body: {}", requestBody);
return httpClient.createRequestFromJson(uri.toString(), config.getGptToken(), requestBody);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantRequests.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantRequests.java
new file mode 100644
index 0000000..c78d349
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantRequests.java
@@ -0,0 +1,24 @@
+package com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.chatgpt;
+
+import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import com.googlesource.gerrit.plugins.chatgpt.data.PluginDataHandlerProvider;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
+import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.git.GitRepoFiles;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class ChatGptAssistantRequests extends ChatGptAssistantBase {
+ public static final String KEY_REQUESTS_ASSISTANT_ID = "requestsAssistantId";
+
+ public ChatGptAssistantRequests(
+ Configuration config,
+ ChangeSetData changeSetData,
+ GerritChange change,
+ GitRepoFiles gitRepoFiles,
+ PluginDataHandlerProvider pluginDataHandlerProvider
+ ) {
+ super(config, changeSetData, change, gitRepoFiles, pluginDataHandlerProvider);
+ keyAssistantId = KEY_REQUESTS_ASSISTANT_ID;
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantReview.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantReview.java
new file mode 100644
index 0000000..26176f7
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptAssistantReview.java
@@ -0,0 +1,24 @@
+package com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.chatgpt;
+
+import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import com.googlesource.gerrit.plugins.chatgpt.data.PluginDataHandlerProvider;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
+import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.git.GitRepoFiles;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class ChatGptAssistantReview extends ChatGptAssistantBase {
+ public static final String KEY_REVIEW_ASSISTANT_ID = "reviewAssistantId";
+
+ public ChatGptAssistantReview(
+ Configuration config,
+ ChangeSetData changeSetData,
+ GerritChange change,
+ GitRepoFiles gitRepoFiles,
+ PluginDataHandlerProvider pluginDataHandlerProvider
+ ) {
+ super(config, changeSetData, change, gitRepoFiles, pluginDataHandlerProvider);
+ keyAssistantId = KEY_REVIEW_ASSISTANT_ID;
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java
index 02d50a6..ca3bc3d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java
@@ -10,6 +10,7 @@
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptResponseContent;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
import com.googlesource.gerrit.plugins.chatgpt.mode.interfaces.client.api.chatgpt.IChatGptClient;
+import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.git.GitRepoFiles;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.model.api.chatgpt.ChatGptThreadMessageResponse;
import lombok.extern.slf4j.Slf4j;
@@ -19,12 +20,18 @@
private static final String TYPE_MESSAGE_CREATION = "message_creation";
private static final String TYPE_TOOL_CALLS = "tool_calls";
+ private final GitRepoFiles gitRepoFiles;
private final PluginDataHandlerProvider pluginDataHandlerProvider;
@VisibleForTesting
@Inject
- public ChatGptClientStateful(Configuration config, PluginDataHandlerProvider pluginDataHandlerProvider) {
+ public ChatGptClientStateful(
+ Configuration config,
+ GitRepoFiles gitRepoFiles,
+ PluginDataHandlerProvider pluginDataHandlerProvider
+ ) {
super(config);
+ this.gitRepoFiles = gitRepoFiles;
this.pluginDataHandlerProvider = pluginDataHandlerProvider;
}
@@ -45,7 +52,15 @@
);
chatGptThreadMessage.addMessage();
- ChatGptRun chatGptRun = new ChatGptRun(threadId, config, pluginDataHandlerProvider);
+ ChatGptRun chatGptRun = new ChatGptRun(
+ threadId,
+ config,
+ changeSetData,
+ change,
+ gitRepoFiles,
+ pluginDataHandlerProvider,
+ isCommentEvent
+ );
chatGptRun.createRun();
chatGptRun.pollRun();
// Attribute `requestBody` is valued for testing purposes
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptRun.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptRun.java
index bd734fa..31d537e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptRun.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptRun.java
@@ -4,9 +4,12 @@
import com.googlesource.gerrit.plugins.chatgpt.data.PluginDataHandler;
import com.googlesource.gerrit.plugins.chatgpt.data.PluginDataHandlerProvider;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.ClientBase;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptResponseMessage;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptToolCall;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.UriResourceLocatorStateful;
+import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.git.GitRepoFiles;
import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.model.api.chatgpt.*;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
@@ -14,7 +17,6 @@
import java.net.URI;
import java.util.*;
-import static com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.chatgpt.ChatGptAssistant.KEY_ASSISTANT_ID;
import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
@Slf4j
@@ -28,19 +30,43 @@
public static final String COMPLETED_STATUS = "completed";
private final ChatGptHttpClient httpClient = new ChatGptHttpClient();
+ private final ChangeSetData changeSetData;
+ private final GerritChange change;
private final String threadId;
- private final PluginDataHandler projectDataHandler;
+ private final GitRepoFiles gitRepoFiles;
+ private final PluginDataHandlerProvider pluginDataHandlerProvider;
+ private final boolean isCommentEvent;
private ChatGptResponse runResponse;
private ChatGptListResponse stepResponse;
+ private String keyAssistantId;
- public ChatGptRun(String threadId, Configuration config, PluginDataHandlerProvider pluginDataHandlerProvider) {
+ public ChatGptRun(
+ String threadId,
+ Configuration config,
+ ChangeSetData changeSetData,
+ GerritChange change,
+ GitRepoFiles gitRepoFiles,
+ PluginDataHandlerProvider pluginDataHandlerProvider,
+ boolean isCommentEvent
+ ) {
super(config);
+ this.changeSetData = changeSetData;
+ this.change = change;
this.threadId = threadId;
- this.projectDataHandler = pluginDataHandlerProvider.getProjectScope();
+ this.gitRepoFiles = gitRepoFiles;
+ this.pluginDataHandlerProvider = pluginDataHandlerProvider;
+ this.isCommentEvent = isCommentEvent;
}
public void createRun() {
+ ChatGptAssistantBase chatGptAssistant = isCommentEvent ?
+ new ChatGptAssistantRequests(config, changeSetData, change, gitRepoFiles, pluginDataHandlerProvider) :
+ new ChatGptAssistantReview(config, changeSetData, change, gitRepoFiles, pluginDataHandlerProvider);
+
+ chatGptAssistant.setupAssistant();
+ keyAssistantId = chatGptAssistant.getKeyAssistantId();
+
Request request = runCreateRequest();
log.info("ChatGPT Create Run request: {}", request);
@@ -85,8 +111,9 @@
URI uri = URI.create(config.getGptDomain() + UriResourceLocatorStateful.runsUri(threadId));
log.debug("ChatGPT Create Run request URI: {}", uri);
+ PluginDataHandler projectDataHandler = pluginDataHandlerProvider.getProjectScope();
ChatGptCreateRunRequest requestBody = ChatGptCreateRunRequest.builder()
- .assistantId(projectDataHandler.getValue(KEY_ASSISTANT_ID))
+ .assistantId(projectDataHandler.getValue(keyAssistantId))
.build();
return httpClient.createRequestFromJson(uri.toString(), config.getGptToken(), requestBody);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/gerrit/GerritClientPatchSetStateful.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/gerrit/GerritClientPatchSetStateful.java
index 7c66e56..b1e6481 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/gerrit/GerritClientPatchSetStateful.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/gerrit/GerritClientPatchSetStateful.java
@@ -5,13 +5,10 @@
import com.google.gerrit.server.util.ManualRequestContext;
import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
-import com.googlesource.gerrit.plugins.chatgpt.data.PluginDataHandlerProvider;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
-import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.chatgpt.ChatGptAssistant;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritClientPatchSet;
import com.googlesource.gerrit.plugins.chatgpt.mode.interfaces.client.api.gerrit.IGerritClientPatchSet;
-import com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api.git.GitRepoFiles;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
@@ -27,27 +24,17 @@
private static final Pattern EXTRACT_B_FILENAMES_FROM_PATCH_SET = Pattern.compile("^diff --git .*? b/(.*)$",
Pattern.MULTILINE);
- private final GitRepoFiles gitRepoFiles;
- private final PluginDataHandlerProvider pluginDataHandlerProvider;
-
private GerritChange change;
@VisibleForTesting
@Inject
- public GerritClientPatchSetStateful(
- Configuration config,
- AccountCache accountCache,
- GitRepoFiles gitRepoFiles,
- PluginDataHandlerProvider pluginDataHandlerProvider) {
+ public GerritClientPatchSetStateful(Configuration config, AccountCache accountCache) {
super(config, accountCache);
- this.gitRepoFiles = gitRepoFiles;
- this.pluginDataHandlerProvider = pluginDataHandlerProvider;
}
public String getPatchSet(ChangeSetData changeSetData, GerritChange change) throws Exception {
+ if (change.getIsCommentEvent()) return "";
this.change = change;
- ChatGptAssistant chatGptAssistant = new ChatGptAssistant(config, change, gitRepoFiles, pluginDataHandlerProvider);
- chatGptAssistant.setupAssistant();
String formattedPatch = getPatchFromGerrit();
List<String> files = extractFilesFromPatch(formattedPatch);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/prompt/ChatGptPromptStateful.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/prompt/ChatGptPromptStateful.java
index 8844427..40fec9b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/prompt/ChatGptPromptStateful.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/prompt/ChatGptPromptStateful.java
@@ -6,20 +6,25 @@
import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
import lombok.extern.slf4j.Slf4j;
+import java.util.ArrayList;
+import java.util.List;
+
@Slf4j
public class ChatGptPromptStateful extends ChatGptPrompt {
public static String DEFAULT_GPT_ASSISTANT_NAME;
public static String DEFAULT_GPT_ASSISTANT_DESCRIPTION;
public static String DEFAULT_GPT_ASSISTANT_INSTRUCTIONS;
+ public static String DEFAULT_GPT_ASSISTANT_INSTRUCTIONS_REVIEW;
+ public static String DEFAULT_GPT_ASSISTANT_INSTRUCTIONS_REQUESTS;
public static String DEFAULT_GPT_MESSAGE_REVIEW;
+ private final ChangeSetData changeSetData;
private final GerritChange change;
- private ChangeSetData changeSetData;
-
- public ChatGptPromptStateful(Configuration config, GerritChange change) {
+ public ChatGptPromptStateful(Configuration config, ChangeSetData changeSetData, GerritChange change) {
super(config);
+ this.changeSetData = changeSetData;
this.change = change;
this.isCommentEvent = change.getIsCommentEvent();
// Avoid repeated loading of prompt constants
@@ -28,23 +33,31 @@
}
}
- public ChatGptPromptStateful(Configuration config, ChangeSetData changeSetData, GerritChange change) {
- this(config, change);
- this.changeSetData = changeSetData;
- }
-
public String getDefaultGptAssistantDescription() {
return String.format(DEFAULT_GPT_ASSISTANT_DESCRIPTION, change.getProjectName());
}
public String getDefaultGptAssistantInstructions() {
- String instructions = DEFAULT_GPT_SYSTEM_PROMPT + DOT +
- String.format(DEFAULT_GPT_ASSISTANT_INSTRUCTIONS, change.getProjectName()) + SPACE +
- getPatchSetReviewUserPrompt();
- if (config.getGptReviewCommitMessages()) {
- instructions += SPACE + getReviewPromptCommitMessages();
+ List<String> instructions = new ArrayList<>(List.of(
+ DEFAULT_GPT_SYSTEM_PROMPT + DOT,
+ String.format(DEFAULT_GPT_ASSISTANT_INSTRUCTIONS, change.getProjectName())
+ ));
+ if (change.getIsCommentEvent()) {
+ instructions.addAll(List.of(
+ DEFAULT_GPT_ASSISTANT_INSTRUCTIONS_REQUESTS,
+ getCommentRequestUserPrompt(changeSetData.getCommentPropertiesSize())
+ ));
}
- return instructions;
+ else {
+ instructions.addAll(List.of(
+ DEFAULT_GPT_ASSISTANT_INSTRUCTIONS_REVIEW,
+ getPatchSetReviewUserPrompt()
+ ));
+ if (config.getGptReviewCommitMessages()) {
+ instructions.add(getReviewPromptCommitMessages());
+ }
+ }
+ return String.join(SPACE, instructions);
}
public String getDefaultGptThreadReviewMessage(String patchSet) {
diff --git a/src/main/resources/config/promptsStateful.json b/src/main/resources/config/promptsStateful.json
index f7f4108..415a868 100644
--- a/src/main/resources/config/promptsStateful.json
+++ b/src/main/resources/config/promptsStateful.json
@@ -1,7 +1,9 @@
{
"DEFAULT_GPT_ASSISTANT_NAME": "PatchSet Reviewer",
"DEFAULT_GPT_ASSISTANT_DESCRIPTION": "PatchSet Reviewer for project %s.",
- "DEFAULT_GPT_ASSISTANT_INSTRUCTIONS": "The JSON project file uploaded includes the source files for the `%s` project. The structure uses the file paths from the project's root as keys, and arrays of lines as their values. This arrangement ensures that the line number for any given line corresponds to its index in the array plus one. You will receive a patch in the standard git format-patch format. Your tasks include: 1. applying this patch to the corresponding existing files, and 2. conducting a review of the patch. Here are the guidelines for reviewing the patch: A. Identify any potential problems and offer suggestions for enhancements, presenting each point as a separate reply; B. Focus solely on identifying and suggesting solutions for issues; refrain from highlighting any positive aspects; C. Only evaluate the code that has been modified in the patch; refrain from reviewing any other parts of the project's code that were not changed.",
+ "DEFAULT_GPT_ASSISTANT_INSTRUCTIONS": "The JSON project file uploaded includes the source files for the `%s` project. The structure uses the file paths from the project's root as keys, and arrays of lines as their values. This arrangement ensures that the line number for any given line corresponds to its index in the array plus one.",
+ "DEFAULT_GPT_ASSISTANT_INSTRUCTIONS_REVIEW": "You will receive a patch in the standard git format-patch format. Your tasks include: 1. applying this patch to the corresponding existing files, and 2. conducting a review of the patch. Here are the guidelines for reviewing the patch: A. Identify any potential problems and offer suggestions for enhancements, presenting each point as a separate reply; B. Focus solely on identifying and suggesting solutions for issues; refrain from highlighting any positive aspects; C. Only evaluate the code that has been modified in the patch; refrain from reviewing any other parts of the project's code that were not changed.",
+ "DEFAULT_GPT_ASSISTANT_INSTRUCTIONS_REQUESTS": "You will receive a prompt request regarding the source files and/or one or more patches applied to these files. You are required to respond to the prompt, which may involve providing information, completing a task, answering a query, or making specified modifications.",
"DEFAULT_GPT_MESSAGE_REVIEW": "Review the following Patch Set: ```%s```",
"DEFAULT_GPT_HOW_TO_FIND_COMMIT_MESSAGE": "the \"Subject:\" entry of the Patch Set"
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewStatefulTest.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewStatefulTest.java
index d5ecc17..75be9c3 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewStatefulTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewStatefulTest.java
@@ -61,11 +61,11 @@
when(pluginDataHandlerProvider.getProjectScope()).thenReturn(pluginDataHandler);
}
- protected void initConfig() {
- super.initConfig();
+ protected void initTest() {
+ super.initTest();
// Load the prompts
- chatGptPromptStateful = new ChatGptPromptStateful(config, getGerritChange());
+ chatGptPromptStateful = new ChatGptPromptStateful(config, changeSetData, getGerritChange());
}
protected void setupMockRequests() throws RestApiException {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
index ee6116f..fbe3f4b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
@@ -120,6 +120,7 @@
protected PluginConfig globalConfig;
protected PluginConfig projectConfig;
protected Configuration config;
+ protected ChangeSetData changeSetData;
protected GerritClient gerritClient;
protected PatchSetReviewer patchSetReviewer;
protected ConfigCreator mockConfigCreator;
@@ -300,8 +301,8 @@
return reviewInputCaptor;
}
- private void initTest() {
- ChangeSetData changeSetData = new ChangeSetData(
+ protected void initTest() {
+ changeSetData = new ChangeSetData(
GPT_USER_ACCOUNT_ID,
config.getVotingMinScore(),
config.getMaxReviewFileSize()
@@ -386,14 +387,14 @@
private IChatGptClient getChatGptClient() {
return switch (config.getGptMode()) {
- case stateful -> new ChatGptClientStateful(config, pluginDataHandlerProvider);
+ case stateful -> new ChatGptClientStateful(config, gitRepoFiles, pluginDataHandlerProvider);
case stateless -> new ChatGptClientStateless(config);
};
}
private IGerritClientPatchSet getGerritClientPatchSet() {
return switch (config.getGptMode()) {
- case stateful -> new GerritClientPatchSetStateful(config, accountCacheMock, gitRepoFiles, pluginDataHandlerProvider);
+ case stateful -> new GerritClientPatchSetStateful(config, accountCacheMock);
case stateless -> new GerritClientPatchSetStateless(config, accountCacheMock);
};
}