fix: remove hacky retrieval settings and engine routing
This commit is contained in:
parent
3b48cb5816
commit
693796a68d
@ -1,38 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { SettingComponentProps, getJanDataFolderPath } from '@janhq/core/node'
|
||||
|
||||
// Sec: Do not send engine settings over requests
|
||||
// Read it manually instead
|
||||
export const readEmbeddingEngine = (engineName: string) => {
|
||||
if (engineName !== 'openai' && engineName !== 'groq') {
|
||||
const engineSettings = fs.readFileSync(
|
||||
path.join(getJanDataFolderPath(), 'engines', `${engineName}.json`),
|
||||
'utf-8'
|
||||
)
|
||||
return JSON.parse(engineSettings)
|
||||
} else {
|
||||
const settingDirectoryPath = path.join(
|
||||
getJanDataFolderPath(),
|
||||
'settings',
|
||||
'@janhq',
|
||||
// TODO: James - To be removed
|
||||
engineName === 'openai'
|
||||
? 'inference-openai-extension'
|
||||
: 'inference-groq-extension',
|
||||
'settings.json'
|
||||
)
|
||||
|
||||
const content = fs.readFileSync(settingDirectoryPath, 'utf-8')
|
||||
const settings: SettingComponentProps[] = JSON.parse(content)
|
||||
const apiKeyId = engineName === 'openai' ? 'openai-api-key' : 'groq-api-key'
|
||||
const keySetting = settings.find((setting) => setting.key === apiKeyId)
|
||||
|
||||
let apiKey = keySetting?.controllerProps.value
|
||||
if (typeof apiKey !== 'string') apiKey = ''
|
||||
|
||||
return {
|
||||
api_key: apiKey,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,6 @@ import { MemoryVectorStore } from 'langchain/vectorstores/memory'
|
||||
import { HNSWLib } from 'langchain/vectorstores/hnswlib'
|
||||
|
||||
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'
|
||||
import { readEmbeddingEngine } from './engine'
|
||||
|
||||
export class Retrieval {
|
||||
public chunkSize: number = 100
|
||||
@ -28,8 +27,8 @@ export class Retrieval {
|
||||
// declare time-weighted retriever and storage
|
||||
this.timeWeightedVectorStore = new MemoryVectorStore(
|
||||
new OpenAIEmbeddings(
|
||||
{ openAIApiKey: 'nitro-embedding' },
|
||||
{ basePath: 'http://127.0.0.1:3928/v1' }
|
||||
{ openAIApiKey: 'cortex-embedding' },
|
||||
{ basePath: 'http://127.0.0.1:39291/v1' }
|
||||
)
|
||||
)
|
||||
this.timeWeightedretriever = new TimeWeightedVectorStoreRetriever({
|
||||
@ -49,21 +48,11 @@ export class Retrieval {
|
||||
}
|
||||
|
||||
public updateEmbeddingEngine(model: string, engine: string): void {
|
||||
// Engine settings are not compatible with the current embedding model params
|
||||
// Switch case manually for now
|
||||
if (engine === 'nitro') {
|
||||
this.embeddingModel = new OpenAIEmbeddings(
|
||||
{ openAIApiKey: 'nitro-embedding', model },
|
||||
{ openAIApiKey: 'cortex-embedding', model },
|
||||
// TODO: Raw settings
|
||||
{ basePath: 'http://127.0.0.1:3928/v1' },
|
||||
{ basePath: 'http://127.0.0.1:39291/v1' }
|
||||
)
|
||||
} else {
|
||||
// Fallback to OpenAI Settings
|
||||
const settings = readEmbeddingEngine(engine)
|
||||
this.embeddingModel = new OpenAIEmbeddings({
|
||||
openAIApiKey: settings.api_key,
|
||||
})
|
||||
}
|
||||
|
||||
// update time-weighted embedding model
|
||||
this.timeWeightedVectorStore.embeddings = this.embeddingModel
|
||||
|
||||
@ -249,19 +249,11 @@ const ChatInput = () => {
|
||||
<li
|
||||
className={twMerge(
|
||||
'text-[hsla(var(--text-secondary)] hover:bg-secondary flex w-full cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-[hsla(var(--dropdown-menu-hover-bg))]',
|
||||
activeThread?.assistants[0].model.settings?.text_model ===
|
||||
false
|
||||
? 'cursor-not-allowed opacity-50'
|
||||
: 'cursor-pointer'
|
||||
'cursor-pointer'
|
||||
)}
|
||||
onClick={() => {
|
||||
if (
|
||||
activeThread?.assistants[0].model.settings
|
||||
?.text_model !== false
|
||||
) {
|
||||
fileInputRef.current?.click()
|
||||
setShowAttacmentMenus(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<FileTextIcon size={16} />
|
||||
@ -270,22 +262,11 @@ const ChatInput = () => {
|
||||
}
|
||||
content={
|
||||
(!activeThread?.assistants[0].tools ||
|
||||
!activeThread?.assistants[0].tools[0]?.enabled ||
|
||||
activeThread?.assistants[0].model.settings?.text_model ===
|
||||
false) && (
|
||||
<>
|
||||
{activeThread?.assistants[0].model.settings
|
||||
?.text_model === false ? (
|
||||
<span>
|
||||
This model does not support text-based retrieval.
|
||||
</span>
|
||||
) : (
|
||||
!activeThread?.assistants[0].tools[0]?.enabled) && (
|
||||
<span>
|
||||
Turn on Retrieval in Assistant Settings to use this
|
||||
feature.
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user