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

@@ -594,6 +594,7 @@
<OptionInput value="openai3small">OpenAI text-embedding-3-small</OptionInput>
<OptionInput value="openai3large">OpenAI text-embedding-3-large</OptionInput>
<OptionInput value="ada">OpenAI Ada</OptionInput>
<OptionInput value="custom">Custom (OpenAI-compatible)</OptionInput>
</SelectInput>
{#if DBState.db.hypaModel === 'openai3small' || DBState.db.hypaModel === 'openai3large' || DBState.db.hypaModel === 'ada'}
@@ -601,5 +602,14 @@
<TextInput size="sm" marginBottom bind:value={DBState.db.supaMemoryKey}/>
{/if}
{#if DBState.db.hypaModel === 'custom'}
<span class="text-textcolor">URL</span>
<TextInput size="sm" marginBottom bind:value={DBState.db.hypaCustomSettings.url}/>
<span class="text-textcolor">Key/Password</span>
<TextInput size="sm" marginBottom bind:value={DBState.db.hypaCustomSettings.key}/>
<span class="text-textcolor">Request Model</span>
<TextInput size="sm" marginBottom bind:value={DBState.db.hypaCustomSettings.model}/>
{/if}
</Arcodion>
{/if}

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[]> {
@@ -78,11 +78,16 @@ 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()

View File

@@ -489,6 +489,11 @@ export function setDatabase(data:Database){
data.antiClaudeOverload = false
data.antiServerOverloads = true
}
data.hypaCustomSettings = {
url: data.hypaCustomSettings?.url ?? "",
key: data.hypaCustomSettings?.key ?? "",
model: data.hypaCustomSettings?.model ?? "",
}
changeLanguage(data.language)
setDatabaseLite(data)
}
@@ -902,7 +907,7 @@ export interface Database{
preserveOrphanedMemory: boolean
processRegexScript: boolean
doNotSummarizeUserMessage: boolean
},
}
OaiCompAPIKeys: {[key:string]:string}
inlayErrorResponse:boolean
reasoningEffort:number
@@ -913,6 +918,11 @@ export interface Database{
useExperimentalGoogleTranslator:boolean
thinkingTokens: number
antiServerOverloads: boolean
hypaCustomSettings: {
url: string,
key: string,
model: string,
}
}
interface SeparateParameters{