From 5c835675fb9ebc76080c44b8e82d9703002e1e8c Mon Sep 17 00:00:00 2001 From: Andrei Canta Date: Tue, 21 Mar 2023 23:41:39 +0200 Subject: [PATCH] add gpt-4 support --- src/components/SettingsModal.tsx | 40 +++++++++++++++++++++++++------- src/db/index.ts | 1 + src/routes/ChatRoute.tsx | 7 +++--- src/routes/IndexRoute.tsx | 2 ++ src/utils/constants.ts | 17 ++++++++++++++ src/utils/openai.ts | 7 +++++- 6 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index 33c6de5..113709c 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -1,9 +1,11 @@ import { + Alert, Anchor, Button, - Group, + Flex, List, Modal, + Select, Stack, Text, TextInput, @@ -13,6 +15,7 @@ import { notifications } from "@mantine/notifications"; import { useLiveQuery } from "dexie-react-hooks"; import { cloneElement, ReactElement, useEffect, useState } from "react"; import { db } from "../db"; +import { availableModels, defaultModel } from "../utils/constants"; import { checkOpenAIKey } from "../utils/openai"; export function SettingsModal({ children }: { children: ReactElement }) { @@ -20,14 +23,20 @@ export function SettingsModal({ children }: { children: ReactElement }) { const [submitting, setSubmitting] = useState(false); const [value, setValue] = useState(""); + const [model, setModel] = useState(defaultModel); - const apiKey = useLiveQuery(async () => { - return (await db.settings.where({ id: "general" }).toArray())[0]; + const settings = useLiveQuery(async () => { + return db.settings.where({ id: "general" }).first(); }); + useEffect(() => { - if (!apiKey?.openAiApiKey) return; - setValue(apiKey.openAiApiKey); - }, [apiKey]); + if (settings?.openAiApiKey) { + setValue(settings.openAiApiKey); + } + if (settings?.openAiModel) { + setModel(settings.openAiModel); + } + }, [settings]); return ( <> @@ -69,7 +78,7 @@ export function SettingsModal({ children }: { children: ReactElement }) { } }} > - + Save - + @@ -101,6 +110,21 @@ export function SettingsModal({ children }: { children: ReactElement }) { +