Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	web/screens/Chat/ErrorMessage/index.tsx
  • Loading branch information
louis-jan committed Apr 2, 2024
2 parents 174f882 + 30f34a4 commit f6d3b53
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 17 deletions.
8 changes: 8 additions & 0 deletions core/src/browser/extensions/engines/OAIEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ export abstract class OAIEngine extends AIEngine {
events.emit(MessageEvent.OnMessageUpdate, message)
},
error: async (err: any) => {
console.error(`Inference error: ${JSON.stringify(err, null, 2)}`)
if (this.isCancelled || message.content.length) {
message.status = MessageStatus.Stopped
events.emit(MessageEvent.OnMessageUpdate, message)
return
}
message.status = MessageStatus.Error
message.content[0] = {
type: ContentType.Text,
text: {
value: err.message,
annotations: [],
},
}
message.error_code = err.code
events.emit(MessageEvent.OnMessageUpdate, message)
},
Expand Down
2 changes: 2 additions & 0 deletions core/src/types/message/messageEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export enum MessageStatus {
export enum ErrorCode {
InvalidApiKey = 'invalid_api_key',

InsufficientQuota = 'insufficient_quota',

Unknown = 'unknown',
}

Expand Down
6 changes: 4 additions & 2 deletions extensions/assistant-extension/src/tools/retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class RetrievalTool extends InferenceTool {
tool?: AssistantTool
): Promise<MessageRequest> {
if (!data.model || !data.messages) {
return Promise.resolve(this.normalize(data))
return Promise.resolve(data)
}

const latestMessage = data.messages[data.messages.length - 1]
Expand All @@ -38,6 +38,8 @@ export class RetrievalTool extends InferenceTool {
docFile,
data.model?.engine
)
} else {
return Promise.resolve(data)
}
} else if (
// Check whether we need to ingest document or not
Expand All @@ -48,7 +50,7 @@ export class RetrievalTool extends InferenceTool {
) {
// No document ingested, reroute the result to inference engine

return Promise.resolve(this.normalize(data))
return Promise.resolve(data)
}
// 2. Load agent on thread changed
if (this.retrievalThreadId !== data.threadId) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/model-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@janhq/model-extension",
"version": "1.0.28",
"version": "1.0.30",
"description": "Model Management Extension provides model exploration and seamless downloads",
"main": "dist/index.js",
"module": "dist/module.js",
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf"
}
],
"id": "mistral-7b",
"id": "mistral-ins-7b-q4",
"object": "model",
"name": "Mistral Instruct 7B Q4",
"version": "1.0",
Expand All @@ -29,7 +29,7 @@
"author": "MistralAI",
"tags": ["Featured", "7B", "Foundational Model"],
"size": 4370000000,
"cover": "https://raw.githubusercontent.com/janhq/jan/dev/models/mistral-7b/cover.png"
"cover": "https://raw.githubusercontent.com/janhq/jan/dev/models/mistral-ins-7b-q4/cover.png"
},
"engine": "nitro"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://huggingface.co/janhq/stealth-v1.3-GGUF/resolve/main/stealth-v1.3.Q4_K_M.gguf"
}
],
"id": "stealth-7b",
"id": "stealth-v1.2-7b",
"object": "model",
"name": "Stealth 7B Q4",
"version": "1.0",
Expand Down
34 changes: 34 additions & 0 deletions models/tinyllama-1.1b/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"sources": [
{
"filename": "tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf",
"url": "https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf"
}
],
"id": "tinyllama-1.1b",
"object": "model",
"name": "TinyLlama Chat 1.1B Q4",
"version": "1.0",
"description": "TinyLlama is a tiny model with only 1.1B. It's a good model for less powerful computers.",
"format": "gguf",
"settings": {
"ctx_len": 4096,
"prompt_template": "<|system|>\n{system_message}<|user|>\n{prompt}<|assistant|>",
"llama_model_path": "tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf"
},
"parameters": {
"temperature": 0.7,
"top_p": 0.95,
"stream": true,
"max_tokens": 2048,
"stop": [],
"frequency_penalty": 0,
"presence_penalty": 0
},
"metadata": {
"author": "TinyLlama",
"tags": ["Tiny", "Foundation Model"],
"size": 669000000
},
"engine": "nitro"
}
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://huggingface.co/janhq/trinity-v1.2-GGUF/resolve/main/trinity-v1.2.Q4_K_M.gguf"
}
],
"id": "trinity-7b",
"id": "trinity-v1.2-7b",
"object": "model",
"name": "Trinity-v1.2 7B Q4",
"version": "1.0",
Expand All @@ -28,7 +28,7 @@
"author": "Jan",
"tags": ["7B", "Merged", "Featured"],
"size": 4370000000,
"cover": "https://raw.githubusercontent.com/janhq/jan/dev/models/trinity-7b/cover.png"
"cover": "https://raw.githubusercontent.com/janhq/jan/dev/models/trinity-v1.2-7b/cover.png"
},
"engine": "nitro"
}
34 changes: 34 additions & 0 deletions web/containers/AutoLink/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'

type Props = {
text: string
}

const AutoLink: React.FC<Props> = ({ text }) => {
const delimiter =
/((?:https?:\/\/)?(?:(?:[a-z0-9]?(?:[a-z0-9-]{1,61}[a-z0-9])?\.[^.|\s])+[a-z.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_/~#&=;%+?\-\\(\\)]*)/gi

return (
<>
{text.split(delimiter).map((word) => {
const match = word.match(delimiter)
if (match) {
const url = match[0]
return (
<a
key={url}
target="blank"
href={url.startsWith('http') ? url : `http://${url}`}
className="text-primary dark:text-blue-400"
>
{url}
</a>
)
}
return word
})}
</>
)
}

export default React.memo(AutoLink)
8 changes: 4 additions & 4 deletions web/hooks/useSendChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ export default function useSendChatMessage() {
selectedModelRef.current?.id ??
activeThreadRef.current.assistants[0].model.id

if (base64Blob) {
setFileUpload([])
}

if (modelRef.current?.id !== modelId) {
setQueuedMessage(true)
const error = await startModel(modelId).catch((error: Error) => error)
Expand Down Expand Up @@ -261,10 +265,6 @@ export default function useSendChatMessage() {
// Reset states
setReloadModel(false)
setEngineParamsUpdate(false)

if (base64Blob) {
setFileUpload([])
}
}

return {
Expand Down
5 changes: 3 additions & 2 deletions web/screens/Chat/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button } from '@janhq/uikit'
import { useAtomValue, useSetAtom } from 'jotai'
import { RefreshCcw } from 'lucide-react'

import AutoLink from '@/containers/AutoLink'
import ModalTroubleShooting, {
modalTroubleShootingAtom,
} from '@/containers/ModalTroubleShoot'
Expand Down Expand Up @@ -110,9 +111,9 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
) : (
<div
key={message.id}
className="flex flex-col items-center text-center text-sm font-medium text-gray-500"
className="mx-6 flex flex-col items-center space-y-2 text-center text-sm font-medium text-gray-500"
>
{getErrorTitle()}
<AutoLink text={getErrorTitle()} />
<p>
Jan’s in beta. Access&nbsp;
<span
Expand Down
8 changes: 5 additions & 3 deletions web/screens/ExploreModels/ExploreModelItemHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'react'
import { useCallback, useState } from 'react'

import { Model } from '@janhq/core'
import {
Expand Down Expand Up @@ -70,6 +70,7 @@ const ExploreModelItemHeader: React.FC<Props> = ({ model, onClick, open }) => {
const { requestCreateNewThread } = useCreateNewThread()
const totalRam = useAtomValue(totalRamAtom)
const { settings } = useSettings()
const [imageLoaded, setImageLoaded] = useState(true)

const nvidiaTotalVram = useAtomValue(nvidiaTotalVramAtom)
const setMainViewState = useSetAtom(mainViewStateAtom)
Expand Down Expand Up @@ -143,9 +144,10 @@ const ExploreModelItemHeader: React.FC<Props> = ({ model, onClick, open }) => {
className="cursor-pointer rounded-t-md bg-background"
onClick={onClick}
>
{model.metadata.cover && (
<div className="relative h-full w-full ">
{model.metadata.cover && imageLoaded && (
<div className="relative h-full w-full">
<img
onError={() => setImageLoaded(false)}
src={model.metadata.cover}
className="h-[250px] w-full object-cover"
alt={`Cover - ${model.id}`}
Expand Down

0 comments on commit f6d3b53

Please sign in to comment.