fix: model value change for empty conversations

This commit is contained in:
Carl-Robert Linnupuu 2024-12-17 11:06:28 +00:00
parent 1c2a5496e4
commit 54fa78e7e6
3 changed files with 9 additions and 4 deletions

View file

@ -187,7 +187,7 @@ public final class ConversationService {
return Optional.empty();
}
private static String getModelForSelectedService(ServiceType serviceType) {
public String getModelForSelectedService(ServiceType serviceType) {
var application = ApplicationManager.getApplication();
return switch (serviceType) {
case CODEGPT -> application.getService(CodeGPTServiceSettings.class)

View file

@ -78,6 +78,7 @@ public class ChatToolWindowTabPanel implements Disposable {
this);
userInputPanel = new UserInputPanel(
project,
conversation,
totalTokensPanel,
this::handleSubmit,
this::handleCancel);

View file

@ -20,8 +20,8 @@ import com.intellij.util.ui.UIUtil
import ee.carlrobert.codegpt.CodeGPTBundle
import ee.carlrobert.codegpt.Icons
import ee.carlrobert.codegpt.actions.AttachImageAction
import ee.carlrobert.codegpt.conversations.Conversation
import ee.carlrobert.codegpt.conversations.ConversationService
import ee.carlrobert.codegpt.conversations.ConversationsState
import ee.carlrobert.codegpt.settings.GeneralSettings
import ee.carlrobert.codegpt.settings.service.ServiceType
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTServiceSettings
@ -41,6 +41,7 @@ import javax.swing.JPanel
class UserInputPanel(
private val project: Project,
private val conversation: Conversation,
private val totalTokensPanel: TotalTokensPanel,
private val onSubmit: (String, List<AppliedActionInlay>?) -> Unit,
private val onStop: () -> Unit
@ -158,9 +159,12 @@ class UserInputPanel(
{
imageActionSupported.set(isImageActionSupported())
// TODO: Implement a proper session management
if (service<ConversationsState>().state?.currentConversation?.messages?.isNotEmpty() == true) {
service<ConversationService>().startConversation()
val conversationService = service<ConversationService>()
if (conversation.messages.isNotEmpty()) {
conversationService.startConversation()
project.service<ChatToolWindowContentManager>().createNewTabPanel()
} else {
conversation.model = conversationService.getModelForSelectedService(it)
}
},
service<GeneralSettings>().state.selectedService