Skip to content

Commit

Permalink
feat: 기본 모델 gpt4o로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonghakseo committed Jul 6, 2024
1 parent 120008f commit 4f7bfe4
Show file tree
Hide file tree
Showing 16 changed files with 7,188 additions and 48 deletions.
7,132 changes: 7,132 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"slotDetail_temperatureTitle": {
"message": "Randomness (temperature: 0~2)"
},
"slotDetail_isGpt4": {
"message": "Use GPT4 (default: 3.5)"
"slotDetail_isGpt4Turbo": {
"message": "Use gpt4-turbo (default: gpt4o)"
},
"slotDetail_saveButtonText": {
"message": "Save"
Expand Down
4 changes: 2 additions & 2 deletions public/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"slotDetail_temperatureTitle": {
"message": "ランダム性(temperature:0~2)"
},
"slotDetail_isGpt4": {
"message": "GPT4の使用(デフォルト:3.5"
"slotDetail_isGpt4Turbo": {
"message": "gpt4Turboの使用(デフォルト:gpt4o"
},
"slotDetail_saveButtonText": {
"message": "保存"
Expand Down
4 changes: 2 additions & 2 deletions public/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"slotDetail_temperatureTitle": {
"message": "무작위성 (temperature: 0~2)"
},
"slotDetail_isGpt4": {
"message": "GPT4 사용 (기본값: 3.5)"
"slotDetail_isGpt4Turbo": {
"message": "GPT4Turbo 사용 (기본값: gpt4o)"
},
"slotDetail_saveButtonText": {
"message": "저장"
Expand Down
4 changes: 2 additions & 2 deletions public/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"slotDetail_temperatureTitle": {
"message": "随机性(温度:0~2)"
},
"slotDetail_isGpt4": {
"message": "使用 GPT4(默认值:3.5"
"slotDetail_isGpt4Turbo": {
"message": "使用 GPT4Turbo(默认值:gpt4o"
},
"slotDetail_saveButtonText": {
"message": "保存"
Expand Down
4 changes: 2 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare module "*.json" {

declare global {
type ChatGPTSlot = {
type: "ChatGPT" | "ChatGPT4";
type: "gpt4-turbo" | "gpt4o";
system?: string;
/** config */
maxTokens?: number; // max 4000
Expand Down Expand Up @@ -108,7 +108,7 @@ declare global {
type: "RequestQuickChatGPTStream";
input?: {
messages: Chat[];
isGpt4: boolean;
isGpt4Turbo: boolean;
};
data?: { result: string; chunk?: string; isDone?: boolean };
};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ chrome.runtime.onConnect.addListener((port) => {
await chatGPT({
input: "hello",
apiKey: message.input,
slot: { type: "ChatGPT" },
slot: { type: "gpt4o" },
}).catch((error) => {
ApiKeyStorage.setApiKey(null);
throw error;
Expand Down Expand Up @@ -143,7 +143,7 @@ chrome.runtime.onConnect.addListener((port) => {
const apiKey = await ApiKeyStorage.getApiKey();
const response = await chatGPT({
chats: message.input?.messages,
slot: { type: message.input?.isGpt4 ? "ChatGPT4" : "ChatGPT" },
slot: { type: message.input?.isGpt4Turbo ? "gpt4-turbo" : "gpt4o" },
apiKey,
onDelta: (chunk) => {
sendResponse({
Expand Down Expand Up @@ -204,7 +204,7 @@ chrome.runtime.onConnect.addListener((port) => {
const response = await chatGPT({
input: message.input,
slot: {
type: "ChatGPT",
type: "gpt4o",
system: PROMPT_GENERATE_PROMPT,
},
apiKey,
Expand Down
5 changes: 2 additions & 3 deletions src/pages/background/lib/infra/chatGPT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function chatGPT({
}

let response = await requestApi(apiKey, {
model: slot.type === "ChatGPT" ? "gpt-3.5-turbo" : "gpt-4",
model: slot.type === "gpt4-turbo" ? "gpt-4-turbo" : "gpt-4o",
max_tokens: slot.maxTokens,
messages,
stream: true,
Expand All @@ -51,8 +51,7 @@ export async function chatGPT({

await handleError(response, async () => {
response = await requestApi(apiKey, {
model:
slot.type === "ChatGPT" ? "gpt-3.5-turbo-0125" : "gpt-4-turbo-preview",
model: slot.type === "gpt4-turbo" ? "gpt-4-turbo" : "gpt-4o",
max_tokens: slot.maxTokens,
messages,
stream: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultSlot: Slot = {
id: "1",
name: "name",
isSelected: false,
type: "ChatGPT",
type: "gpt4o",
};

describe("SlotsManipulator test", () => {
Expand Down
14 changes: 7 additions & 7 deletions src/pages/background/lib/storage/slotStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("SlotStorage test", () => {
test("선택된 슬롯이 없으면 에러가 발생한다", async () => {
// given
const savedSlots: Slot[] = [
{ type: "ChatGPT", id: "id", name: "name", isSelected: false },
{ type: "gpt4o", id: "id", name: "name", isSelected: false },
];
jest
.spyOn(SlotStorage, "getAllSlots")
Expand All @@ -76,7 +76,7 @@ describe("SlotStorage test", () => {
test("선택된 슬롯이 있으면 가져온다", async () => {
// given
const savedSelectedSlot: Slot = {
type: "ChatGPT",
type: "gpt4o",
id: "id",
name: "name",
isSelected: true,
Expand All @@ -99,7 +99,7 @@ describe("SlotStorage test", () => {
// given
const savedSlots: Slot[] = [];
const slot: Slot = {
type: "ChatGPT",
type: "gpt4o",
id: "id",
name: "name",
isSelected: false,
Expand All @@ -121,14 +121,14 @@ describe("SlotStorage test", () => {
// given
const savedSlots: Slot[] = [
{
type: "ChatGPT",
type: "gpt4o",
id: "id1",
name: "name",
isSelected: false,
},
];
const slot: Slot = {
type: "ChatGPT",
type: "gpt4o",
id: "id2",
name: "name",
isSelected: false,
Expand All @@ -150,7 +150,7 @@ describe("SlotStorage test", () => {
test("updateSlot", async () => {
// given
const slot: Slot = {
type: "ChatGPT",
type: "gpt4o",
id: "id",
name: "name",
isSelected: false,
Expand All @@ -175,7 +175,7 @@ describe("SlotStorage test", () => {
// given
const slotId = "slotId";
const slot: Slot = {
type: "ChatGPT",
type: "gpt4o",
id: slotId,
name: "name",
isSelected: false,
Expand Down
12 changes: 6 additions & 6 deletions src/pages/popup/components/SlotDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function SlotDetail({
exitDetail,
}: SlotDetailProps) {
const [slot, setSlot] = useState(initialSlot);
const isGpt4 = slot.type === "ChatGPT4";
const isGpt4Turbo = slot.type === "gpt4-turbo";

const onSaveButtonClick = () => {
onUpdate(slot);
Expand All @@ -48,9 +48,9 @@ export default function SlotDetail({
}));
};

const toggleGpt4Switch = () => {
updateSlot("type", isGpt4 ? "ChatGPT" : "ChatGPT4");
console.log(isGpt4, slot);
const toggleGpt4TurboSwitch = () => {
updateSlot("type", isGpt4Turbo ? "gpt4-turbo" : "gpt4o");
console.log(isGpt4Turbo, slot);
};

return (
Expand Down Expand Up @@ -107,9 +107,9 @@ export default function SlotDetail({
whiteSpace="pre-wrap"
fontSize={12}
>
{t("slotDetail_isGpt4")}
{t("slotDetail_isGpt4Turbo")}
</Text>
<Switch isChecked={isGpt4} onChange={toggleGpt4Switch} />
<Switch isChecked={isGpt4Turbo} onChange={toggleGpt4TurboSwitch} />
</HStack>
<HStack paddingTop={4} width="100%" justifyContent="space-between">
<StyledButton onClick={onSaveButtonClick} colorScheme="blue">
Expand Down
6 changes: 3 additions & 3 deletions src/pages/popup/pages/QuickChattingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function QuickChattingPage({
},
getGPTResponse: (context) => {
return getQuickGPTResponseAsStream({
isGpt4: context.isGpt4,
isGpt4Turbo: context.isGpt4Turbo,
messages: context.chats,
onDelta: (chunk) => {
send("RECEIVE_ING", { data: chunk });
Expand Down Expand Up @@ -165,8 +165,8 @@ export default function QuickChattingPage({
</FormLabel>
<Switch
id="is-gpt4-switch"
isChecked={state.context.isGpt4}
onChange={() => send("TOGGLE_IS_GPT4")}
isChecked={state.context.isGpt4Turbo}
onChange={() => send("TOGGLE_IS_GPT4_TURBO")}
/>
</HStack>
<HStack justifyContent="end">
Expand Down
6 changes: 3 additions & 3 deletions src/shared/services/getGPTResponseAsStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { sendMessageToBackground } from "@src/chrome/message";

export async function getQuickGPTResponseAsStream({
messages,
isGpt4,
isGpt4Turbo,
onDelta,
onFinish,
}: {
messages: Chat[];
isGpt4: boolean;
isGpt4Turbo: boolean;
onDelta: (chunk: string) => unknown;
onFinish: (result: string) => unknown;
}) {
Expand All @@ -16,7 +16,7 @@ export async function getQuickGPTResponseAsStream({
const { disconnect } = sendMessageToBackground({
message: {
type: "RequestQuickChatGPTStream",
input: { messages, isGpt4 },
input: { messages, isGpt4Turbo },
},
handleSuccess: (response) => {
if (response.isDone || !response.chunk) {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/slot/createNewChatGPTSlot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function createNewChatGPTSlot(config?: Partial<Slot>): Slot {
return {
type: "ChatGPT",
type: "gpt4o",
isSelected: false,
id: generateId(),
name: "",
Expand Down
29 changes: 19 additions & 10 deletions src/shared/xState/streamChatStateMachine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { assign, createMachine } from "xstate";

type Events =
| { type: "EXIT" | "QUERY" | "RESET" | "RECEIVE_CANCEL" | "TOGGLE_IS_GPT4" }
| {
type:
| "EXIT"
| "QUERY"
| "RESET"
| "RECEIVE_CANCEL"
| "TOGGLE_IS_GPT4_TURBO";
}
| { type: "CHANGE_TEXT"; data: string }
| { type: "RECEIVE_ING"; data: string }
| { type: "RECEIVE_DONE"; data: string };
Expand All @@ -10,7 +17,7 @@ interface Context {
inputText: string;
chats: Chat[];
tempResponse: string;
isGpt4: boolean;
isGpt4Turbo: boolean;
error?: Error;
cancelReceive?: () => unknown;
}
Expand All @@ -28,7 +35,7 @@ const initialContext: Context = {
inputText: "",
chats: [],
tempResponse: "",
isGpt4: false,
isGpt4Turbo: false,
};

const streamChatStateMachine = createMachine(
Expand Down Expand Up @@ -63,8 +70,8 @@ const streamChatStateMachine = createMachine(
CHANGE_TEXT: {
actions: "updateChatText",
},
TOGGLE_IS_GPT4: {
actions: "toggleIsGpt4",
TOGGLE_IS_GPT4_TURBO: {
actions: "toggleIsGpt4Turbo",
},
},
},
Expand All @@ -83,8 +90,8 @@ const streamChatStateMachine = createMachine(
CHANGE_TEXT: {
actions: "updateChatText",
},
TOGGLE_IS_GPT4: {
actions: "toggleIsGpt4",
TOGGLE_IS_GPT4_TURBO: {
actions: "toggleIsGpt4Turbo",
},
},
},
Expand All @@ -96,8 +103,8 @@ const streamChatStateMachine = createMachine(
CHANGE_TEXT: {
actions: "updateChatText",
},
TOGGLE_IS_GPT4: {
actions: "toggleIsGpt4",
TOGGLE_IS_GPT4_TURBO: {
actions: "toggleIsGpt4Turbo",
},
},
},
Expand Down Expand Up @@ -169,7 +176,9 @@ const streamChatStateMachine = createMachine(
inputText: () => "",
}),
resetChatData: assign({ chats: () => [] }),
toggleIsGpt4: assign({ isGpt4: (context) => !context.isGpt4 }),
toggleIsGpt4Turbo: assign({
isGpt4Turbo: (context) => !context.isGpt4Turbo,
}),
},
guards: {
isValidText: (context) => context.inputText.length > 0,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/xState/streamChatStateMachine.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface Typegen0 {
resetChatText: "QUERY";
setCancelReceive: "done.invoke.stream-chat-state.loading:invocation[0]";
setChats: "done.invoke.stream-chat-state.init:invocation[0]";
toggleIsGpt4: "TOGGLE_IS_GPT4";
toggleIsGpt4Turbo: "TOGGLE_IS_GPT4_TURBO";
updateChatText: "CHANGE_TEXT";
};
eventsCausingDelays: {};
Expand Down

0 comments on commit 4f7bfe4

Please sign in to comment.