From a8a67b876fc474071698db5f44f25ceda3b2c5f9 Mon Sep 17 00:00:00 2001 From: Luc Georges Date: Fri, 24 May 2024 16:18:49 +0200 Subject: [PATCH] feat: update llm-ls to `0.5.3` (#141) --- .github/workflows/release.yml | 6 +++--- README.md | 25 +++++++++++-------------- package.json | 5 +++++ src/extension.ts | 14 ++++++++------ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b9c8a69..d84e980 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,7 @@ on: env: FETCH_DEPTH: 0 # pull in the tags for the version string - LLM_LS_VERSION: 0.5.2 + LLM_LS_VERSION: 0.5.3 jobs: package: @@ -48,7 +48,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 - uses: robinraju/release-downloader@v1.8 with: @@ -89,7 +89,7 @@ jobs: - name: Install Nodejs uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 - run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV - run: 'echo "HEAD_SHA: $HEAD_SHA"' diff --git a/README.md b/README.md index fed528e..b720543 100644 --- a/README.md +++ b/README.md @@ -83,20 +83,8 @@ const data = { inputs, ...configuration.requestBody }; const model = configuration.modelId; let endpoint; switch(configuration.backend) { - case "huggingface": - let url; - if (configuration.url === null) { - url = "https://api-inference.huggingface.co"; - } else { - url = configuration.url; - } - endpoint = `${url}/models/${model}`; - break; - case "ollama": - case "openai": - case "tgi": - endpoint = configuration.url; - break; + // cf URL construction + let endpoint = build_url(configuration); } const res = await fetch(endpoint, { @@ -110,6 +98,15 @@ const json = await res.json() as { generated_text: string }; Note that the example above is a simplified version to explain what is happening under the hood. +#### URL construction + +The endpoint URL that is queried to fetch suggestions is build the following way: +- depending on the backend, it will try to append the correct path to the base URL located in the configuration (e.g. `{url}/v1/completions` for the `openai` backend) +- if no URL is set for the `huggingface` backend, it will automatically use the default URL + - it will error for other backends as there is no sensible default URL +- if you do set the **correct** path at the end of the URL it will not add it a second time as it checks if it is already present +- there is an option to disable this behavior: `llm.disableUrlPathCompletion` + ### Suggestion behavior You can tune the way the suggestions behave: diff --git a/package.json b/package.json index 50f974e..127d31d 100644 --- a/package.json +++ b/package.json @@ -219,6 +219,11 @@ "pattern": "**" }, "description": "Filter documents to enable suggestions for" + }, + "llm.disableUrlPathCompletion": { + "type": "boolean", + "default": false, + "description": "When setting `llm.url`, llm-ls will try to append the correct path to your URL if it doesn't end with such a path, e.g. for an OpenAI backend if it doesn't end with `/v1/completions`. Set this to `true` to disable this behavior." } } } diff --git a/src/extension.ts b/src/extension.ts index 63075cb..b266fec 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -26,10 +26,10 @@ let ctx: vscode.ExtensionContext; let loadingIndicator: vscode.StatusBarItem; function createLoadingIndicator(): vscode.StatusBarItem { - let li = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10) - li.text = "$(loading~spin) LLM" - li.tooltip = "Generating completions..." - return li + let li = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10); + li.text = "$(loading~spin) LLM"; + li.tooltip = "Generating completions..."; + return li; } export async function activate(context: vscode.ExtensionContext) { @@ -48,6 +48,7 @@ export async function activate(context: vscode.ExtensionContext) { if (command.startsWith("~/")) { command = homedir() + command.slice("~".length); } + const serverOptions: ServerOptions = { run: { command, transport: TransportKind.stdio, options: { @@ -81,7 +82,7 @@ export async function activate(context: vscode.ExtensionContext) { clientOptions ); - loadingIndicator = createLoadingIndicator() + loadingIndicator = createLoadingIndicator(); await client.start(); @@ -173,6 +174,7 @@ export async function activate(context: vscode.ExtensionContext) { tlsSkipVerifyInsecure: config.get("tlsSkipVerifyInsecure") as boolean, ide: "vscode", tokenizerConfig, + disableUrlPathCompletion: config.get("disableUrlPathCompletion") as boolean, }; try { loadingIndicator.show() @@ -345,4 +347,4 @@ async function delay(milliseconds: number, token: vscode.CancellationToken): Pro resolve(token.isCancellationRequested) }, milliseconds); }); -} \ No newline at end of file +}