-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support to save the locally selected model so that new chats don´t require repeated model selection #2438
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also started looking into it because I want GPT-4 by default. TY!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! I would expect some kind of validation to go on though, did you look into this?
Removing @valerybugakov's approval not to merge this too eagerly since it could cause some nasty errors
@@ -205,7 +207,7 @@ export class ChatPanelsManager implements vscode.Disposable { | |||
this.options.contextProvider, | |||
this.options.platform | |||
), | |||
defaultModelID: defaultModel.model, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check if the saved model is actually a valid model name for the current configuration. Otherwise, if you switch from a dotcom account to enterprise or from pro to free, this may result in a wrong model identifier which, when used, might cause errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the right call. I was too eager to get into the release to start using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems strange that we write the last selected model ID in SimpleChatPanelProvider, but read it in ChatPanelsManager to pass into SimpleChatPanelProvider as a constructor param. Where possible, it's better to localize state management. Could we move the localStorage.get
call to an onReady
method in SimpleChatPanelProvider that runs when we receive the ready
message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the model selection to this function
cody/vscode/src/chat/chat-view/SimpleChatPanelProvider.ts
Lines 176 to 192 in 2b9310b
private selectModel(models: ChatModelProvider[]): string { | |
// Check for the last selected model | |
const lastSelectedModelID = localStorage.get('model') | |
if (lastSelectedModelID) { | |
// If the last selected model exists in the list of models then we return it | |
const model = models.find(m => m.model === lastSelectedModelID) | |
if (model) { | |
return lastSelectedModelID | |
} | |
} | |
// If the user has not selected a model before then we return the default model | |
const defaultModel = models.find(m => m.default) || models[0] | |
if (!defaultModel) { | |
throw new Error('No chat model found in server-provided config') | |
} | |
return defaultModel.model | |
} |
Also it takes into account that the model selected is valid for that user.
Could we move the localStorage.get call to an onReady method in SimpleChatPanelProvider that runs when we receive the ready message?
Not sure if I fully understand this but hopefully moving the model selection to a single place makes the code better than before.
vscode/src/chat/protocol.ts
Outdated
@@ -77,6 +77,7 @@ export type WebviewMessage = | |||
| { command: 'abort' } | |||
| { command: 'custom-prompt'; title: string; value?: CustomCommandType } | |||
| { command: 'reload' } | |||
| { command: 'saveModel'; model: string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chatModel
command already exists; why not use that one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to store and load from storage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arafatkatze Not sure I follow: If we already send a chatModel
message, why would we need another one to save that if the behavior is "always save the last one as default"? 🤔
@@ -139,7 +140,8 @@ export class ChatPanelsManager implements vscode.Disposable { | |||
// Get the view column of the current active chat panel so that we can open a new one on top of it | |||
const activePanelViewColumn = this.activePanelProvider?.webviewPanel?.viewColumn | |||
|
|||
const provider = this.createProvider() | |||
const savedModel = localStorage.get('model') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's give the key a more distinctive name, like "lastSelectedModelID"
@@ -205,7 +207,7 @@ export class ChatPanelsManager implements vscode.Disposable { | |||
this.options.contextProvider, | |||
this.options.platform | |||
), | |||
defaultModelID: defaultModel.model, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems strange that we write the last selected model ID in SimpleChatPanelProvider, but read it in ChatPanelsManager to pass into SimpleChatPanelProvider as a constructor param. Where possible, it's better to localize state management. Could we move the localStorage.get
call to an onReady
method in SimpleChatPanelProvider that runs when we receive the ready
message?
d403b80
to
2b9310b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks crisp now but I’m still unsure why we need a new notification for this instead of reusing. Do you mind elaborating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sharp! This looks good now. Let's add a change log entry though 🙇
I wonder why the test still fails 🤔 Did you create the PR in a fork of the cody repo? You can now create your branches on this repo instead, that should help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found one more nit I’m afraid. I don't feel great that we have a compute function but keep a copy of the value in the class properties. Can we avoid this somehow?
@@ -108,7 +109,7 @@ export class SimpleChatPanelProvider implements vscode.Disposable, IChatPanelPro | |||
private readonly contextStatusAggregator = new ContextStatusAggregator() | |||
private readonly editor: VSCodeEditor | |||
private readonly treeView: TreeViewProvider | |||
private readonly defaultModelID: string | |||
private readonly modelID: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this as a member now that we can compute it based on the localStorage? Asking because I just noticed that we have this.modelID
and this.chatmodel.modelID
and we only update one at some point. It's better to not keep duplicate references around I think.
@@ -336,6 +355,8 @@ export class SimpleChatPanelProvider implements vscode.Disposable, IChatPanelPro | |||
break | |||
case 'chatModel': | |||
this.chatModel.modelID = message.model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also update this.modelID
(and if yes, can we make it so that there is no duplication?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bliss
I was quite frustrated with the loading issue as well so I changed it. The video is pretty self explanatory. It saves the state even after you quit and load Cody again.
I have a strong suspicion that a lot of users will switch to GPT 4-Turbo once and then never switch back
Untitled.mov
Test plan
Just try it out and open close a few times