Spaces:
Paused
Paused
matt HOFFNER
commited on
Commit
·
2670b73
1
Parent(s):
fa1eede
more mini
Browse files- components/Chat/ChatInput.tsx +1 -1
- pages/api/home/home.context.tsx +0 -4
- pages/api/home/home.tsx +4 -93
- services/useApiService.ts +0 -16
- utils/app/const.ts +1 -1
components/Chat/ChatInput.tsx
CHANGED
|
@@ -325,7 +325,7 @@ export const ChatInput = ({
|
|
| 325 |
}`,
|
| 326 |
}}
|
| 327 |
placeholder={
|
| 328 |
-
t('Type a message
|
| 329 |
}
|
| 330 |
value={content}
|
| 331 |
rows={1}
|
|
|
|
| 325 |
}`,
|
| 326 |
}}
|
| 327 |
placeholder={
|
| 328 |
+
t('Type a message') || ''
|
| 329 |
}
|
| 330 |
value={content}
|
| 331 |
rows={1}
|
pages/api/home/home.context.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import { ActionType } from '@/hooks/useCreateReducer';
|
|
| 4 |
|
| 5 |
import { Conversation } from '@/types/chat';
|
| 6 |
import { KeyValuePair } from '@/types/data';
|
| 7 |
-
import { FolderType } from '@/types/folder';
|
| 8 |
|
| 9 |
import { HomeInitialState } from './home.state';
|
| 10 |
|
|
@@ -12,9 +11,6 @@ export interface HomeContextProps {
|
|
| 12 |
state: HomeInitialState;
|
| 13 |
dispatch: Dispatch<ActionType<HomeInitialState>>;
|
| 14 |
handleNewConversation: () => void;
|
| 15 |
-
handleCreateFolder: (name: string, type: FolderType) => void;
|
| 16 |
-
handleDeleteFolder: (folderId: string) => void;
|
| 17 |
-
handleUpdateFolder: (folderId: string, name: string) => void;
|
| 18 |
handleSelectConversation: (conversation: Conversation) => void;
|
| 19 |
handleUpdateConversation: (
|
| 20 |
conversation: Conversation,
|
|
|
|
| 4 |
|
| 5 |
import { Conversation } from '@/types/chat';
|
| 6 |
import { KeyValuePair } from '@/types/data';
|
|
|
|
| 7 |
|
| 8 |
import { HomeInitialState } from './home.state';
|
| 9 |
|
|
|
|
| 11 |
state: HomeInitialState;
|
| 12 |
dispatch: Dispatch<ActionType<HomeInitialState>>;
|
| 13 |
handleNewConversation: () => void;
|
|
|
|
|
|
|
|
|
|
| 14 |
handleSelectConversation: (conversation: Conversation) => void;
|
| 15 |
handleUpdateConversation: (
|
| 16 |
conversation: Conversation,
|
pages/api/home/home.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
import { useEffect, useRef
|
| 2 |
-
import { useQuery } from 'react-query';
|
| 3 |
|
| 4 |
import { GetServerSideProps } from 'next';
|
| 5 |
import { useTranslation } from 'next-i18next';
|
|
@@ -8,9 +7,6 @@ import Head from 'next/head';
|
|
| 8 |
|
| 9 |
import { useCreateReducer } from '@/hooks/useCreateReducer';
|
| 10 |
|
| 11 |
-
import useErrorService from '@/services/errorService';
|
| 12 |
-
import useApiService from '@/services/useApiService';
|
| 13 |
-
|
| 14 |
import {
|
| 15 |
cleanConversationHistory,
|
| 16 |
cleanSelectedConversation,
|
|
@@ -32,9 +28,6 @@ import { OpenAIModelID, OpenAIModels, fallbackModelID } from '@/types/openai';
|
|
| 32 |
import { Prompt } from '@/types/prompt';
|
| 33 |
|
| 34 |
import { Chat } from '@/components/Chat/Chat';
|
| 35 |
-
import { Chatbar } from '@/components/Chatbar/Chatbar';
|
| 36 |
-
import { Navbar } from '@/components/Mobile/Navbar';
|
| 37 |
-
import Promptbar from '@/components/Promptbar';
|
| 38 |
|
| 39 |
import HomeContext from './home.context';
|
| 40 |
import { HomeInitialState, initialState } from './home.state';
|
|
@@ -53,9 +46,6 @@ const Home = ({
|
|
| 53 |
defaultModelId,
|
| 54 |
}: Props) => {
|
| 55 |
const { t } = useTranslation('chat');
|
| 56 |
-
const { getModels } = useApiService();
|
| 57 |
-
const { getModelsError } = useErrorService();
|
| 58 |
-
const [initialRender, setInitialRender] = useState<boolean>(true);
|
| 59 |
|
| 60 |
const contextValue = useCreateReducer<HomeInitialState>({
|
| 61 |
initialState,
|
|
@@ -76,8 +66,6 @@ const Home = ({
|
|
| 76 |
|
| 77 |
const stopConversationRef = useRef<boolean>(false);
|
| 78 |
|
| 79 |
-
// FETCH MODELS ----------------------------------------------
|
| 80 |
-
|
| 81 |
const handleSelectConversation = (conversation: Conversation) => {
|
| 82 |
dispatch({
|
| 83 |
field: 'selectedConversation',
|
|
@@ -87,72 +75,6 @@ const Home = ({
|
|
| 87 |
saveConversation(conversation);
|
| 88 |
};
|
| 89 |
|
| 90 |
-
// FOLDER OPERATIONS --------------------------------------------
|
| 91 |
-
|
| 92 |
-
const handleCreateFolder = (name: string, type: FolderType) => {
|
| 93 |
-
const newFolder: FolderInterface = {
|
| 94 |
-
id: uuidv4(),
|
| 95 |
-
name,
|
| 96 |
-
type,
|
| 97 |
-
};
|
| 98 |
-
|
| 99 |
-
const updatedFolders = [...folders, newFolder];
|
| 100 |
-
|
| 101 |
-
dispatch({ field: 'folders', value: updatedFolders });
|
| 102 |
-
saveFolders(updatedFolders);
|
| 103 |
-
};
|
| 104 |
-
|
| 105 |
-
const handleDeleteFolder = (folderId: string) => {
|
| 106 |
-
const updatedFolders = folders.filter((f) => f.id !== folderId);
|
| 107 |
-
dispatch({ field: 'folders', value: updatedFolders });
|
| 108 |
-
saveFolders(updatedFolders);
|
| 109 |
-
|
| 110 |
-
const updatedConversations: Conversation[] = conversations.map((c) => {
|
| 111 |
-
if (c.folderId === folderId) {
|
| 112 |
-
return {
|
| 113 |
-
...c,
|
| 114 |
-
folderId: null,
|
| 115 |
-
};
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
return c;
|
| 119 |
-
});
|
| 120 |
-
|
| 121 |
-
dispatch({ field: 'conversations', value: updatedConversations });
|
| 122 |
-
saveConversations(updatedConversations);
|
| 123 |
-
|
| 124 |
-
const updatedPrompts: Prompt[] = prompts.map((p) => {
|
| 125 |
-
if (p.folderId === folderId) {
|
| 126 |
-
return {
|
| 127 |
-
...p,
|
| 128 |
-
folderId: null,
|
| 129 |
-
};
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
return p;
|
| 133 |
-
});
|
| 134 |
-
|
| 135 |
-
dispatch({ field: 'prompts', value: updatedPrompts });
|
| 136 |
-
savePrompts(updatedPrompts);
|
| 137 |
-
};
|
| 138 |
-
|
| 139 |
-
const handleUpdateFolder = (folderId: string, name: string) => {
|
| 140 |
-
const updatedFolders = folders.map((f) => {
|
| 141 |
-
if (f.id === folderId) {
|
| 142 |
-
return {
|
| 143 |
-
...f,
|
| 144 |
-
name,
|
| 145 |
-
};
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
return f;
|
| 149 |
-
});
|
| 150 |
-
|
| 151 |
-
dispatch({ field: 'folders', value: updatedFolders });
|
| 152 |
-
|
| 153 |
-
saveFolders(updatedFolders);
|
| 154 |
-
};
|
| 155 |
-
|
| 156 |
// CONVERSATION OPERATIONS --------------------------------------------
|
| 157 |
|
| 158 |
const handleNewConversation = () => {
|
|
@@ -236,15 +158,7 @@ const Home = ({
|
|
| 236 |
});
|
| 237 |
}
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
if (serverSideApiKeyIsSet) {
|
| 242 |
-
dispatch({ field: 'apiKey', value: '' });
|
| 243 |
-
|
| 244 |
-
localStorage.removeItem('apiKey');
|
| 245 |
-
} else if (apiKey) {
|
| 246 |
-
dispatch({ field: 'apiKey', value: apiKey });
|
| 247 |
-
}
|
| 248 |
|
| 249 |
const pluginKeys = localStorage.getItem('pluginKeys');
|
| 250 |
if (serverSidePluginKeysSet) {
|
|
@@ -329,16 +243,13 @@ const Home = ({
|
|
| 329 |
value={{
|
| 330 |
...contextValue,
|
| 331 |
handleNewConversation,
|
| 332 |
-
handleCreateFolder,
|
| 333 |
-
handleDeleteFolder,
|
| 334 |
-
handleUpdateFolder,
|
| 335 |
handleSelectConversation,
|
| 336 |
handleUpdateConversation,
|
| 337 |
}}
|
| 338 |
>
|
| 339 |
<Head>
|
| 340 |
-
<title>
|
| 341 |
-
<meta name="description" content="
|
| 342 |
<meta
|
| 343 |
name="viewport"
|
| 344 |
content="height=device-height ,width=device-width, initial-scale=1, user-scalable=no"
|
|
|
|
| 1 |
+
import { useEffect, useRef } from 'react';
|
|
|
|
| 2 |
|
| 3 |
import { GetServerSideProps } from 'next';
|
| 4 |
import { useTranslation } from 'next-i18next';
|
|
|
|
| 7 |
|
| 8 |
import { useCreateReducer } from '@/hooks/useCreateReducer';
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
import {
|
| 11 |
cleanConversationHistory,
|
| 12 |
cleanSelectedConversation,
|
|
|
|
| 28 |
import { Prompt } from '@/types/prompt';
|
| 29 |
|
| 30 |
import { Chat } from '@/components/Chat/Chat';
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
import HomeContext from './home.context';
|
| 33 |
import { HomeInitialState, initialState } from './home.state';
|
|
|
|
| 46 |
defaultModelId,
|
| 47 |
}: Props) => {
|
| 48 |
const { t } = useTranslation('chat');
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
const contextValue = useCreateReducer<HomeInitialState>({
|
| 51 |
initialState,
|
|
|
|
| 66 |
|
| 67 |
const stopConversationRef = useRef<boolean>(false);
|
| 68 |
|
|
|
|
|
|
|
| 69 |
const handleSelectConversation = (conversation: Conversation) => {
|
| 70 |
dispatch({
|
| 71 |
field: 'selectedConversation',
|
|
|
|
| 75 |
saveConversation(conversation);
|
| 76 |
};
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
// CONVERSATION OPERATIONS --------------------------------------------
|
| 79 |
|
| 80 |
const handleNewConversation = () => {
|
|
|
|
| 158 |
});
|
| 159 |
}
|
| 160 |
|
| 161 |
+
dispatch({ field: 'apiKey', value: "test" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
const pluginKeys = localStorage.getItem('pluginKeys');
|
| 164 |
if (serverSidePluginKeysSet) {
|
|
|
|
| 243 |
value={{
|
| 244 |
...contextValue,
|
| 245 |
handleNewConversation,
|
|
|
|
|
|
|
|
|
|
| 246 |
handleSelectConversation,
|
| 247 |
handleUpdateConversation,
|
| 248 |
}}
|
| 249 |
>
|
| 250 |
<Head>
|
| 251 |
+
<title>Chatbot Mini</title>
|
| 252 |
+
<meta name="description" content="Mini chatbot UI" />
|
| 253 |
<meta
|
| 254 |
name="viewport"
|
| 255 |
content="height=device-height ,width=device-width, initial-scale=1, user-scalable=no"
|
services/useApiService.ts
CHANGED
|
@@ -9,22 +9,6 @@ export interface GetModelsRequestProps {
|
|
| 9 |
const useApiService = () => {
|
| 10 |
const fetchService = useFetch();
|
| 11 |
|
| 12 |
-
// const getModels = useCallback(
|
| 13 |
-
// (
|
| 14 |
-
// params: GetManagementRoutineInstanceDetailedParams,
|
| 15 |
-
// signal?: AbortSignal
|
| 16 |
-
// ) => {
|
| 17 |
-
// return fetchService.get<GetManagementRoutineInstanceDetailed>(
|
| 18 |
-
// `/v1/ManagementRoutines/${params.managementRoutineId}/instances/${params.instanceId
|
| 19 |
-
// }?sensorGroupIds=${params.sensorGroupId ?? ''}`,
|
| 20 |
-
// {
|
| 21 |
-
// signal,
|
| 22 |
-
// }
|
| 23 |
-
// );
|
| 24 |
-
// },
|
| 25 |
-
// [fetchService]
|
| 26 |
-
// );
|
| 27 |
-
|
| 28 |
const getModels = useCallback(
|
| 29 |
(params: GetModelsRequestProps, signal?: AbortSignal) => {
|
| 30 |
return fetchService.post<GetModelsRequestProps>(`/api/models`, {
|
|
|
|
| 9 |
const useApiService = () => {
|
| 10 |
const fetchService = useFetch();
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
const getModels = useCallback(
|
| 13 |
(params: GetModelsRequestProps, signal?: AbortSignal) => {
|
| 14 |
return fetchService.post<GetModelsRequestProps>(`/api/models`, {
|
utils/app/const.ts
CHANGED
|
@@ -3,7 +3,7 @@ export const DEFAULT_SYSTEM_PROMPT =
|
|
| 3 |
"You are a large language model. Follow the user's instructions carefully. Respond using markdown.";
|
| 4 |
|
| 5 |
export const OPENAI_API_HOST =
|
| 6 |
-
process.env.OPENAI_API_HOST || '
|
| 7 |
|
| 8 |
export const DEFAULT_TEMPERATURE =
|
| 9 |
parseFloat(process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE || "1");
|
|
|
|
| 3 |
"You are a large language model. Follow the user's instructions carefully. Respond using markdown.";
|
| 4 |
|
| 5 |
export const OPENAI_API_HOST =
|
| 6 |
+
process.env.OPENAI_API_HOST || 'http://localhost:8000';
|
| 7 |
|
| 8 |
export const DEFAULT_TEMPERATURE =
|
| 9 |
parseFloat(process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE || "1");
|