mirror of
https://github.com/coaidev/coai.git
synced 2025-05-24 15:30:15 +09:00
update gpt3.5turbo, gpt3.5turbo-16k, gpt4, gpt4-32k select group and fix import cycle
This commit is contained in:
parent
653a90bd08
commit
402ee8b52c
@ -4,9 +4,9 @@ import { AnonymousProps, requestAnonymous } from "./anonymous.ts";
|
|||||||
|
|
||||||
type ConversationCallback = (idx: number, message: Message[]) => void;
|
type ConversationCallback = (idx: number, message: Message[]) => void;
|
||||||
export type SendMessageProps = {
|
export type SendMessageProps = {
|
||||||
|
model: string;
|
||||||
message: string;
|
message: string;
|
||||||
web?: boolean;
|
web?: boolean;
|
||||||
gpt4?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Conversation {
|
export class Conversation {
|
||||||
|
@ -73,6 +73,7 @@ export class Manager {
|
|||||||
auth: boolean,
|
auth: boolean,
|
||||||
props: SendMessageProps,
|
props: SendMessageProps,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
props.model = props.model.trim().toLowerCase();
|
||||||
const id = this.getCurrent();
|
const id = this.getCurrent();
|
||||||
if (!this.conversations[id]) return false;
|
if (!this.conversations[id]) return false;
|
||||||
console.debug(
|
console.debug(
|
||||||
|
@ -12,8 +12,6 @@ import {
|
|||||||
Trash2,
|
Trash2,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { Button } from "../components/ui/button.tsx";
|
import { Button } from "../components/ui/button.tsx";
|
||||||
import { Switch } from "../components/ui/switch.tsx";
|
|
||||||
import { Label } from "../components/ui/label.tsx";
|
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
@ -37,15 +35,15 @@ import {
|
|||||||
useAnimation,
|
useAnimation,
|
||||||
useEffectAsync,
|
useEffectAsync,
|
||||||
} from "../utils.ts";
|
} from "../utils.ts";
|
||||||
import { useToast } from "../components/ui/use-toast.ts";
|
import {toast, useToast} from "../components/ui/use-toast.ts";
|
||||||
import { ConversationInstance, Message } from "../conversation/types.ts";
|
import { ConversationInstance, Message } from "../conversation/types.ts";
|
||||||
import {
|
import {
|
||||||
selectCurrent,
|
selectCurrent,
|
||||||
selectGPT4,
|
selectModel,
|
||||||
selectHistory,
|
selectHistory,
|
||||||
selectMessages,
|
selectMessages,
|
||||||
selectWeb,
|
selectWeb,
|
||||||
setGPT4,
|
setModel,
|
||||||
setWeb,
|
setWeb,
|
||||||
} from "../store/chat.ts";
|
} from "../store/chat.ts";
|
||||||
import {
|
import {
|
||||||
@ -64,6 +62,7 @@ import MessageSegment from "../components/Message.tsx";
|
|||||||
import { setMenu } from "../store/menu.ts";
|
import { setMenu } from "../store/menu.ts";
|
||||||
import FileProvider, { FileObject } from "../components/FileProvider.tsx";
|
import FileProvider, { FileObject } from "../components/FileProvider.tsx";
|
||||||
import router from "../router.ts";
|
import router from "../router.ts";
|
||||||
|
import SelectGroup from "../components/SelectGroup.tsx";
|
||||||
|
|
||||||
function SideBar() {
|
function SideBar() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -281,7 +280,7 @@ function ChatWrapper() {
|
|||||||
const [clearEvent, setClearEvent] = useState<() => void>(() => {});
|
const [clearEvent, setClearEvent] = useState<() => void>(() => {});
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const auth = useSelector(selectAuthenticated);
|
const auth = useSelector(selectAuthenticated);
|
||||||
const gpt4 = useSelector(selectGPT4);
|
const model = useSelector(selectModel);
|
||||||
const web = useSelector(selectWeb);
|
const web = useSelector(selectWeb);
|
||||||
const messages = useSelector(selectMessages);
|
const messages = useSelector(selectMessages);
|
||||||
const target = useRef(null);
|
const target = useRef(null);
|
||||||
@ -291,13 +290,13 @@ function ChatWrapper() {
|
|||||||
clearEvent?.();
|
clearEvent?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSend(auth: boolean, gpt4: boolean, web: boolean) {
|
async function handleSend(auth: boolean, model: string, web: boolean) {
|
||||||
// because of the function wrapper, we need to update the selector state using props.
|
// because of the function wrapper, we need to update the selector state using props.
|
||||||
if (!target.current) return;
|
if (!target.current) return;
|
||||||
const el = target.current as HTMLInputElement;
|
const el = target.current as HTMLInputElement;
|
||||||
const message: string = formatMessage(file, el.value);
|
const message: string = formatMessage(file, el.value);
|
||||||
if (message.length > 0 && el.value.trim().length > 0) {
|
if (message.length > 0 && el.value.trim().length > 0) {
|
||||||
if (await manager.send(t, auth, { message, web, gpt4 })) {
|
if (await manager.send(t, auth, { message, web, model })) {
|
||||||
clearFile();
|
clearFile();
|
||||||
el.value = "";
|
el.value = "";
|
||||||
}
|
}
|
||||||
@ -351,7 +350,7 @@ function ChatWrapper() {
|
|||||||
ref={target}
|
ref={target}
|
||||||
placeholder={t("chat.placeholder")}
|
placeholder={t("chat.placeholder")}
|
||||||
onKeyDown={async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
onKeyDown={async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === "Enter") await handleSend(auth, gpt4, web);
|
if (e.key === "Enter") await handleSend(auth, model, web);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{auth && (
|
{auth && (
|
||||||
@ -368,7 +367,7 @@ function ChatWrapper() {
|
|||||||
size={`icon`}
|
size={`icon`}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={`send-button`}
|
className={`send-button`}
|
||||||
onClick={() => handleSend(auth, gpt4, web)}
|
onClick={() => handleSend(auth, model, web)}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
className="h-4 w-4"
|
className="h-4 w-4"
|
||||||
@ -383,12 +382,18 @@ function ChatWrapper() {
|
|||||||
</div>
|
</div>
|
||||||
<div className={`input-options`}>
|
<div className={`input-options`}>
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<Switch
|
<SelectGroup
|
||||||
disabled={!auth}
|
current={model}
|
||||||
id="enable-gpt4"
|
list={["GPT-3.5", "GPT-3.5-16k", "GPT-4", "GPT-4-32k"]}
|
||||||
onCheckedChange={(state: boolean) => dispatch(setGPT4(state))}
|
onChange={(model: string) => {
|
||||||
|
if (!auth && model !== "GPT-3.5") {
|
||||||
|
toast({
|
||||||
|
title: t("login-required"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
dispatch(setModel(model));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Label htmlFor="enable-gpt4">GPT-4</Label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,7 +7,7 @@ import { RootState } from "./index.ts";
|
|||||||
type initialStateType = {
|
type initialStateType = {
|
||||||
history: ConversationInstance[];
|
history: ConversationInstance[];
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
gpt4: boolean;
|
model: string;
|
||||||
web: boolean;
|
web: boolean;
|
||||||
current: number;
|
current: number;
|
||||||
};
|
};
|
||||||
@ -17,7 +17,7 @@ const chatSlice = createSlice({
|
|||||||
initialState: {
|
initialState: {
|
||||||
history: [],
|
history: [],
|
||||||
messages: [],
|
messages: [],
|
||||||
gpt4: false,
|
model: "GPT-3.5",
|
||||||
web: true,
|
web: true,
|
||||||
current: -1,
|
current: -1,
|
||||||
} as initialStateType,
|
} as initialStateType,
|
||||||
@ -43,8 +43,8 @@ const chatSlice = createSlice({
|
|||||||
setMessages: (state, action) => {
|
setMessages: (state, action) => {
|
||||||
state.messages = action.payload as Message[];
|
state.messages = action.payload as Message[];
|
||||||
},
|
},
|
||||||
setGPT4: (state, action) => {
|
setModel: (state, action) => {
|
||||||
state.gpt4 = action.payload as boolean;
|
state.model = action.payload as string;
|
||||||
},
|
},
|
||||||
setWeb: (state, action) => {
|
setWeb: (state, action) => {
|
||||||
state.web = action.payload as boolean;
|
state.web = action.payload as boolean;
|
||||||
@ -67,7 +67,7 @@ export const {
|
|||||||
addHistory,
|
addHistory,
|
||||||
setCurrent,
|
setCurrent,
|
||||||
setMessages,
|
setMessages,
|
||||||
setGPT4,
|
setModel,
|
||||||
setWeb,
|
setWeb,
|
||||||
addMessage,
|
addMessage,
|
||||||
setMessage,
|
setMessage,
|
||||||
@ -76,7 +76,7 @@ export const selectHistory = (state: RootState): ConversationInstance[] =>
|
|||||||
state.chat.history;
|
state.chat.history;
|
||||||
export const selectMessages = (state: RootState): Message[] =>
|
export const selectMessages = (state: RootState): Message[] =>
|
||||||
state.chat.messages;
|
state.chat.messages;
|
||||||
export const selectGPT4 = (state: RootState): boolean => state.chat.gpt4;
|
export const selectModel = (state: RootState): string => state.chat.model;
|
||||||
export const selectWeb = (state: RootState): boolean => state.chat.web;
|
export const selectWeb = (state: RootState): boolean => state.chat.web;
|
||||||
export const selectCurrent = (state: RootState): number => state.chat.current;
|
export const selectCurrent = (state: RootState): number => state.chat.current;
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import "chat/utils"
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GPT3Turbo = "gpt-3.5-turbo"
|
GPT3Turbo = "gpt-3.5-turbo"
|
||||||
GPT3Turbo0613 = "gpt-3.5-turbo-0613"
|
GPT3Turbo0613 = "gpt-3.5-turbo-0613"
|
||||||
@ -42,10 +40,19 @@ var GPT432kArray = []string{
|
|||||||
GPT432k0613,
|
GPT432k0613,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func in(value string, slice []string) bool {
|
||||||
|
for _, item := range slice {
|
||||||
|
if item == value {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func IsGPT4Model(model string) bool {
|
func IsGPT4Model(model string) bool {
|
||||||
return utils.Contains(model, GPT4Array) || utils.Contains(model, GPT432kArray)
|
return in(model, GPT4Array) || in(model, GPT432kArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsGPT3TurboModel(model string) bool {
|
func IsGPT3TurboModel(model string) bool {
|
||||||
return utils.Contains(model, GPT3TurboArray) || utils.Contains(model, GPT3Turbo16kArray)
|
return in(model, GPT3TurboArray) || in(model, GPT3Turbo16kArray)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user