Skip to content

Commit

Permalink
fix: execute chat completion request in background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed Dec 17, 2024
1 parent 59fe48f commit 1c2a549
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ee.carlrobert.codegpt.completions;

import com.intellij.openapi.application.ApplicationManager;
import ee.carlrobert.codegpt.settings.GeneralSettings;
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
import ee.carlrobert.llm.client.openai.completion.ErrorDetails;
Expand All @@ -16,15 +17,17 @@ public ToolwindowChatCompletionRequestHandler(
}

public void call(ChatCompletionParameters callParameters) {
try {
eventSource = startCall(callParameters);
} catch (TotalUsageExceededException e) {
completionResponseEventListener.handleTokensExceeded(
callParameters.getConversation(),
callParameters.getMessage());
} finally {
sendInfo(callParameters);
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
eventSource = startCall(callParameters);
} catch (TotalUsageExceededException e) {
completionResponseEventListener.handleTokensExceeded(
callParameters.getConversation(),
callParameters.getMessage());
} finally {
sendInfo(callParameters);
}
});
}

public void cancel() {
Expand Down

0 comments on commit 1c2a549

Please sign in to comment.