Skip to content

Commit

Permalink
fix: #1569 - Does not apply thread settings when loading model
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Jan 14, 2024
1 parent 4a2f5bc commit fb9b800
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion extensions/inference-nitro-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
joinPath,
InferenceExtension,
log,
InferenceEngine,
} from "@janhq/core";
import { requestInference } from "./helpers/sse";
import { ulid } from "ulid";
Expand Down Expand Up @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion extensions/inference-nitro-extension/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
17 changes: 15 additions & 2 deletions web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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()

Expand All @@ -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({
Expand All @@ -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)
}
Expand Down

0 comments on commit fb9b800

Please sign in to comment.