Skip to content

Commit

Permalink
fix llm switch problem
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangtianyu committed Dec 14, 2023
1 parent 066e83b commit b0349d7
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DevPilotChatToolWindow {

private final Project project;

private final LlmProvider llmProvider;
private LlmProvider llmProvider;

private final DevPilotChatCompletionRequest multiSessionRequest = new DevPilotChatCompletionRequest();

Expand All @@ -60,7 +60,6 @@ public DevPilotChatToolWindow(Project project, ToolWindow toolWindow) {
this.devPilotChatToolWindowPanel = new JPanel(new GridBagLayout());
this.chatContentPanel = new ScrollablePanel();
this.userChatPanel = new UserChatPanel(this::syncSendAndDisplay, this::stopSending);
this.llmProvider = new LlmProviderFactory().getLlmProvider(project);

var gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
Expand Down Expand Up @@ -153,6 +152,10 @@ private String sendMessage(Integer sessionType, String message) {
multiSessionRequest.getMessages().add(userMessage);
devPilotChatCompletionRequest.getMessages().addAll(multiSessionRequest.getMessages());
}

var llmProvider = new LlmProviderFactory().getLlmProvider(project);
this.llmProvider = llmProvider;

String chatCompletion = llmProvider.chatCompletion(devPilotChatCompletionRequest);
if (SessionTypeEnum.MULTI_TURN.equals(sessionTypeEnum) &&
devPilotChatCompletionRequest.getMessages().size() > multiSessionRequest.getMessages().size()) {
Expand Down Expand Up @@ -207,6 +210,9 @@ public void syncSendAndDisplay(Integer sessionType, EditorActionEnum editorActio
}

private void stopSending() {
if (llmProvider == null) {
return;
}
llmProvider.interruptSend();
userChatPanel.setIconSend();
userChatPanel.setSending(false);
Expand Down

0 comments on commit b0349d7

Please sign in to comment.