diff --git a/app.py b/app.py index 78d8b93..727704f 100644 --- a/app.py +++ b/app.py @@ -774,12 +774,13 @@ async def chat_title(request: ChatRequest, token_info: dict = Depends(verify_tok # Get the chat model from the request and create the corresponding chat instance chat_config = model_company_mapping.get("gpt-4o-mini") - if chat_config['premium']: - if not verify_active_subscription(token_info): - raise HTTPException( - status_code=status.HTTP_403_FORBIDDEN, - detail="Forbidden", - ) + # check the number of generations left for the user + generations_left = get_generations(token_info) + if generations_left == 0: + raise HTTPException( + status_code=status.HTTP_403_FORBIDDEN, + detail="Generations limit exceeded", + ) chat = chat_config['model']( model_name="gpt-4o-mini", @@ -817,6 +818,9 @@ async def chat_title(request: ChatRequest, token_info: dict = Depends(verify_tok # Handle validation errors specifically for better user feedback logging.error("Validation error: %s", ve) raise HTTPException(status_code=400, detail="Invalid request data") from ve + except HTTPException as he: + # Handle HTTP exceptions specifically for better user feedback + raise he except Exception as e: # Log and handle generic exceptions gracefully logging.error("Error processing chat request: %s", e) diff --git a/web/public/index.html b/web/public/index.html index e1f1a93..a6b91f9 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -7,7 +7,7 @@ diff --git a/web/src/App.js b/web/src/App.js index 81d0ed4..4984cc3 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -4,6 +4,8 @@ import { LoginPage } from "./pages/LoginPage"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import { ProtectedPage } from "./pages/ProtectedPage"; import { DashboardV2 } from "./pages/DashboardV2"; +import TermsAndConditions from "./components/TermsAndConditions"; +import PrivacyPolicy from "./components/PrivacyPolicy"; @@ -48,6 +50,12 @@ function App() { } /> */} + + } /> + + } /> diff --git a/web/src/components/AiCard.js b/web/src/components/AiCard.js index d2e6f65..e394233 100644 --- a/web/src/components/AiCard.js +++ b/web/src/components/AiCard.js @@ -1,16 +1,14 @@ -import React, { useState } from 'react'; +import React, { useState, useMemo } from 'react'; import { Card, CardBody, CardFooter } from "@nextui-org/react"; -import { AiOutlineCopy, AiOutlineCheck } from 'react-icons/ai'; // Import AiOutlineReload for the retry icon +import { AiOutlineCopy, AiOutlineCheck } from 'react-icons/ai'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; -import { useTheme } from '../components/ThemeContext'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { okaidia } from 'react-syntax-highlighter/dist/esm/styles/prism'; export const AiCard = ({ message, retryComponent }) => { const [copied, setCopied] = useState(false); const [codeToCopy, setCodeToCopy] = useState(''); - const { theme } = useTheme(); const handleCopy = async () => { try { @@ -32,77 +30,77 @@ export const AiCard = ({ message, retryComponent }) => { } }; + const renderedMarkdown = useMemo(() => ( + + + + + ) : ( + + {children} + + ); + }, + }} + /> + ), [message, codeToCopy]); // Memoize based on the message and codeToCopy + + const renderedCopyButton = useMemo(() => ( + + ), [copied]); // Memoize the copy button based on the copied state + return ( - - - - - ) : ( - - {children} - - ); - }, - }} - /> + {renderedMarkdown} - {/* {showRetry && ( - - )} */} {retryComponent} - + {renderedCopyButton} ); diff --git a/web/src/components/Footer.js b/web/src/components/Footer.js index e1291a3..6a0acee 100644 --- a/web/src/components/Footer.js +++ b/web/src/components/Footer.js @@ -9,10 +9,7 @@ export const Footer = () => { © 2024 chat-with-llms. All rights reserved. This is an open-source project.