mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 22:31:24 +00:00
feat: add support for auto resolving compilation errors (#318)
This commit is contained in:
parent
7031a6dc73
commit
f831a1facd
51 changed files with 919 additions and 595 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package ee.carlrobert.codegpt.toolwindow.chat;
|
||||
|
||||
import static ee.carlrobert.codegpt.completions.CompletionRequestProvider.COMPLETION_SYSTEM_PROMPT;
|
||||
import static ee.carlrobert.codegpt.completions.CompletionRequestProvider.FIX_COMPILE_ERRORS_SYSTEM_PROMPT;
|
||||
import static ee.carlrobert.codegpt.completions.llama.PromptTemplate.LLAMA;
|
||||
import static ee.carlrobert.llm.client.util.JSONUtil.e;
|
||||
import static ee.carlrobert.llm.client.util.JSONUtil.jsonArray;
|
||||
|
|
@ -13,13 +14,14 @@ import static org.awaitility.Awaitility.await;
|
|||
|
||||
import ee.carlrobert.codegpt.CodeGPTKeys;
|
||||
import ee.carlrobert.codegpt.EncodingManager;
|
||||
import ee.carlrobert.codegpt.completions.ConversationType;
|
||||
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
|
||||
import ee.carlrobert.codegpt.conversations.ConversationService;
|
||||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
|
||||
import ee.carlrobert.codegpt.settings.state.LlamaSettingsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.standard.StandardChatToolWindowTabPanel;
|
||||
import ee.carlrobert.embedding.CheckedFile;
|
||||
import ee.carlrobert.embedding.ReferencedFile;
|
||||
import ee.carlrobert.llm.client.http.exchange.StreamHttpExchange;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -88,12 +90,15 @@ public class StandardChatToolWindowTabPanelTest extends IntegrationTest {
|
|||
|
||||
public void testSendingOpenAIMessageWithReferencedContext() {
|
||||
getProject().putUserData(CodeGPTKeys.SELECTED_FILES, List.of(
|
||||
new CheckedFile("TEST_FILE_NAME_1", "TEST_FILE_PATH_1", "TEST_FILE_CONTENT_1"),
|
||||
new CheckedFile("TEST_FILE_NAME_2", "TEST_FILE_PATH_2", "TEST_FILE_CONTENT_2"),
|
||||
new CheckedFile("TEST_FILE_NAME_3", "TEST_FILE_PATH_3", "TEST_FILE_CONTENT_3")));
|
||||
new ReferencedFile("TEST_FILE_NAME_1", "TEST_FILE_PATH_1", "TEST_FILE_CONTENT_1"),
|
||||
new ReferencedFile("TEST_FILE_NAME_2", "TEST_FILE_PATH_2", "TEST_FILE_CONTENT_2"),
|
||||
new ReferencedFile("TEST_FILE_NAME_3", "TEST_FILE_PATH_3", "TEST_FILE_CONTENT_3")));
|
||||
useOpenAIService();
|
||||
ConfigurationState.getInstance().setSystemPrompt(COMPLETION_SYSTEM_PROMPT);
|
||||
var message = new Message("Hello!");
|
||||
var message = new Message("TEST_MESSAGE");
|
||||
message.setUserMessage("TEST_MESSAGE");
|
||||
message.setReferencedFilePaths(
|
||||
List.of("TEST_FILE_PATH_1", "TEST_FILE_PATH_2", "TEST_FILE_PATH_3"));
|
||||
var conversation = ConversationService.getInstance().startConversation();
|
||||
var panel = new StandardChatToolWindowTabPanel(getProject(), conversation);
|
||||
expectOpenAI((StreamHttpExchange) request -> {
|
||||
|
|
@ -125,7 +130,7 @@ public class StandardChatToolWindowTabPanelTest extends IntegrationTest {
|
|||
+ "```TEST_FILE_NAME_3\n"
|
||||
+ "TEST_FILE_CONTENT_3\n"
|
||||
+ "```\n\n"
|
||||
+ "Question: Hello!")));
|
||||
+ "Question: TEST_MESSAGE")));
|
||||
return List.of(
|
||||
jsonMapResponse("choices", jsonArray(jsonMap("delta", jsonMap("role", "assistant")))),
|
||||
jsonMapResponse("choices", jsonArray(jsonMap("delta", jsonMap("content", "Hel")))),
|
||||
|
|
@ -170,6 +175,93 @@ public class StandardChatToolWindowTabPanelTest extends IntegrationTest {
|
|||
List.of("TEST_FILE_PATH_1", "TEST_FILE_PATH_2", "TEST_FILE_PATH_3"));
|
||||
}
|
||||
|
||||
public void testFixCompileErrorsWithOpenAIService() {
|
||||
getProject().putUserData(CodeGPTKeys.SELECTED_FILES, List.of(
|
||||
new ReferencedFile("TEST_FILE_NAME_1", "TEST_FILE_PATH_1", "TEST_FILE_CONTENT_1"),
|
||||
new ReferencedFile("TEST_FILE_NAME_2", "TEST_FILE_PATH_2", "TEST_FILE_CONTENT_2"),
|
||||
new ReferencedFile("TEST_FILE_NAME_3", "TEST_FILE_PATH_3", "TEST_FILE_CONTENT_3")));
|
||||
useOpenAIService();
|
||||
ConfigurationState.getInstance().setSystemPrompt(COMPLETION_SYSTEM_PROMPT);
|
||||
var message = new Message("TEST_MESSAGE");
|
||||
message.setUserMessage("TEST_MESSAGE");
|
||||
message.setReferencedFilePaths(
|
||||
List.of("TEST_FILE_PATH_1", "TEST_FILE_PATH_2", "TEST_FILE_PATH_3"));
|
||||
var conversation = ConversationService.getInstance().startConversation();
|
||||
var panel = new StandardChatToolWindowTabPanel(getProject(), conversation);
|
||||
expectOpenAI((StreamHttpExchange) request -> {
|
||||
assertThat(request.getUri().getPath()).isEqualTo("/v1/chat/completions");
|
||||
assertThat(request.getMethod()).isEqualTo("POST");
|
||||
assertThat(request.getHeaders().get(AUTHORIZATION).get(0)).isEqualTo("Bearer TEST_API_KEY");
|
||||
assertThat(request.getBody())
|
||||
.extracting(
|
||||
"model",
|
||||
"messages")
|
||||
.containsExactly(
|
||||
"gpt-4",
|
||||
List.of(
|
||||
Map.of("role", "system", "content", FIX_COMPILE_ERRORS_SYSTEM_PROMPT),
|
||||
Map.of("role", "user", "content",
|
||||
"Use the following context to answer question at the end:\n\n"
|
||||
+ "File Path: TEST_FILE_PATH_1\n"
|
||||
+ "File Content:\n"
|
||||
+ "```TEST_FILE_NAME_1\n"
|
||||
+ "TEST_FILE_CONTENT_1\n"
|
||||
+ "```\n\n"
|
||||
+ "File Path: TEST_FILE_PATH_2\n"
|
||||
+ "File Content:\n"
|
||||
+ "```TEST_FILE_NAME_2\n"
|
||||
+ "TEST_FILE_CONTENT_2\n"
|
||||
+ "```\n\n"
|
||||
+ "File Path: TEST_FILE_PATH_3\n"
|
||||
+ "File Content:\n"
|
||||
+ "```TEST_FILE_NAME_3\n"
|
||||
+ "TEST_FILE_CONTENT_3\n"
|
||||
+ "```\n\n"
|
||||
+ "Question: TEST_MESSAGE")));
|
||||
return List.of(
|
||||
jsonMapResponse("choices", jsonArray(jsonMap("delta", jsonMap("role", "assistant")))),
|
||||
jsonMapResponse("choices", jsonArray(jsonMap("delta", jsonMap("content", "Hel")))),
|
||||
jsonMapResponse("choices", jsonArray(jsonMap("delta", jsonMap("content", "lo")))),
|
||||
jsonMapResponse("choices", jsonArray(jsonMap("delta", jsonMap("content", "!")))));
|
||||
});
|
||||
|
||||
panel.sendMessage(message, ConversationType.FIX_COMPILE_ERRORS);
|
||||
|
||||
await().atMost(5, SECONDS)
|
||||
.until(() -> {
|
||||
var messages = conversation.getMessages();
|
||||
return !messages.isEmpty() && "Hello!".equals(messages.get(0).getResponse());
|
||||
});
|
||||
var encodingManager = EncodingManager.getInstance();
|
||||
assertThat(panel.getTokenDetails()).extracting(
|
||||
"systemPromptTokens",
|
||||
"conversationTokens",
|
||||
"userPromptTokens",
|
||||
"highlightedTokens")
|
||||
.containsExactly(
|
||||
encodingManager.countTokens(COMPLETION_SYSTEM_PROMPT),
|
||||
encodingManager.countTokens(message.getPrompt()),
|
||||
0,
|
||||
0);
|
||||
assertThat(panel.getConversation())
|
||||
.isNotNull()
|
||||
.extracting("id", "model", "clientCode", "discardTokenLimit")
|
||||
.containsExactly(
|
||||
conversation.getId(),
|
||||
conversation.getModel(),
|
||||
conversation.getClientCode(),
|
||||
false);
|
||||
var messages = panel.getConversation().getMessages();
|
||||
assertThat(messages.size()).isOne();
|
||||
assertThat(messages.get(0))
|
||||
.extracting("id", "prompt", "response", "referencedFilePaths")
|
||||
.containsExactly(
|
||||
message.getId(),
|
||||
message.getPrompt(),
|
||||
message.getResponse(),
|
||||
List.of("TEST_FILE_PATH_1", "TEST_FILE_PATH_2", "TEST_FILE_PATH_3"));
|
||||
}
|
||||
|
||||
public void testSendingLlamaMessage() {
|
||||
useLlamaService();
|
||||
var configurationState = ConfigurationState.getInstance();
|
||||
|
|
@ -218,7 +310,7 @@ public class StandardChatToolWindowTabPanelTest extends IntegrationTest {
|
|||
e("stop", true)));
|
||||
});
|
||||
|
||||
panel.sendMessage(message);
|
||||
panel.sendMessage(message, ConversationType.DEFAULT);
|
||||
|
||||
await().atMost(5, SECONDS)
|
||||
.until(() -> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue