Skip to content

Commit c1edca0

Browse files
authored
Predefined lists and refactoring (#118)
- File menu.ts refactored - Predefined lists added for completion models, chat models, embeddings models, tools models and for envs - Bugfixes - If chat model is not selected, but a tools model is selected, it is used for generating commit messages, editing code with AI and in search_source tool
1 parent d452ea7 commit c1edca0

19 files changed

+2290
-985
lines changed

src/application.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {LlamaWebviewProvider} from "./llama-webview-provider"
1818
import * as vscode from "vscode"
1919
import path from "path";
2020
import { Persistence } from "./persistence";
21+
import { ModelService } from "./services/model-service";
22+
import { HfModelStrategy } from "./services/hf-model-strategy";
23+
import { LocalModelStrategy } from "./services/local-model-strategy";
24+
import { ExternalModelStrategy } from "./services/external-model-strategy";
2125

2226
export class Application {
2327
private static instance: Application;
@@ -39,6 +43,10 @@ export class Application {
3943
public llamaAgent: LlamaAgent
4044
public llamaWebviewProvider: LlamaWebviewProvider
4145
public persistence: Persistence
46+
public modelService: ModelService
47+
public hfModelStrategy: HfModelStrategy
48+
public localModelStrategy: LocalModelStrategy
49+
public externalModelStrategy: ExternalModelStrategy
4250

4351
private constructor(context: vscode.ExtensionContext) {
4452
this.configuration = new Configuration()
@@ -59,6 +67,11 @@ export class Application {
5967
this.llamaAgent = new LlamaAgent(this)
6068
this.llamaWebviewProvider = new LlamaWebviewProvider(context.extensionUri, this, context)
6169
this.persistence = new Persistence(this, context)
70+
// strategies should be initialized before modelService constructor as they are needed there.
71+
this.hfModelStrategy = new HfModelStrategy(this)
72+
this.localModelStrategy = new LocalModelStrategy(this)
73+
this.externalModelStrategy = new ExternalModelStrategy(this)
74+
this.modelService = new ModelService(this)
6275
}
6376

6477
public static getInstance(context: vscode.ExtensionContext): Application {

src/architect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {LlamaWebviewProvider} from './llama-webview-provider'
88
import { Utils } from './utils';
99
import { Env, LlmModel } from './types';
1010
import { env } from 'process';
11+
import { SETTING_NAME_FOR_LIST } from './constants';
1112

1213
export class Architect {
1314
private app: Application
@@ -485,9 +486,9 @@ export class Architect {
485486
Utils.removeFaOptionFromModels(toolsModels);
486487
Utils.removeFaOptionFromEnvs(envs);
487488

488-
this.app.configuration.updateConfigValue("chat_models_list", chatModels);
489-
this.app.configuration.updateConfigValue("tools_models_list", toolsModels);
490-
this.app.configuration.updateConfigValue("envs_list", envs);
489+
this.app.configuration.updateConfigValue(SETTING_NAME_FOR_LIST.CHAT_MODELS, chatModels);
490+
this.app.configuration.updateConfigValue(SETTING_NAME_FOR_LIST.TOOLS_MODELS, toolsModels);
491+
this.app.configuration.updateConfigValue(SETTING_NAME_FOR_LIST.ENVS, envs);
491492
}
492493
} else {
493494
let questionStopAskingLlamaCppUpgrade = "Do you prefer to stop getting a suggestion to upgrade llama.cpp?"

src/chat-with-ai.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,24 @@ export class ChatWithAi {
5151
let aiPanel = this.askAiPanel
5252
let extraCont = aiInitialExtraContext ? aiInitialExtraContext + "\n\n" : "";
5353
let query: string|undefined = undefined
54-
let targetUrl = this.app.configuration.endpoint_chat ? this.app.configuration.endpoint_chat + "/" : "";
54+
let targetUrl = this.app.configuration.endpoint_chat
55+
? this.app.configuration.endpoint_chat + "/"
56+
: this.app.configuration.endpoint_tools ? this.app.configuration.endpoint_tools + "/" : "";
5557

56-
let chatModel = this.app.menu.getChatModel();
58+
let chatModel = this.app.menu.getChatModel();
59+
if (!this.app.menu.isChatModelSelected()) chatModel = this.app.menu.getToolsModel();
5760
if (chatModel.endpoint) {
5861
const chatEndpoint = Utils.trimTrailingSlash(chatModel.endpoint)
5962
targetUrl = chatEndpoint ? chatEndpoint + "/" : "";
6063
}
6164
if (!targetUrl) {
62-
const shouldSelectModel = await Utils.showUserChoiceDialog("Select a chat model or an env with chat model to chat with AI.","Select")
65+
const shouldSelectModel = await Utils.showUserChoiceDialog("Select a chat or tools model run by llama-server or an env with chat or tools model run on llama-server to chat with AI.","Select")
6366
if (shouldSelectModel){
64-
// await this.app.menu.selectEnvFromList(this.app.configuration.envs_list.filter(item => item.chat != undefined && item.chat.name)) // .selectStartModel(chatTypeDetails);
6567
this.app.menu.showEnvView();
66-
vscode.window.showInformationMessage("After the chat model is loaded, try again opening Chat with AI.")
68+
vscode.window.showInformationMessage("After the chat/tools model is loaded, try again opening Chat with AI.")
6769
return;
6870
} else {
69-
vscode.window.showErrorMessage("No endpoint for the chat model. Select an env with chat model or enter the endpoint of a running llama.cpp server with chat model in setting endpoint_chat. ")
71+
vscode.window.showErrorMessage("No endpoint for the chat or tools model. Select a chat or tools model run on llama-server or an env with chat or tools model or enter the endpoint of a running llama.cpp server with chat model in setting endpoint_chat. ")
7072
return
7173
}
7274
}

src/constants.ts

Lines changed: 168 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,172 @@ export enum AGENT_NAME {
8484
}
8585

8686
export const UI_TEXT_KEYS = {
87-
// Note: These are keys for getUiText calls; actual strings not extracted here to avoid touching getUiText parameters.
88-
// Example: selectEnv: 'Select/start env...',
89-
// Map all relevant keys as needed in future phases.
87+
// Menu separators and sections
88+
actions: "Actions",
89+
entities: "Entities",
90+
maintenance: "Maintenance",
91+
help: "Help",
92+
93+
// Env related
94+
selectStartEnv: "Select/start env...",
95+
envSelectDescription: "Stops the currently running models and starts the selected env - (a predefined group of models for completion, chat, embeddings and tools).",
96+
deselectStopEnv: "Deselect/stop env and models",
97+
deselectStopEnvDescription: "Deselects/stops env, completion, chat, embeddings and tools models",
98+
showSelectedEnv: "Show selected env",
99+
showSelectedEnvDescription: "Shows details about the selected env",
100+
addEnv: "Add env...",
101+
addEnvDescription: "Opens a panel for adding an env.",
102+
viewEnvDetails: "View env details...",
103+
deleteEnv: "Delete env...",
104+
exportEnv: "Export env...",
105+
importEnv: "Import env...",
106+
downloadUploadEnvsOnline: "Download/upload envs online",
107+
108+
// Models lists
109+
envs: "Envs...",
110+
completionModels: "Completion models...",
111+
chatModels: "Chat models...",
112+
embeddingsModels: "Embeddings models...",
113+
toolsModels: "Tools models...",
114+
115+
// Common toggles
116+
disable: "Disable",
117+
enable: "Enable",
118+
allCompletions: "All Completions",
119+
turnOffCompletionsGlobally: "Turn off completions globally",
120+
turnOnCompletionsGlobally: "Turn on completions globally",
121+
completionsFor: "Completions for",
122+
currently: "Currently",
123+
enabled: "enabled",
124+
disabled: "disabled",
125+
rag: "RAG",
126+
turnOffRAG: "Turn off RAG related features like Chat with AI with project context",
127+
turnOnRAG: "Turn on RAG related features like Chat with AI with project context",
128+
129+
// UI actions
130+
showLlamaAgent: "Show Llama Agent",
131+
showLlamaAgentDescription: "Shows Llama Agent panel",
132+
chatWithAI: "Chat with AI",
133+
chatWithAIDescription: "Opens a chat with AI window inside VS Code using the selected chat model (or setting endpoint_chat)",
134+
chatWithAIWithProjectContext: "Chat with AI with project context",
135+
showSelectedModels: "Show selected models",
136+
showSelectedModelsDescription: "Displays a list of currently selected models",
137+
useAsLocalAIRunner: "Use as local AI runner",
138+
localAIRunnerDescription: "Download models automatically from Huggingface and chat with them (as LM Studio, Ollama, etc.)",
139+
editSettings: "Edit Settings...",
140+
apiKeys: "API keys...",
141+
apiKeysDescription: "Edit or remove API keys. New API keys are added on first use of an endpoint.",
142+
agents: "Agents...",
143+
agentCommands: "Agent commands...",
144+
chats: "Chats...",
145+
146+
// Help and maintenance
147+
howToUseLlamaVscode: "How to use llama-vscode",
148+
chatWithAIAboutLlamaVscode: "Chat with AI about llama-vscode",
149+
chatWithAIAboutLlamaVscodeDescription: "Selects llama-vscode help agent and opens llama agent view for asking ai about llama-vscode",
150+
howToDeleteModels: "How to delete models",
151+
howToDeleteModelsDescription: "Explains how to delete the downloaded models",
152+
viewDocumentation: "View Documentation...",
153+
startTrainingCompletionModel: "Start training completion model",
154+
launchTrainingCompletionDescription: "Runs the command from property launch_training_completion",
155+
startTrainingChatModel: "Start training chat model",
156+
launchTrainingChatDescription: "Runs the command from property launch_training_chat",
157+
stopTraining: "Stop training",
158+
stopTrainingDescription: "Stops training if it was started from llama.vscode menu",
159+
160+
// API keys
161+
addAPIKey: "Add API key...",
162+
editDeleteAPIKey: "Edit/delete API key...",
163+
164+
// Agent actions
165+
selectStartAgent: "Select/start agent...",
166+
deselectStopAgent: "Deselect/stop agent...",
167+
addAgent: "Add agent...",
168+
viewAgentDetails: "View agent details...",
169+
deleteAgent: "Delete agent...",
170+
exportAgent: "Export agent...",
171+
importAgent: "Import agent...",
172+
173+
// Agent command actions
174+
addAgentCommand: "Add agent command...",
175+
viewAgentCommandDetails: "View agent command details...",
176+
deleteAgentCommand: "Delete agent command...",
177+
exportAgentCommand: "Export agent command...",
178+
importAgentCommand: "Import agent command...",
179+
180+
// Chat actions
181+
selectStartChat: "Select/start chat...",
182+
deleteChat: "Delete chat...",
183+
exportChat: "Export chat...",
184+
importChat: "Import chat...",
185+
186+
// Model actions for Completion
187+
selectStartCompletionModel: "Select/start completion model...",
188+
deselectStopCompletionModel: "Deselect/stop completion model",
189+
addLocalCompletionModel: "Add local completion model...",
190+
addExternalCompletionModel: "Add external completion model...",
191+
addCompletionModelFromHuggingface: "Add completion model from huggingface...",
192+
viewCompletionModelDetails: "View completion model details...",
193+
deleteCompletionModel: "Delete completion model...",
194+
exportCompletionModel: "Export completion model...",
195+
importCompletionModel: "Import completion model...",
196+
197+
// Model actions for Chat
198+
selectStartChatModel: "Select/start chat model...",
199+
deselectStopChatModel: "Deselect/stop chat model",
200+
addLocalChatModel: "Add local chat model...",
201+
addExternalChatModel: "Add external chat model...",
202+
addChatModelFromHuggingface: "Add chat model from huggingface...",
203+
viewChatModelDetails: "View chat model details...",
204+
deleteChatModel: "Delete chat model...",
205+
exportChatModel: "Export chat model...",
206+
importChatModel: "Import chat model...",
207+
208+
// Model actions for Embeddings
209+
selectStartEmbeddingsModel: "Select/start embeddings model...",
210+
deselectStopEmbeddingsModel: "Deselect/stop embeddings model",
211+
addLocalEmbeddingsModel: "Add local embeddings model...",
212+
addExternalEmbeddingsModel: "Add external embeddings model...",
213+
addEmbeddingsModelFromHuggingface: "Add embeddings model from huggingface...",
214+
viewEmbeddingsModelDetails: "View embeddings model details...",
215+
deleteEmbeddingsModel: "Delete embeddings model...",
216+
exportEmbeddingsModel: "Export embeddings model...",
217+
importEmbeddingsModel: "Import embeddings model...",
218+
219+
// Model actions for Tools
220+
selectStartToolsModel: "Select/start tools model...",
221+
deselectStopToolsModel: "Deselect/stop tools model",
222+
addLocalToolsModel: "Add local tools model...",
223+
addExternalToolsModel: "Add external tools model...",
224+
addToolsModelFromHuggingface: "Add tools model from huggingface...",
225+
viewToolsModelDetails: "View tools model details...",
226+
deleteToolsModel: "Delete tools model...",
227+
exportToolsModel: "Export tools model...",
228+
importToolsModel: "Import tools model...",
229+
} as const;
230+
231+
export const PERSISTENCE_KEYS = {
232+
SELECTED_CHAT: 'selectedChat' as const,
233+
SELECTED_AGENT: 'selectedAgent' as const,
234+
SELECTED_ENV: 'selectedEnv' as const,
235+
} as const;
236+
237+
export const SETTING_NAME_FOR_LIST = {
238+
COMPLETION_MODELS: MODEL_TYPE_CONFIG[ModelType.Completion].settingName,
239+
CHAT_MODELS: MODEL_TYPE_CONFIG[ModelType.Chat].settingName,
240+
EMBEDDINGS_MODELS: MODEL_TYPE_CONFIG[ModelType.Embeddings].settingName,
241+
TOOLS_MODELS: MODEL_TYPE_CONFIG[ModelType.Tools].settingName,
242+
ENVS: 'envs_list' as const,
243+
AGENTS: 'agents_list' as const,
244+
AGENT_COMMANDS: 'agent_commands' as const
245+
} as const;
246+
247+
export const PREDEFINED_LISTS_KEYS = {
248+
COMPLETIONS: ModelType.Completion as const,
249+
CHATS: ModelType.Chat as const,
250+
EMBEDDINGS: ModelType.Embeddings as const,
251+
TOOLS: ModelType.Tools as const,
252+
ENVS: SETTING_NAME_FOR_LIST.ENVS,
253+
AGENTS: SETTING_NAME_FOR_LIST.AGENTS,
254+
AGENT_COMMANDS: SETTING_NAME_FOR_LIST.AGENT_COMMANDS,
90255
} as const;

src/git.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ export class Git {
1212

1313
generateCommitMessage = async (): Promise<void> => {
1414
let chatUrl = this.app.configuration.endpoint_chat
15+
if (!chatUrl) chatUrl = this.app.configuration.endpoint_tools;
1516
let chatModel = this.app.menu.getChatModel();
17+
if (!this.app.menu.isChatModelSelected()) chatModel = this.app.menu.getToolsModel();
1618
if (chatModel.endpoint) {
1719
const chatEndpoint = Utils.trimTrailingSlash(chatModel.endpoint)
1820
chatUrl = chatEndpoint ? chatEndpoint + "/" : "";
1921
}
2022
if (!chatUrl) {
21-
const shouldSelectModel = await Utils.showUserChoiceDialog("Select a chat model or an env with chat model to generate a commit message.","Select")
23+
const shouldSelectModel = await Utils.showUserChoiceDialog("Select a chat or tools model or an env with chat or tools model to generate a commit message.","Select")
2224
if (shouldSelectModel){
2325
this.app.menu.showEnvView();
24-
vscode.window.showInformationMessage("After the chat model is loaded, try again generating commit message.")
26+
vscode.window.showInformationMessage("After the chat/tools model is loaded, try again generating commit message.")
2527
return;
2628
}
2729
else {
28-
vscode.window.showErrorMessage("No endpoint for the chat model. Select a chat model or an env with chat model or enter the endpoint of a running llama.cpp server with chat model in setting endpoint_chat. ")
30+
vscode.window.showErrorMessage("No endpoint for the chat model. Select a chat or tools model or an env with chat or tools model or enter the endpoint of a running llama.cpp server with chat model in setting endpoint_chat. ")
2931
return;
3032
}
3133
}

0 commit comments

Comments
 (0)