From 3da6bee78414463b1973bbcb40dd8b347aa5d817 Mon Sep 17 00:00:00 2001 From: rj Date: Fri, 18 Oct 2024 12:56:19 +0100 Subject: [PATCH] development > main (#352) * LM Studio embedding (#348) * my local fixes * cusomizing my local providers * const ext name change * local providers adj. * added LM Studio embeddings response treatment * method renaming * revert my local changes * import fix * Update src/extension/embeddings.ts Co-authored-by: rj * Update src/extension/embeddings.ts Co-authored-by: rj * Update src/extension/embeddings.ts Co-authored-by: rj * Update src/extension/embeddings.ts Co-authored-by: rj --------- Co-authored-by: rj * format, replace any usage * 3.17.30 * update readme --------- Co-authored-by: vkx86 --- package-lock.json | 4 ++-- package.json | 2 +- src/common/types.ts | 19 +++++++++++++++++++ src/extension/embeddings.ts | 19 +++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index eb81382..66ea818 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "twinny", - "version": "3.17.29", + "version": "3.17.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "twinny", - "version": "3.17.29", + "version": "3.17.30", "cpu": [ "x64", "arm64" diff --git a/package.json b/package.json index 6c6f596..4a68dfe 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "twinny", "displayName": "twinny - AI Code Completion and Chat", "description": "Locally hosted AI code completion plugin for vscode", - "version": "3.17.29", + "version": "3.17.30", "icon": "assets/icon.png", "keywords": [ "code-inference", diff --git a/src/common/types.ts b/src/common/types.ts index b26eb83..338ade9 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -314,3 +314,22 @@ export interface GitHubPr { title: string html_url: string } + +export interface LMSEmbeddingItem { + object: string + embedding: number[] + index: number +} + +export interface LMSEmbeddingUsage { + prompt_tokens: number + total_tokens: number +} + +export interface LMStudioEmbedding { + object: string + data: LMSEmbeddingItem[] + model: string + usage: LMSEmbeddingUsage +} + diff --git a/src/extension/embeddings.ts b/src/extension/embeddings.ts index c1cec45..6d86c97 100644 --- a/src/extension/embeddings.ts +++ b/src/extension/embeddings.ts @@ -8,8 +8,10 @@ import * as vscode from "vscode" import { ACTIVE_EMBEDDINGS_PROVIDER_STORAGE_KEY } from "../common/constants" import { logger } from "../common/logger" import { + apiProviders, EmbeddedDocument, Embedding, + LMStudioEmbedding, RequestOptionsOllama, StreamRequestOptions as RequestOptions } from "../common/types" @@ -80,7 +82,7 @@ export class EmbeddingDatabase { body: requestBody, options: requestOptions, onData: (response) => { - resolve((response as Embedding).embeddings) + resolve(this.getEmbeddingFromResponse(provider, response)) } }) }) @@ -110,9 +112,7 @@ export class EmbeddingDatabase { minimatch(relativePath, pattern, { dot: true, matchBase: true }) && !pattern.startsWith("!") if (isIgnored) { - logger.log( - `Ignoring ${relativePath} due to pattern: ${pattern}` - ) + logger.log(`Ignoring ${relativePath} due to pattern: ${pattern}`) } return isIgnored }) @@ -242,4 +242,15 @@ export class EmbeddingDatabase { private getIsDuplicateItem(item: string, collection: string[]): boolean { return collection.includes(item.trim().toLowerCase()) } + + private getEmbeddingFromResponse( + provider: TwinnyProvider, + response: T + ): number[] { + if (provider.provider === apiProviders.LMStudio) { + return (response as LMStudioEmbedding).data?.[0].embedding + } + + return (response as Embedding).embeddings + } }