- Fix the embeddings ranking - the wrong query was used

- Removed the free DeepSeek model from open router as not working now
- Setting endpoint_tools is now enought to start agent
- Agent View is now not hidden if the tools model is deselected
- Refactoring
This commit is contained in:
igardev 2025-10-08 16:50:53 +03:00
commit ddfdbbee53
14 changed files with 81 additions and 71 deletions

View file

@ -8,7 +8,7 @@ import {LlamaWebviewProvider} from './llama-webview-provider'
import { Utils } from './utils';
import { Env, LlmModel } from './types';
import { env } from 'process';
import { PERSISTENCE_KEYS, SETTING_NAME_FOR_LIST } from './constants';
import { PERSISTENCE_KEYS, SETTING_NAME_FOR_LIST, UiView } from './constants';
export class Architect {
private app: Application
@ -398,7 +398,8 @@ export class Architect {
'extension.showLlamaWebview',
async () => {
vscode.commands.executeCommand('llama-vscode.webview.focus');
this.app.llamaWebviewProvider.setView("agent")
if (this.app.isToolsModelSelected() || this.app.configuration.endpoint_tools) this.app.llamaWebviewProvider.setView(UiView.Agent)
else this.app.llamaWebviewProvider.setView(UiView.Environment)
const editor = vscode.window.activeTextEditor;
if (editor && editor.selection) {
let fileLongName = editor.document.fileName;

View file

@ -56,7 +56,7 @@ export class ChatContext {
if ((this.app.getEmbeddingsModel().endpoint && this.app.getEmbeddingsModel().endpoint?.trim() != "")
|| this.app.configuration.endpoint_embeddings.trim() != ""){
this.app.statusbar.showTextInfo(this.app.configuration.getUiText("Filtering chunks with embeddings..."))
topContextChunks = await this.cosineSimilarityRank(query, topChunksBm25, this.app.configuration.rag_max_embedding_filter_chunks);
topContextChunks = await this.cosineSimilarityRank(prompt, topChunksBm25, this.app.configuration.rag_max_embedding_filter_chunks);
} else {
vscode.window.showInformationMessage('No embeddings server. Filtering chunks with embeddings will be skipped.');
topContextChunks = topChunksBm25.slice(0, 5);

View file

@ -56,21 +56,19 @@ export class ChatWithAi {
: this.app.configuration.endpoint_tools ? this.app.configuration.endpoint_tools + "/" : "";
let chatModel = this.app.getChatModel();
if (!this.app.isChatModelSelected()) chatModel = this.app.getToolsModel();
if (!this.app.isChatModelSelected() && !this.app.configuration.endpoint_chat) chatModel = this.app.getToolsModel();
if (chatModel.endpoint) {
const chatEndpoint = Utils.trimTrailingSlash(chatModel.endpoint)
targetUrl = chatEndpoint ? chatEndpoint + "/" : "";
}
if (!targetUrl) {
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")
if (shouldSelectModel){
this.app.llamaWebviewProvider.showEnvView();
vscode.window.showInformationMessage("After the chat/tools model is loaded, try again opening Chat with AI.")
return;
} else {
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. ")
return
}
await Utils.suggestModelSelection(
"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.",
"After the chat/tools model is loaded, try again opening Chat with AI.",
"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. ",
this.app
);
return
}
if (withContext){

View file

@ -346,7 +346,7 @@ export class Configuration {
};
}
this.axiosRequestConfigTools = {};
this.axiosRequestConfigTools = {};
if (this.api_key_tools != undefined && this.api_key_tools.trim() != "") {
this.axiosRequestConfigTools = {
headers: {

View file

@ -6,6 +6,13 @@ export enum ModelType {
Tools = 'tools'
}
export enum UiView {
Agent = 'agent',
Environment = 'addenv',
Embeddings = 'embeddings',
AiRunner = 'airunner'
}
export enum Action {
Select = 'select',
AddLocal = 'addLocal',

View file

@ -14,22 +14,20 @@ export class Git {
let chatUrl = this.app.configuration.endpoint_chat
if (!chatUrl) chatUrl = this.app.configuration.endpoint_tools;
let chatModel = this.app.getChatModel();
if (!this.app.isChatModelSelected()) chatModel = this.app.getToolsModel();
if (!this.app.isChatModelSelected() && !this.app.configuration.endpoint_chat) chatModel = this.app.getToolsModel();
if (chatModel.endpoint) {
const chatEndpoint = Utils.trimTrailingSlash(chatModel.endpoint)
chatUrl = chatEndpoint ? chatEndpoint + "/" : "";
}
if (!chatUrl) {
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")
if (shouldSelectModel){
this.app.llamaWebviewProvider.showEnvView();
vscode.window.showInformationMessage("After the chat/tools model is loaded, try again generating commit message.")
return;
}
else {
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. ")
return;
}
await Utils.suggestModelSelection(
"Select a chat or tools model or an env with chat or tools model to generate a commit message.",
"After the chat/tools model is loaded, try again generating commit message.",
"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 server with chat model in setting endpoint_chat.",
this.app
);
return
}
const gitExtension = vscode.extensions.getExtension('vscode.git')?.exports;

View file

@ -82,13 +82,6 @@ export const PREDEFINED_LISTS = new Map<string, any>([
"aiModel": "",
"isKeyRequired": false
},
{
"name": "DeepSeek V3.1 (free) 163,800 context (OpenRouter)",
"localStartCommand": "",
"endpoint": "https://openrouter.ai/api",
"aiModel": "deepseek/deepseek-chat-v3.1:free",
"isKeyRequired": true
},
{
"name": "Z.AI: GLM 4.5 Air (free): GLM 4.5 Air - 128.000 context (OpenRouter)",
"endpoint": "https://openrouter.ai/api",

View file

@ -145,8 +145,8 @@ export class LlamaAgent {
this.logText += "***" + query.replace("\n", " \n") + "***" + "\n\n"; // Make sure markdown shows new lines correctly
if (!this.app.isToolsModelSelected()) {
vscode.window.showErrorMessage("Error: Tools model is not selected! Select tools model (or orchestra with tools model) if you want to to use Llama Agent.")
if (!this.app.isToolsModelSelected() && !this.app.configuration.endpoint_tools) {
vscode.window.showErrorMessage("Error: Tools model is not selected! Select tools model (or env with tools model) or set and endpoint in setting endpoint_tools if you want to to use Llama Agent View.")
this.app.llamaWebviewProvider.setState("AI is stopped")
return "Tools model is not selected"
}

View file

@ -743,27 +743,31 @@ export class LlamaServer {
private getChatModelProperties() {
let selectedModel: LlmModel = this.app.getChatModel();
if (!this.app.isChatModelSelected()) selectedModel = this.app.getToolsModel();
let model = this.app.configuration.ai_model;
if (selectedModel?.aiModel !== undefined && selectedModel.aiModel) model = selectedModel.aiModel;
if (!this.app.isChatModelSelected() && !this.app.configuration.endpoint_chat) selectedModel = this.app.getToolsModel();
let endpoint = this.app.configuration.endpoint_chat;
if (!endpoint) endpoint = this.app.configuration.endpoint_tools;
if (selectedModel?.endpoint !== undefined && selectedModel.endpoint) endpoint = selectedModel.endpoint;
let model = this.app.configuration.ai_model;
let requestConfig = this.app.configuration.axiosRequestConfigChat;
if (selectedModel?.isKeyRequired !== undefined && selectedModel.isKeyRequired) {
const apiKey = this.app.persistence.getApiKey(selectedModel.endpoint??"");
if (apiKey) {
requestConfig = {
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
};
if (!endpoint) {
endpoint = this.app.configuration.endpoint_tools;
requestConfig = this.app.configuration.axiosRequestConfigTools;
}
if (selectedModel?.endpoint !== undefined && selectedModel.endpoint) {
endpoint = selectedModel.endpoint;
if (selectedModel?.aiModel !== undefined && selectedModel.aiModel) model = selectedModel.aiModel;
if (selectedModel?.isKeyRequired !== undefined && selectedModel.isKeyRequired) {
const apiKey = this.app.persistence.getApiKey(selectedModel.endpoint??"");
if (apiKey) {
requestConfig = {
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
};
}
}
}
return { endpoint, model, requestConfig };
}

View file

@ -1,7 +1,7 @@
import {Application} from "./application";
import vscode, { QuickPickItem } from "vscode";
import { Utils } from "./utils";
import { ModelType, AGENT_NAME, UI_TEXT_KEYS } from "./constants";
import { ModelType, AGENT_NAME, UI_TEXT_KEYS, UiView } from "./constants";
export class Menu {
private app: Application
@ -228,7 +228,7 @@ export class Menu {
break;
case this.app.configuration.getUiText(UI_TEXT_KEYS.useAsLocalAIRunner):
vscode.commands.executeCommand('extension.showLlamaWebview');
this.app.llamaWebviewProvider.setView("airunner");
this.app.llamaWebviewProvider.setView(UiView.AiRunner);
break;
default:
isHandled = false;

View file

@ -408,14 +408,13 @@ export class ModelService {
targetUrl = toolsEndpoint ? toolsEndpoint + "/" : "";
}
if (!targetUrl) {
const shouldSelectEnv = await Utils.showUserChoiceDialog("Select a tools model or an env with tools model to use Llama Agent.", "Select");
if (shouldSelectEnv) {
// await this.app.menu.selectEnvFromList(this.app.configuration.envs_list.filter(item => item.tools != undefined && item.tools.name));
this.app.llamaWebviewProvider.showEnvView()
vscode.window.showInformationMessage("After the tools model is loaded, try again opening llama agent.");
} else {
vscode.window.showErrorMessage("No endpoint for the tools model. Select an env with tools model or enter the endpoint of a running llama.cpp server with tools model in setting endpoint_tools. ");
}
await Utils.suggestModelSelection(
"Select a tools model or an env with tools model to use Llama Agent.",
"After the tools model is loaded, try again opening llama agent.",
"No endpoint for the tools model. Select an env with tools model or enter the endpoint of a running llama.cpp server with tools model in setting endpoint_tools.",
this.app
);
return false;
}
else return true;

View file

@ -36,15 +36,13 @@ export class TextEditor {
chatUrl = chatEndpoint ? chatEndpoint + "/" : "";
}
if (!chatUrl) {
const shouldSelectModel = await Utils.showUserChoiceDialog("Select a chat or tools model or an env with chat or tools model to edit code with AI.","Select")
if (shouldSelectModel){
this.app.llamaWebviewProvider.showEnvView();
vscode.window.showInformationMessage("After the chat model is loaded, try again using Edit with AI.")
return;
} else {
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. ")
return
}
await Utils.suggestModelSelection(
"Select a chat or tools model or an env with chat or tools model to edit code with AI.",
"After the chat model is loaded, try again using Edit with AI.",
"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.",
this.app
);
return
}
if (editor.selection.isEmpty) {

View file

@ -7,6 +7,7 @@ import pm from 'picomatch'
import * as https from 'https';
import * as http from 'http';
import { URL } from 'url';
import { Application } from "./application";
interface BM25Stats {
@ -865,4 +866,14 @@ export class Utils {
}
return items;
}
static suggestModelSelection = async (choiceMsg: string, yesMsg: string, noMsg: string, app: Application) => {
const shouldSelectModel = await Utils.showUserChoiceDialog(choiceMsg, "Select");
if (shouldSelectModel) {
app.llamaWebviewProvider.showEnvView();
vscode.window.showInformationMessage(yesMsg);
} else {
vscode.window.showErrorMessage(noMsg);
}
}
}

View file

@ -321,7 +321,8 @@ const AgentView: React.FC<AgentViewProps> = ({
{/* Modern Header */}
<div className="header">
<div className="header-content">
{!currentToolsModel.includes('No model selected') && (
// TODO Remove this check once you are sure it works fine without it
{!currentToolsModel.includes('No model selected...') && (
<div className="header-left">
<button
onClick={handleClearText}
@ -365,7 +366,7 @@ const AgentView: React.FC<AgentViewProps> = ({
</div>
{/* Main Content */}
{!currentToolsModel.includes('No model selected') && (
{!currentToolsModel.includes('No model selected...') && (
<div className="content" style={{ flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0 }}>
{/* Chat Display Area */}
{/* Markdown Display Area */}