mirror of
https://github.com/ggml-org/llama.vscode.git
synced 2026-05-07 01:15:23 +00:00
Compare commits
2 commits
master
...
improve_ag
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddfdbbee53 | ||
|
|
0ff6aa39ae |
16 changed files with 128 additions and 83 deletions
|
|
@ -1,15 +1,50 @@
|
|||
# Exclude VCS and workspace config
|
||||
.git/**
|
||||
.github/**
|
||||
.vscode/**
|
||||
.idea/**
|
||||
.vscode-test/**
|
||||
|
||||
# Do not ship TypeScript sources or source maps
|
||||
src/**
|
||||
.gitignore
|
||||
.yarnrc
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/eslint.config.mjs
|
||||
**/*.map
|
||||
**/*.ts
|
||||
**/.vscode-test.*
|
||||
ui/node_modules/**
|
||||
ui/src/**
|
||||
**/test
|
||||
**/*.tsx
|
||||
**/*.test.*
|
||||
**/*.spec.*
|
||||
|
||||
# VS Code testing/coverage artifacts
|
||||
.vscode-test/**
|
||||
coverage/**
|
||||
|
||||
# Build artifacts and local packages
|
||||
*.vsix
|
||||
.vsix/**
|
||||
|
||||
# UI workspace: keep only built assets
|
||||
ui/**
|
||||
!ui/dist/**
|
||||
|
||||
# Keep built extension output and resources
|
||||
!dist/**
|
||||
!resources/**
|
||||
!llama.png
|
||||
!README.md
|
||||
!LICENSE
|
||||
!package.json
|
||||
|
||||
# Node modules: keep runtime code but drop heavy non-runtime extras
|
||||
node_modules/**/test/**
|
||||
node_modules/**/tests/**
|
||||
node_modules/**/__tests__/**
|
||||
node_modules/**/benchmark/**
|
||||
node_modules/**/benchmarks/**
|
||||
node_modules/**/example/**
|
||||
node_modules/**/examples/**
|
||||
node_modules/**/doc/**
|
||||
node_modules/**/docs/**
|
||||
node_modules/**/man/**
|
||||
node_modules/**/.github/**
|
||||
node_modules/**/.vscode/**
|
||||
|
||||
# Logs and misc
|
||||
npm-debug.log*
|
||||
yarn-error.log*
|
||||
|
|
|
|||
|
|
@ -1946,7 +1946,6 @@
|
|||
"format": "prettier --write --ignore-path .gitignore '**/*'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
"axios": "^1.1.2",
|
||||
"globby": "^14.1.0",
|
||||
"ignore": "^7.0.4",
|
||||
|
|
@ -1956,6 +1955,7 @@
|
|||
"simple-git": "^3.28.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
"@babel/types": "^7.28.4",
|
||||
"@types/micromatch": "^4.0.9",
|
||||
"@types/mocha": "^10.0.10",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
20
src/git.ts
20
src/git.ts
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
11
src/utils.ts
11
src/utils.ts
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue