feat: add support for OpenAI-compatible embedding API

This commit is contained in:
Bo26fhmC5M
2025-02-27 23:27:50 +09:00
parent 929108def3
commit 1775591ef0
3 changed files with 34 additions and 9 deletions

View File

@@ -37,14 +37,14 @@ export class HypaProcesser{
name: "hypaVector"
})
this.vectors = []
const db = getDatabase()
if(model === 'auto'){
const db = getDatabase()
this.model = db.hypaModel || 'MiniLM'
}
else{
this.model = model
}
this.customEmbeddingUrl = customEmbeddingUrl
this.customEmbeddingUrl = customEmbeddingUrl || db.hypaCustomSettings.url
}
async embedDocuments(texts: string[]): Promise<VectorArray[]> {
@@ -77,12 +77,17 @@ export class HypaProcesser{
}
const {customEmbeddingUrl} = this
const replaceUrl = customEmbeddingUrl.endsWith('/embeddings')?customEmbeddingUrl:appendLastPath(customEmbeddingUrl,'embeddings')
gf = await globalFetch(replaceUrl.toString(), {
body:{
"input": input
},
})
const db = getDatabase()
const fetchArgs = {
...(db.hypaCustomSettings.key ? {headers: {"Authorization": "Bearer " + db.hypaCustomSettings.key}} : {}),
body: {
"input": input,
...(db.hypaCustomSettings.model ? {"model": db.hypaCustomSettings.model} : {})
}
};
gf = await globalFetch(replaceUrl.toString(), fetchArgs)
}
if(this.model === 'ada' || this.model === 'openai3small' || this.model === 'openai3large'){
const db = getDatabase()