From ee042d9dbe25300958499d47253d62ef813d8d1b Mon Sep 17 00:00:00 2001 From: DirkSchlossmacher <62424946+DirkSchlossmacher@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:37:21 +0100 Subject: [PATCH] no req --- app/client/platforms/openai.ts | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 4ff0ea395..fbcd48290 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -29,6 +29,10 @@ import { incrementAPICallCount } from '../../utils/cloud/redisRestClient'; // app\client\platforms\openai.ts // app\auth.ts +export async function getMyServerSession() { + return await getServerAuthSession(); +} + export interface OpenAIListModelResponse { @@ -109,31 +113,27 @@ export class ChatGPTApi implements LLMApi { - const modelIdentifier = modelConfig.model; + const modelIdentifier = modelConfig.model; + console.log("API Call: session or email is not available - model: ", modelIdentifier); + + const session = await getMyServerSession(req); + + if (session?.user?.email) { + // Now you have the user's email from the session + const userEmail = session.user.email; + + const dateKey = new Date().toISOString().slice(0, 7); // "YYYY-MM" + console.log("API Call: ", userEmail, modelIdentifier); + + // Use the userEmail to increment the API call count + await incrementAPICallCount(userEmail, modelIdentifier, dateKey); + + } else { + // Handle cases where the session or email is not available console.log("API Call: session or email is not available - model: ", modelIdentifier); - export default async function handler(req, res) { - const session = await getServerAuthSession({ req }); + } - - if (session?.user?.email) { - // Now you have the user's email from the session - const userEmail = session.user.email; - - const dateKey = new Date().toISOString().slice(0, 7); // "YYYY-MM" - console.log("API Call: ", userEmail, modelIdentifier); - - // Use the userEmail to increment the API call count - await incrementAPICallCount(userEmail, modelIdentifier, dateKey); - - // ... rest of your API route logic ... - res.status(200).json({ success: true }); - } else { - // Handle cases where the session or email is not available - console.log("API Call: session or email is not available - model: ", modelIdentifier); - res.status(401).json({ error: "Unauthorized" }); - } - } /* // export default async function handler(req: NextApiRequest, res: NextApiResponse) { // Retrieve the session using getServerAuthSession