2024-09-29 19:57:26 +05:30
|
|
|
import { getModelInfo, isCustomModel } from "@/db/models"
|
2024-06-30 20:45:06 +05:30
|
|
|
import { ChatChromeAI } from "./ChatChromeAi"
|
|
|
|
|
import { ChatOllama } from "./ChatOllama"
|
2024-09-29 19:57:26 +05:30
|
|
|
import { getOpenAIConfigById } from "@/db/openai"
|
|
|
|
|
import { ChatOpenAI } from "@langchain/openai"
|
2024-06-30 20:45:06 +05:30
|
|
|
|
|
|
|
|
export const pageAssistModel = async ({
|
|
|
|
|
model,
|
|
|
|
|
baseUrl,
|
|
|
|
|
keepAlive,
|
|
|
|
|
temperature,
|
|
|
|
|
topK,
|
|
|
|
|
topP,
|
|
|
|
|
numCtx,
|
2024-08-20 16:11:50 +05:30
|
|
|
seed,
|
|
|
|
|
numGpu
|
2024-06-30 20:45:06 +05:30
|
|
|
}: {
|
|
|
|
|
model: string
|
|
|
|
|
baseUrl: string
|
2024-08-05 00:49:27 +05:30
|
|
|
keepAlive?: string
|
|
|
|
|
temperature?: number
|
|
|
|
|
topK?: number
|
|
|
|
|
topP?: number
|
|
|
|
|
numCtx?: number
|
|
|
|
|
seed?: number
|
2024-08-20 16:11:50 +05:30
|
|
|
numGpu?: number
|
2024-06-30 20:45:06 +05:30
|
|
|
}) => {
|
2024-09-29 19:57:26 +05:30
|
|
|
|
|
|
|
|
if (model === "chrome::gemini-nano::page-assist") {
|
|
|
|
|
return new ChatChromeAI({
|
|
|
|
|
temperature,
|
|
|
|
|
topK
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isCustom = isCustomModel(model)
|
|
|
|
|
|
|
|
|
|
console.log("isCustom", isCustom, model)
|
|
|
|
|
|
|
|
|
|
if (isCustom) {
|
|
|
|
|
const modelInfo = await getModelInfo(model)
|
|
|
|
|
const providerInfo = await getOpenAIConfigById(modelInfo.provider_id)
|
|
|
|
|
|
|
|
|
|
return new ChatOpenAI({
|
|
|
|
|
modelName: modelInfo.model_id,
|
|
|
|
|
openAIApiKey: providerInfo.apiKey || "",
|
|
|
|
|
temperature,
|
|
|
|
|
topP,
|
|
|
|
|
configuration: {
|
|
|
|
|
apiKey: providerInfo.apiKey || "",
|
|
|
|
|
baseURL: providerInfo.baseUrl || "",
|
|
|
|
|
}
|
|
|
|
|
}) as any
|
2024-06-30 20:45:06 +05:30
|
|
|
}
|
2024-09-29 19:57:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ChatOllama({
|
|
|
|
|
baseUrl,
|
|
|
|
|
keepAlive,
|
|
|
|
|
temperature,
|
|
|
|
|
topK,
|
|
|
|
|
topP,
|
|
|
|
|
numCtx,
|
|
|
|
|
seed,
|
|
|
|
|
model,
|
|
|
|
|
numGpu
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-30 20:45:06 +05:30
|
|
|
}
|