{"id":20314751,"url":"https://github.com/mazzasaverio/nextjs-fastapi-your-chat","last_synced_at":"2025-09-22T22:31:24.908Z","repository":{"id":220560467,"uuid":"751312241","full_name":"mazzasaverio/nextjs-fastapi-your-chat","owner":"mazzasaverio","description":"Chat with any website using FastAPI, Next.js, and the latest LangChain version for seamless integration.","archived":false,"fork":false,"pushed_at":"2024-02-02T18:46:00.000Z","size":224,"stargazers_count":52,"open_issues_count":1,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T18:16:31.661Z","etag":null,"topics":["api","backend","chat","chatbot","fastapi","frontend","langchain","nextjs","openai","python","vercel","vercel-deployment"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mazzasaverio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-01T11:03:54.000Z","updated_at":"2024-11-14T12:52:07.000Z","dependencies_parsed_at":"2024-02-02T19:25:38.775Z","dependency_job_id":"65121f35-b1a3-4be2-af6e-b6df34ea30dd","html_url":"https://github.com/mazzasaverio/nextjs-fastapi-your-chat","commit_stats":null,"previous_names":["mazzasaverio/nextjs-fastapi-your-chat"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Fnextjs-fastapi-your-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Fnextjs-fastapi-your-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Fnextjs-fastapi-your-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Fnextjs-fastapi-your-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazzasaverio","download_url":"https://codeload.github.com/mazzasaverio/nextjs-fastapi-your-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233895585,"owners_count":18747070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","backend","chat","chatbot","fastapi","frontend","langchain","nextjs","openai","python","vercel","vercel-deployment"],"created_at":"2024-11-14T18:16:35.225Z","updated_at":"2025-09-22T22:31:19.600Z","avatar_url":"https://github.com/mazzasaverio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js + FastAPI: Chat with Your Website\n\nThis application facilitates a chatbot by leveraging Next.js as the frontend and FastAPI as the backend, utilizing the power of LangChain for dynamic web interactions.\n\n![Chatbot Interface](images/chatbot.png)\n\n## Features of the Hybrid App\n\n- **Web Interaction via LangChain**: Utilizes the latest LangChain version for effective interaction and information extraction from websites.\n- **Versatile Language Model Integration**: Offers compatibility with various models including GPT-4. Users can easily switch between models to suit their needs.\n- **User-Friendly Next.js Frontend**: The interface is intuitive and accessible for users of all technical backgrounds.\n\n## Operational Mechanics\n\nThe application integrates the Python/FastAPI server into the Next.js app under the `/api/` route. This is achieved through [`next.config.js` rewrites](https://github.com/digitros/nextjs-fastapi/blob/main/next.config.js), directing any `/api/:path*` requests to the FastAPI server located in the `/api` folder. Locally, FastAPI runs on `127.0.0.1:8000`, while in production, it operates as serverless functions on Vercel.\n\n## Setting Up the Application\n\n1. Install dependencies:\n   ```bash\n   npm install\n   ```\n2. Create a `.env` file with your OpenAI API key:\n   ```\n   OPENAI_API_KEY=[your-openai-api-key]\n   ```\n3. Start the development server:\n   ```bash\n   npm run dev\n   ```\n4. Access the application at [http://localhost:3000](http://localhost:3000). The FastAPI server runs on [http://127.0.0.1:8000](http://127.0.0.1:8000).\n\nFor backend-only testing:\n\n```bash\nconda create --name nextjs-fastapi-your-chat python=3.10\nconda activate nextjs-fastapi-your-chat\npip install -r requirements.txt\nuvicorn api.index:app --reload\n```\n\n## Maintaining Chat History (TODO List)\n\nOptions for preserving chat history include:\n\n- **Global Variable**: Simple but not ideal for scalability and consistency.\n- **In-Memory Database/Cache**: Scalable solutions like Redis for storing chat history.\n- **Database Storage**: Robust and persistent method, suitable for production environments.\n\n## Understanding RAG Algorithms\n\nRAG (Retrieval Augmented Generation) enhances language models with context retrieved from a custom knowledge base. The process involves fetching HTML documents, splitting them into chunks, and vectorizing these chunks using embedding models like OpenAI's. This vectorized data forms a vector store, enabling semantic searches based on user queries. The retrieved relevant chunks are then used as context for the language model, forming a comprehensive response to user inquiries.\n\n## Implementing Context Retrieval\n\nThe `get_vectorstore_from_url` function extracts and processes text from a given URL, while `get_context_retriever_chain` forms a chain that retrieves context relevant to the entire conversation history. This pipeline approach ensures that responses are contextually aware and accurate.\n\n## Inspiration and References\n\n- [chat-with-websites](https://github.com/alejandro-ao/chat-with-websites)\n- [next13-ai-saas](https://github.com/AntonioErdeljac/next13-ai-saas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazzasaverio%2Fnextjs-fastapi-your-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazzasaverio%2Fnextjs-fastapi-your-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazzasaverio%2Fnextjs-fastapi-your-chat/lists"}