fix: execute chat completion request in background thread

This commit is contained in:
Carl-Robert Linnupuu 2024-12-17 10:43:33 +00:00
parent 59fe48f00f
commit 1c2a5496e4

View file

@ -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;
@ -16,15 +17,17 @@ public class 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() {