parent
e7fcd775fb
commit
ca28fe51d1
@ -22,6 +22,7 @@ import {
|
||||
joinPath,
|
||||
InferenceExtension,
|
||||
log,
|
||||
InferenceEngine,
|
||||
} from "@janhq/core";
|
||||
import { requestInference } from "./helpers/sse";
|
||||
import { ulid } from "ulid";
|
||||
@ -128,7 +129,7 @@ export default class JanInferenceNitroExtension implements InferenceExtension {
|
||||
}
|
||||
|
||||
private async onModelInit(model: Model) {
|
||||
if (model.engine !== "nitro") return;
|
||||
if (model.engine !== InferenceEngine.nitro) return;
|
||||
|
||||
const modelFullPath = await joinPath(["models", model.id]);
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@ function promptTemplateConverter(promptTemplate) {
|
||||
* @returns A Promise that resolves when the model is loaded successfully, or rejects with an error message if the model is not found or fails to load.
|
||||
*/
|
||||
function loadLLMModel(settings): Promise<Response> {
|
||||
log(`[NITRO]::Debug: Loading model with params ${settings}`);
|
||||
log(`[NITRO]::Debug: Loading model with params ${JSON.stringify(settings)}`);
|
||||
return fetchRetry(NITRO_HTTP_LOAD_MODEL_URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { EventName, events, Model } from '@janhq/core'
|
||||
import { atom, useAtom } from 'jotai'
|
||||
import { atom, useAtom, useAtomValue } from 'jotai'
|
||||
|
||||
import { toaster } from '@/containers/Toast'
|
||||
|
||||
import { useGetDownloadedModels } from './useGetDownloadedModels'
|
||||
import { LAST_USED_MODEL_ID } from './useRecommendedModel'
|
||||
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
|
||||
|
||||
export const activeModelAtom = atom<Model | undefined>(undefined)
|
||||
|
||||
@ -17,6 +18,7 @@ export const stateModelAtom = atom({
|
||||
|
||||
export function useActiveModel() {
|
||||
const [activeModel, setActiveModel] = useAtom(activeModelAtom)
|
||||
const activeThread = useAtomValue(activeThreadAtom)
|
||||
const [stateModel, setStateModel] = useAtom(stateModelAtom)
|
||||
const { downloadedModels } = useGetDownloadedModels()
|
||||
|
||||
@ -34,7 +36,7 @@ export function useActiveModel() {
|
||||
|
||||
setStateModel({ state: 'start', loading: true, model: modelId })
|
||||
|
||||
const model = downloadedModels.find((e) => e.id === modelId)
|
||||
let model = downloadedModels.find((e) => e.id === modelId)
|
||||
|
||||
if (!model) {
|
||||
toaster({
|
||||
@ -49,6 +51,17 @@ export function useActiveModel() {
|
||||
return
|
||||
}
|
||||
|
||||
/// Apply thread model settings
|
||||
if (activeThread?.assistants[0]?.model.id === modelId) {
|
||||
model = {
|
||||
...model,
|
||||
settings: {
|
||||
...model.settings,
|
||||
...activeThread.assistants[0].model.settings,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem(LAST_USED_MODEL_ID, model.id)
|
||||
events.emit(EventName.OnModelInit, model)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user