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 { HNSWLib } from 'langchain/vectorstores/hnswlib'
|
||||||
|
|
||||||
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'
|
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'
|
||||||
import { readEmbeddingEngine } from './engine'
|
|
||||||
|
|
||||||
export class Retrieval {
|
export class Retrieval {
|
||||||
public chunkSize: number = 100
|
public chunkSize: number = 100
|
||||||
@ -28,8 +27,8 @@ export class Retrieval {
|
|||||||
// declare time-weighted retriever and storage
|
// declare time-weighted retriever and storage
|
||||||
this.timeWeightedVectorStore = new MemoryVectorStore(
|
this.timeWeightedVectorStore = new MemoryVectorStore(
|
||||||
new OpenAIEmbeddings(
|
new OpenAIEmbeddings(
|
||||||
{ openAIApiKey: 'nitro-embedding' },
|
{ openAIApiKey: 'cortex-embedding' },
|
||||||
{ basePath: 'http://127.0.0.1:3928/v1' }
|
{ basePath: 'http://127.0.0.1:39291/v1' }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
this.timeWeightedretriever = new TimeWeightedVectorStoreRetriever({
|
this.timeWeightedretriever = new TimeWeightedVectorStoreRetriever({
|
||||||
@ -49,21 +48,11 @@ export class Retrieval {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public updateEmbeddingEngine(model: string, engine: string): void {
|
public updateEmbeddingEngine(model: string, engine: string): void {
|
||||||
// Engine settings are not compatible with the current embedding model params
|
this.embeddingModel = new OpenAIEmbeddings(
|
||||||
// Switch case manually for now
|
{ openAIApiKey: 'cortex-embedding', model },
|
||||||
if (engine === 'nitro') {
|
// TODO: Raw settings
|
||||||
this.embeddingModel = new OpenAIEmbeddings(
|
{ basePath: 'http://127.0.0.1:39291/v1' }
|
||||||
{ openAIApiKey: 'nitro-embedding', model },
|
)
|
||||||
// TODO: Raw settings
|
|
||||||
{ basePath: 'http://127.0.0.1:3928/v1' },
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// Fallback to OpenAI Settings
|
|
||||||
const settings = readEmbeddingEngine(engine)
|
|
||||||
this.embeddingModel = new OpenAIEmbeddings({
|
|
||||||
openAIApiKey: settings.api_key,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// update time-weighted embedding model
|
// update time-weighted embedding model
|
||||||
this.timeWeightedVectorStore.embeddings = this.embeddingModel
|
this.timeWeightedVectorStore.embeddings = this.embeddingModel
|
||||||
|
|||||||
@ -249,19 +249,11 @@ const ChatInput = () => {
|
|||||||
<li
|
<li
|
||||||
className={twMerge(
|
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))]',
|
'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 ===
|
'cursor-pointer'
|
||||||
false
|
|
||||||
? 'cursor-not-allowed opacity-50'
|
|
||||||
: 'cursor-pointer'
|
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
fileInputRef.current?.click()
|
||||||
activeThread?.assistants[0].model.settings
|
setShowAttacmentMenus(false)
|
||||||
?.text_model !== false
|
|
||||||
) {
|
|
||||||
fileInputRef.current?.click()
|
|
||||||
setShowAttacmentMenus(false)
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FileTextIcon size={16} />
|
<FileTextIcon size={16} />
|
||||||
@ -270,22 +262,11 @@ const ChatInput = () => {
|
|||||||
}
|
}
|
||||||
content={
|
content={
|
||||||
(!activeThread?.assistants[0].tools ||
|
(!activeThread?.assistants[0].tools ||
|
||||||
!activeThread?.assistants[0].tools[0]?.enabled ||
|
!activeThread?.assistants[0].tools[0]?.enabled) && (
|
||||||
activeThread?.assistants[0].model.settings?.text_model ===
|
<span>
|
||||||
false) && (
|
Turn on Retrieval in Assistant Settings to use this
|
||||||
<>
|
feature.
|
||||||
{activeThread?.assistants[0].model.settings
|
</span>
|
||||||
?.text_model === false ? (
|
|
||||||
<span>
|
|
||||||
This model does not support text-based retrieval.
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span>
|
|
||||||
Turn on Retrieval in Assistant Settings to use this
|
|
||||||
feature.
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user