Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthJadhav committed Oct 16, 2023
1 parent b017c3e commit e611cc9
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 46 deletions.
2 changes: 1 addition & 1 deletion ui/components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useRef,
useState,
} from 'react';
import { toast } from 'react-hot-toast';

import { useTranslation } from 'next-i18next';

Expand All @@ -27,7 +28,6 @@ import HomeContext from '@/pages/api/home/home.context';
import { PluginSelect } from './PluginSelect';
import { PromptList } from './PromptList';
import { VariableModal } from './VariableModal';
import { toast } from 'react-hot-toast';

interface Props {
onSend: (message: Message, plugin: Plugin | null) => void;
Expand Down
2 changes: 1 addition & 1 deletion ui/components/Chat/ChatLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IconRobot } from '@tabler/icons-react';
import { FC } from 'react';

interface Props { }
interface Props {}

export const ChatLoader: FC<Props> = () => {
return (
Expand Down
15 changes: 9 additions & 6 deletions ui/components/Chat/ModelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useContext } from 'react';

import { useTranslation } from 'next-i18next';

import useModel from '@/hooks/useModel';

import { LlamaModel } from '@/types/openai';

import HomeContext from '@/pages/api/home/home.context';
import useModel from '@/hooks/useModel';

export const ModelSelect = () => {
const { t } = useTranslation('chat');
Expand All @@ -18,9 +19,9 @@ export const ModelSelect = () => {
} = useContext(HomeContext);

const handleChange = async (e: React.ChangeEvent<HTMLSelectElement>) => {
const model = models.find(
(model) => e.target.value.includes(model.id),
) as LlamaModel
const model = models.find((model) =>
e.target.value.includes(model.id),
) as LlamaModel;
runModel(model.codeName);
handleUpdateCurrentModel(model);
};
Expand All @@ -33,13 +34,15 @@ export const ModelSelect = () => {
<div className="w-full rounded-lg border border-neutral-600 bg-transparent pr-2 text-neutral-900 dark:border-neutral-700 dark:text-white">
<select
className="w-full bg-transparent p-2"
// remove selectedConversation model because we can't have different models
// remove selectedConversation model because we can't have different models
// per conversation as you won't be able to run it anyways without changing the model
value={currentModel ? currentModel.id : ''}
disabled={isModelLoading}
onChange={handleChange}
>
<option value="" disabled hidden>Select a model</option>
<option value="" disabled hidden>
Select a model
</option>
{models.map((model) => (
<option
key={model.id}
Expand Down
67 changes: 36 additions & 31 deletions ui/hooks/useModel.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
import { toast, Toast } from "react-hot-toast";
import { useMutation } from "react-query";
import { Toast, toast } from 'react-hot-toast';
import { useMutation } from 'react-query';

const startModel = async (codeName: string) => {
const response = await fetch('http://localhost:3002/start-model', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: codeName,
}),
});
return response.json();
}
const response = await fetch('http://localhost:3002/start-model', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: codeName,
}),
});
return response.json();
};

const useModel = () => {
let toastId: string;
const { mutate, error, isLoading, isSuccess } = useMutation(startModel, {
onMutate: () => {
toast.dismiss(toastId);
toastId = toast.loading("Starting model...");
},
onSuccess: () => {
toast.dismiss(toastId);
toast.success("Model started!");
},
onError: () => {
toast.dismiss(toastId);
toast.error("Error starting model!");
}
});
let toastId: string;
const { mutate, error, isLoading, isSuccess } = useMutation(startModel, {
onMutate: () => {
toast.dismiss(toastId);
toastId = toast.loading('Starting model...');
},
onSuccess: () => {
toast.dismiss(toastId);
toast.success('Model started!');
},
onError: () => {
toast.dismiss(toastId);
toast.error('Error starting model!');
},
});

return { runModel: mutate, modelError: error, isModelLoading: isLoading, isModelSuccess: isSuccess };
}
return {
runModel: mutate,
modelError: error,
isModelLoading: isLoading,
isModelSuccess: isSuccess,
};
};

export default useModel;
export default useModel;
2 changes: 1 addition & 1 deletion ui/pages/api/home/home.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ActionType } from '@/hooks/useCreateReducer';
import { Conversation } from '@/types/chat';
import { KeyValuePair } from '@/types/data';
import { FolderType } from '@/types/folder';
import { LlamaModel, LlamaModelID } from '@/types/openai';

import { HomeInitialState } from './home.state';
import { LlamaModel, LlamaModelID } from '@/types/openai';

export interface HomeContextProps {
state: HomeInitialState;
Expand Down
18 changes: 14 additions & 4 deletions ui/pages/api/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import { getSettings } from '@/utils/app/settings';
import { Conversation } from '@/types/chat';
import { KeyValuePair } from '@/types/data';
import { FolderInterface, FolderType } from '@/types/folder';
import { LlamaModelID, LlamaModels, fallbackModelID, LlamaModel } from '@/types/openai';
import {
LlamaModel,
LlamaModelID,
LlamaModels,
fallbackModelID,
} from '@/types/openai';
import { Prompt } from '@/types/prompt';

import { Chat } from '@/components/Chat/Chat';
Expand Down Expand Up @@ -97,7 +102,9 @@ const Home = ({
useEffect(() => {
if (data) {
// @ts-ignore
const modelId = data[0].id.startsWith('.') ? data[0].id.slice(1) : data[0].id;
const modelId = data[0].id.startsWith('.')
? data[0].id.slice(1)
: data[0].id;
// @ts-ignore
dispatch({ field: 'currentModel', value: LlamaModels[modelId] });
}
Expand All @@ -121,7 +128,7 @@ const Home = ({

const handleUpdateCurrentModel = (model: LlamaModel) => {
dispatch({ field: 'currentModel', value: model });
}
};

// FOLDER OPERATIONS --------------------------------------------

Expand Down Expand Up @@ -375,7 +382,10 @@ const Home = ({
>
<Head>
<title>LlamaGPT</title>
<meta name="description" content="Chat with a local LLM on your Umbrel without leaking your data to OpenAI" />
<meta
name="description"
content="Chat with a local LLM on your Umbrel without leaking your data to OpenAI"
/>
<meta
name="viewport"
content="height=device-height ,width=device-width, initial-scale=1, user-scalable=no"
Expand Down
7 changes: 5 additions & 2 deletions ui/utils/app/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const cleanSelectedConversation = (conversation: Conversation) => {
if (!updatedConversation.model) {
updatedConversation = {
...updatedConversation,
model: updatedConversation.model || LlamaModels[LlamaModelID.LLAMA_7B_CHAT_GGMLV3_Q4_0],
model:
updatedConversation.model ||
LlamaModels[LlamaModelID.LLAMA_7B_CHAT_GGMLV3_Q4_0],
};
}

Expand Down Expand Up @@ -67,7 +69,8 @@ export const cleanConversationHistory = (history: any[]): Conversation[] => {
return history.reduce((acc: any[], conversation) => {
try {
if (!conversation.model) {
conversation.model = LlamaModels[LlamaModelID.LLAMA_7B_CHAT_GGMLV3_Q4_0];
conversation.model =
LlamaModels[LlamaModelID.LLAMA_7B_CHAT_GGMLV3_Q4_0];
}

if (!conversation.prompt) {
Expand Down

0 comments on commit e611cc9

Please sign in to comment.