Skip to content

Commit

Permalink
Merge branch 'main' into docs/install
Browse files Browse the repository at this point in the history
  • Loading branch information
0xHieu01 authored Nov 20, 2023
2 parents 12f1897 + c9cfebd commit f2b2247
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 147 deletions.
1 change: 0 additions & 1 deletion plugins/inference-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import {
ChatCompletionMessage,
ChatCompletionRole,
EventName,
MessageRequest,
Expand Down
4 changes: 2 additions & 2 deletions plugins/inference-plugin/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ async function validateModelStatus(): Promise<InitModelResponse> {
return { error: undefined };
}
}
return { error: "Model is not loaded successfully" };
return { error: "Model loading failed" };
})
.catch((err) => {
return { error: `Model is not loaded successfully. ${err.message}` };
return { error: `Model loading failed. ${err.message}` };
});
}

Expand Down
21 changes: 21 additions & 0 deletions plugins/model-plugin/src/@types/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
interface Version {
name: string
quantMethod: string
bits: number
size: number
maxRamRequired: number
usecase: string
downloadLink: string
}
interface ModelSchema {
id: string
name: string
shortDescription: string
avatarUrl: string
longDescription: string
author: string
version: string
modelUrl: string
tags: string[]
versions: Version[]
}
35 changes: 15 additions & 20 deletions plugins/model-plugin/src/helpers/modelParser.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
export const parseToModel = (model) => {
import { ModelCatalog } from '@janhq/core'

export function parseToModel(schema: ModelSchema): ModelCatalog {
const modelVersions = []
model.versions.forEach((v) => {
schema.versions.forEach((v) => {
const version = {
id: `${model.author}-${v.name}`,
name: v.name,
quantMethod: v.quantMethod,
bits: v.bits,
size: v.size,
maxRamRequired: v.maxRamRequired,
usecase: v.usecase,
downloadLink: v.downloadLink,
productId: model.id,
}
modelVersions.push(version)
})

const product = {
id: model.id,
name: model.name,
shortDescription: model.shortDescription,
avatarUrl: model.avatarUrl,
author: model.author,
version: model.version,
modelUrl: model.modelUrl,
nsfw: model.nsfw,
tags: model.tags,
greeting: model.defaultGreeting,
type: model.type,
createdAt: model.createdAt,
longDescription: model.longDescription,
status: 'Downloadable',
const model: ModelCatalog = {
id: schema.id,
name: schema.name,
shortDescription: schema.shortDescription,
avatarUrl: schema.avatarUrl,
author: schema.author,
version: schema.version,
modelUrl: schema.modelUrl,
tags: schema.tags,
longDescription: schema.longDescription,
releaseDate: 0,
availableVersions: modelVersions,
}
return product
return model
}
4 changes: 3 additions & 1 deletion web/containers/Layout/TopBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const TopBar = () => {
<div className="fixed left-0 top-0 z-50 flex h-12 w-full border-b border-border bg-background/50">
<div className="relative left-16 flex w-[calc(100%-64px)] items-center justify-between space-x-4 pl-6 pr-2">
<div>
<span className="font-medium">{viewStateName}</span>
<span className="font-medium">
{viewStateName.replace(/([A-Z])/g, ' $1').trim()}
</span>
</div>
<CommandSearch />
{/* Command without trigger interface */}
Expand Down
12 changes: 0 additions & 12 deletions web/helpers/atoms/Modal.atom.ts

This file was deleted.

5 changes: 4 additions & 1 deletion web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export function useActiveModel() {
const model = downloadedModels.find((e) => e.id === modelId)

if (!model) {
alert(`Model ${modelId} not found! Please re-download the model first.`)
toaster({
title: `Model ${modelId} not found!`,
description: `Please download the model first.`,
})
setStateModel(() => ({
state: 'start',
loading: false,
Expand Down
5 changes: 2 additions & 3 deletions web/hooks/useCreateConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ export const useCreateConversation = () => {
const addNewConvoState = useSetAtom(addNewConversationStateAtom)

const requestCreateConvo = async (model: Model) => {
const summary = model.name
const mappedConvo: Thread = {
id: generateConversationId(),
modelId: model.id,
summary,
summary: model.name,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
messages: [],
Expand All @@ -35,7 +34,7 @@ export const useCreateConversation = () => {
waitingForResponse: false,
})

pluginManager
await pluginManager
.get<ConversationalPlugin>(PluginType.Conversational)
?.saveConversation(mappedConvo)
setUserConversations([mappedConvo, ...userConversations])
Expand Down
14 changes: 3 additions & 11 deletions web/hooks/useDeleteConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ import {
getActiveConvoIdAtom,
setActiveConvoIdAtom,
} from '@/helpers/atoms/Conversation.atom'
import {
showingProductDetailAtom,
showingAdvancedPromptAtom,
} from '@/helpers/atoms/Modal.atom'

export default function useDeleteConversation() {
const { activeModel } = useActiveModel()
const [userConversations, setUserConversations] = useAtom(
userConversationsAtom
)
const setCurrentPrompt = useSetAtom(currentPromptAtom)
const setShowingProductDetail = useSetAtom(showingProductDetailAtom)
const setShowingAdvancedPrompt = useSetAtom(showingAdvancedPromptAtom)
const activeConvoId = useAtomValue(getActiveConvoIdAtom)

const setActiveConvoId = useSetAtom(setActiveConvoIdAtom)
Expand All @@ -45,18 +39,16 @@ export default function useDeleteConversation() {
)
setUserConversations(currentConversations)
deleteMessages(activeConvoId)
setCurrentPrompt('')
toaster({
title: 'Succes delete a chat',
description: `Delete chat with ${activeModel?.name} has been completed`,
title: 'Chat successfully deleted.',
description: `Chat with ${activeModel?.name} has been successfully deleted.`,
})
if (currentConversations.length > 0) {
setActiveConvoId(currentConversations[0].id)
} else {
setActiveConvoId(undefined)
}
setCurrentPrompt('')
setShowingProductDetail(false)
setShowingAdvancedPrompt(false)
} catch (err) {
console.error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions web/hooks/useDeleteModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export default function useDeleteModel() {
// reload models
setDownloadedModels(downloadedModels.filter((e) => e.id !== model.id))
toaster({
title: 'Delete a Model',
description: `Model ${model.id} has been deleted.`,
title: 'Model Deletion Successful',
description: `The model ${model.id} has been successfully deleted.`,
})
}

Expand Down
13 changes: 5 additions & 8 deletions web/hooks/useGetConfiguredModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ export function useGetConfiguredModels() {
const [models, setModels] = useState<ModelCatalog[]>([])

async function getConfiguredModels(): Promise<ModelCatalog[]> {
return (
((await pluginManager
.get<ModelPlugin>(PluginType.Model)
?.getConfiguredModels()) as ModelCatalog[]) ?? []
)
const models = await pluginManager
.get<ModelPlugin>(PluginType.Model)
?.getConfiguredModels()
return models ?? []
}

const fetchModels = async () => {
async function fetchModels() {
setLoading(true)
let models = await getConfiguredModels()
if (process.env.NODE_ENV === 'development') {
Expand All @@ -37,10 +36,8 @@ export function useGetConfiguredModels() {
setModels(models)
}

// TODO allow user for filter
useEffect(() => {
fetchModels()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return { loading, models }
Expand Down
9 changes: 4 additions & 5 deletions web/hooks/useGetDownloadedModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export function useGetDownloadedModels() {
const [downloadedModels, setDownloadedModels] = useAtom(downloadedModelAtom)

async function getDownloadedModels(): Promise<Model[]> {
const models =
((await pluginManager
.get<ModelPlugin>(PluginType.Model)
?.getDownloadedModels()) as Model[]) ?? []
return models
const models = await pluginManager
.get<ModelPlugin>(PluginType.Model)
?.getDownloadedModels()
return models ?? []
}

useEffect(() => {
Expand Down
14 changes: 7 additions & 7 deletions web/hooks/useGetInputState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import { currentConversationAtom } from '@/helpers/atoms/Conversation.atom'

export default function useGetInputState() {
const [inputState, setInputState] = useState<InputType>('loading')
const currentConvo = useAtomValue(currentConversationAtom)
const currentThread = useAtomValue(currentConversationAtom)
const { activeModel } = useActiveModel()
const { downloadedModels } = useGetDownloadedModels()

const handleInputState = (
convo: Thread | undefined,
thread: Thread | undefined,
currentModel: Model | undefined
) => {
if (convo == null) return
if (thread == null) return
if (currentModel == null) {
setInputState('loading')
return
}

// check if convo model id is in downloaded models
const isModelAvailable = downloadedModels.some(
(model) => model.id === convo.modelId
(model) => model.id === thread.modelId
)

if (!isModelAvailable) {
Expand All @@ -35,7 +35,7 @@ export default function useGetInputState() {
return
}

if (convo.modelId !== currentModel.id) {
if (thread.modelId !== currentModel.id) {
// in case convo model and active model is different,
// ask user to init the required model
setInputState('model-mismatch')
Expand All @@ -46,11 +46,11 @@ export default function useGetInputState() {
}

useEffect(() => {
handleInputState(currentConvo, activeModel)
handleInputState(currentThread, activeModel)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return { inputState, currentConvo }
return { inputState, currentThread }
}

type InputType = 'available' | 'loading' | 'model-mismatch' | 'model-not-found'
7 changes: 4 additions & 3 deletions web/hooks/useGetSystemResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ export default function useGetSystemResources() {
useEffect(() => {
getSystemResources()

// Fetch interval - every 3s
// Fetch interval - every 5s
// TODO: Will we really need this?
// There is a possibility that this will be removed and replaced by the process event hook?
const intervalId = setInterval(() => {
getSystemResources()
}, 5000)

// clean up
// clean up interval
return () => clearInterval(intervalId)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return {
Expand Down
Loading

0 comments on commit f2b2247

Please sign in to comment.