From 66a6ce662284f35b30dafcf7a264b9e271a8d798 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 | 36 +++++++++++++++++------------------ README.md | 25 +++++++++++------------- package.json | 9 +++++++-- src/extension.ts | 14 ++++++++------ 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b9c8a69..57eafef 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: @@ -41,16 +41,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: ${{ env.FETCH_DEPTH }} - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - - uses: robinraju/release-downloader@v1.8 + - uses: robinraju/release-downloader@v1.10 with: repository: "huggingface/llm-ls" tag: ${{ env.LLM_LS_VERSION }} @@ -71,7 +71,7 @@ jobs: run: npx vsce package -o "./llm-ls-${{ matrix.code-target }}.vsix" --target ${{ matrix.code-target }} - name: Upload artifacts - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: pkg-${{ matrix.target }} path: ./llm-ls-${{ matrix.code-target }}.vsix @@ -82,14 +82,14 @@ jobs: needs: ["package"] steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: ${{ env.FETCH_DEPTH }} - name: Install Nodejs - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV - run: 'echo "HEAD_SHA: $HEAD_SHA"' @@ -98,37 +98,37 @@ jobs: env: BRANCH: ${{ github.ref_name }} id: split - run: echo "::set-output name=tag::${BRANCH##*/}" + run: echo "tag=${BRANCH##*/}" >> $GITHUB_OUTPUT - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-aarch64-apple-darwin path: pkg - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-x86_64-apple-darwin path: pkg - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-x86_64-unknown-linux-gnu path: pkg - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-x86_64-unknown-linux-musl path: pkg - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-aarch64-unknown-linux-gnu path: pkg - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-arm-unknown-linux-gnueabihf path: pkg - - uses: actions/download-artifact@v1 + - uses: actions/download-artifact@v4 with: name: pkg-x86_64-pc-windows-msvc path: pkg - # - uses: actions/download-artifact@v1 + # - uses: actions/download-artifact@v4 # with: # name: pkg-aarch64-pc-windows-msvc # path: pkg 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..2de824b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "huggingface-vscode", "displayName": "llm-vscode", "description": "LLM powered development for VS Code", - "version": "0.2.0", + "version": "0.2.1", "publisher": "HuggingFace", "icon": "small_logo.png", "engines": { @@ -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." } } } @@ -260,4 +265,4 @@ "ovsx": "^0.8.3", "typescript": "^5.3.3" } -} \ No newline at end of file +} 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 +}