Skip to content

Commit

Permalink
development > main (#352)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update src/extension/embeddings.ts

Co-authored-by: rj <[email protected]>

* Update src/extension/embeddings.ts

Co-authored-by: rj <[email protected]>

* Update src/extension/embeddings.ts

Co-authored-by: rj <[email protected]>

---------

Co-authored-by: rj <[email protected]>

* format, replace any usage

* 3.17.30

* update readme

---------

Co-authored-by: vkx86 <[email protected]>
  • Loading branch information
rjmacarthy and vkx86 authored Oct 18, 2024
1 parent c9fac4b commit 3da6bee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

19 changes: 15 additions & 4 deletions src/extension/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -80,7 +82,7 @@ export class EmbeddingDatabase {
body: requestBody,
options: requestOptions,
onData: (response) => {
resolve((response as Embedding).embeddings)
resolve(this.getEmbeddingFromResponse(provider, response))
}
})
})
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -242,4 +242,15 @@ export class EmbeddingDatabase {
private getIsDuplicateItem(item: string, collection: string[]): boolean {
return collection.includes(item.trim().toLowerCase())
}

private getEmbeddingFromResponse<T>(
provider: TwinnyProvider,
response: T
): number[] {
if (provider.provider === apiProviders.LMStudio) {
return (response as LMStudioEmbedding).data?.[0].embedding
}

return (response as Embedding).embeddings
}
}

0 comments on commit 3da6bee

Please sign in to comment.