diff --git a/src/components/ConversationView/index.tsx b/src/components/ConversationView/index.tsx index 5a9a3d9..3f221da 100644 --- a/src/components/ConversationView/index.tsx +++ b/src/components/ConversationView/index.tsx @@ -14,7 +14,7 @@ import { useUserStore, } from "@/store"; import { Conversation, CreatorRole, Message } from "@/types"; -import { countTextTokens, generateUUID } from "@/utils"; +import { countTextTokens, generateUUID, hasFeature } from "@/utils"; import getEventEmitter from "@/utils/event-emitter"; import Header from "./Header"; import EmptyView from "../EmptyView"; @@ -290,36 +290,38 @@ const ConversationView = () => { // Emit usage update event so quota widget can update. getEventEmitter().emit("usage.update"); - // Collect system prompt - // We only collect the db prompt for the system prompt. We do not collect the intermediate - // exchange to save space since those can be derived from the previous record. - usageMessageList.push({ - id: generateUUID(), - createdAt: Date.now(), - creatorRole: CreatorRole.System, - content: dbPrompt, - } as Message); + if (hasFeature("collect")) { + // Collect system prompt + // We only collect the db prompt for the system prompt. We do not collect the intermediate + // exchange to save space since those can be derived from the previous record. + usageMessageList.push({ + id: generateUUID(), + createdAt: Date.now(), + creatorRole: CreatorRole.System, + content: dbPrompt, + } as Message); - // Collect user message - usageMessageList.push(userMessage); + // Collect user message + usageMessageList.push(userMessage); - // Collect assistant response - usageMessageList.push(assistantMessage); + // Collect assistant response + usageMessageList.push(assistantMessage); - axios - .post( - "/api/collect", - { - conversation: currentConversation, - messages: usageMessageList, - }, - { - headers: requestHeaders, - } - ) - .catch(() => { - // do nth - }); + axios + .post( + "/api/collect", + { + conversation: currentConversation, + messages: usageMessageList, + }, + { + headers: requestHeaders, + } + ) + .catch(() => { + // do nth + }); + } }; return ( diff --git a/src/pages/api/chat.ts b/src/pages/api/chat.ts index 976a647..f408c40 100644 --- a/src/pages/api/chat.ts +++ b/src/pages/api/chat.ts @@ -144,7 +144,7 @@ const handler = async (req: NextRequest) => { }, }); - if (useServerKey) { + if (useServerKey && hasFeature("quota")) { // Increment usage count await fetch(usageUrl, { method: "POST", diff --git a/src/pages/api/collect.ts b/src/pages/api/collect.ts index 1e96795..a1e68f5 100644 --- a/src/pages/api/collect.ts +++ b/src/pages/api/collect.ts @@ -1,7 +1,7 @@ import { PrismaClient } from "@prisma/client"; import { NextApiRequest, NextApiResponse } from "next"; import { Conversation, Message } from "@/types"; -import { getModel, gpt35 } from "@/utils"; +import { getModel } from "@/utils"; import { getEndUser } from "./auth/end-user"; const prisma = new PrismaClient(); diff --git a/src/utils/feature.ts b/src/utils/feature.ts index 28ce67f..2acd2ba 100644 --- a/src/utils/feature.ts +++ b/src/utils/feature.ts @@ -1,4 +1,4 @@ -type FeatureType = "debug" | "account" | "payment" | "quota"; +type FeatureType = "debug" | "account" | "payment" | "quota" | "collect"; const matrix: { [key: string]: { [feature: string]: boolean } } = { development: { @@ -6,12 +6,14 @@ const matrix: { [key: string]: { [feature: string]: boolean } } = { account: true, payment: true, quota: true, + collect: true, }, production: { debug: false, account: true, payment: true, quota: true, + collect: true, }, };