| from fastapi import FastAPI, HTTPException |
| from pydantic import BaseModel |
| from utils import get_mongo_collection, groq_calls |
| from groq import Groq |
| from dotenv import load_dotenv |
| import os |
| import random |
| import uvicorn |
| from bson import ObjectId |
|
|
| load_dotenv() |
|
|
|
|
|
|
| app = FastAPI(title="Mind Dump Summariser") |
|
|
| class ReportRequest(BaseModel): |
| user_id: str |
| username: str |
|
|
|
|
|
|
| @app.post("/cron_schedulerbot") |
| async def cron_test(): |
| return "Hello Cron Tester" |
|
|
|
|
|
|
| @app.post("/mindDump") |
| async def generate_report(request: ReportRequest): |
| try: |
| userid = request.user_id |
| username = request.username |
| journalcollection = get_mongo_collection() |
| cursor = journalcollection.find({"type":"mind_dump","userId":userid}).sort("createdAt",-1).limit(1) |
| original = "" |
| for item in cursor: |
| if item["content"].get('original'): |
| |
| original = item["content"].get('original') |
|
|
| print(original) |
| |
| prompt = f""" |
| I am giving you the complete mind dump as written by the user :{original} |
| You can greet and address him with his name: {username} |
| Now you are working as a keen oberserver who can identify patterns among a series of entangled thoughts |
| SO basically there are multiple knots that will be present inside the user's mind. ALl of that he has written in the mind dump |
| Now starting from start to finish and linking multiple parts in proper series you have to tell user what he has been expriencing |
| You need to untie those knots identifying the problems adn what could possibly be causing them |
| You should not bring rememdies or solution externally, whatever you say to the user has to be from what he has written in the mind dump section |
| Remember, you're not being asked as a chatbot, you'll have to run just one time and hence whatever output you give should be complete in it's own sense |
| You shouldn't ask questions or further clarifications. |
| |
| """ |
|
|
| final = groq_calls(prompt) |
|
|
| return {"Summary points": final} |
|
|
| except Exception as e: |
| raise HTTPException(status_code=500, detail=str(e)) |
| |
| if __name__ == "__main__": |
| uvicorn.run(app, host="0.0.0.0", port=8000) |
|
|