feat: add support for OpenAI-compatible embedding API (#776)
# PR Checklist - [x] Have you checked if it works normally in all models? *Ignore this if it doesn't use models.* - [x] Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions? - [ ] Have you added type definitions? # Preview  # Description This PR introduces support for OpenAI-compatible embedding API
This commit is contained in:
@@ -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}
|
||||
@@ -37,14 +37,14 @@ export class HypaProcesser{
|
||||
name: "hypaVector"
|
||||
})
|
||||
this.vectors = []
|
||||
if(model === 'auto'){
|
||||
const db = getDatabase()
|
||||
if(model === 'auto'){
|
||||
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(), {
|
||||
const db = getDatabase()
|
||||
const fetchArgs = {
|
||||
...(db.hypaCustomSettings.key ? {headers: {"Authorization": "Bearer " + db.hypaCustomSettings.key}} : {}),
|
||||
body: {
|
||||
"input": input
|
||||
},
|
||||
})
|
||||
"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()
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user