diff --git a/backend/Pipfile b/backend/Pipfile index 0ee5d8e..778105e 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -21,6 +21,8 @@ openai = "==1.23.2" llama-index-readers-file = "==0.1.19" httpx = "==0.27.0" pymupdf = "==1.24.2" +pydantic = {extras = ["email"], version = "==2.7.1"} +python-multipart = "==0.0.9" [dev-packages] diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock index daf1f79..26e665f 100644 --- a/backend/Pipfile.lock +++ b/backend/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "fa9c5313c4d53977c1a5dcab6a14d23e55dbe3b4ce6520fe2d0a6c957ebbeb1d" + "sha256": "65638357e5510f64031dc36b3f7368a06de6512a2f4459dfea5f802c371cc4e4" }, "pipfile-spec": 6, "requires": { @@ -309,6 +309,21 @@ "markers": "python_version >= '3.6'", "version": "==1.9.0" }, + "dnspython": { + "hashes": [ + "sha256:5ef3b9680161f6fa89daf8ad451b5f1a33b18ae8a1c6778cdf4b43f08c0a6e50", + "sha256:e8f0f9c23a7b7cb99ded64e6c3a6f3e701d78f50c55e002b839dea7225cff7cc" + ], + "markers": "python_version >= '3.8'", + "version": "==2.6.1" + }, + "email-validator": { + "hashes": [ + "sha256:200a70680ba08904be6d1eef729205cc0d687634399a5924d842533efb824b84", + "sha256:97d882d174e2a65732fb43bfce81a3a834cbc1bde8bf419e30ef5ea976370a05" + ], + "version": "==2.1.1" + }, "fastapi": { "hashes": [ "sha256:239403f2c0a3dda07a9420f95157a7f014ddb2b770acdbc984f9bdf3ead7afdb", @@ -1201,6 +1216,9 @@ "version": "==0.16.3" }, "pydantic": { + "extras": [ + "email" + ], "hashes": [ "sha256:e029badca45266732a9a79898a15ae2e8b14840b1eabbb25844be28f0b33f3d5", "sha256:e9dbb5eada8abe4d9ae5f46b9939aead650cd2b68f249bb3a8139dbe125803cc" @@ -1368,6 +1386,15 @@ "markers": "python_version >= '3.8'", "version": "==1.0.1" }, + "python-multipart": { + "hashes": [ + "sha256:03f54688c663f1b7977105f021043b0793151e4cb1c1a9d4a11fc13d622c4026", + "sha256:97ca7b8ea7b05f977dc3849c3ba99d51689822fab725c3703af7c866a0c2b215" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==0.0.9" + }, "pytz": { "hashes": [ "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812", diff --git a/backend/app/main.py b/backend/app/main.py index 54772df..3da25ac 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,11 +1,11 @@ import json from typing import List, Any -from fastapi import FastAPI, HTTPException, Depends, Body +from fastapi import FastAPI, HTTPException, Depends, Body, Form from fastapi.responses import StreamingResponse from fastapi.middleware.cors import CORSMiddleware from dotenv import load_dotenv -from pydantic import BaseModel, Field, ConfigDict +from pydantic import BaseModel, Field, ConfigDict, EmailStr from app.db import DB from app.llm import summarise_text @@ -46,15 +46,15 @@ class PageCreate(BaseModel): class Email(BaseModel): model_config = ConfigDict(populate_by_name=True) - to: str - from_: str = Field(..., alias="from") - subject: str - text: str - html: str - attachments: int - attachment_info: Any = Field(..., alias="attachment-info") - spam_score: Any - spam_report: Any + to: EmailStr = Form(...) + from_: EmailStr = Form(..., alias="from") + subject: str = Form(...) + text: str = Form(...) + html: str = Form(...) + attachments: int = Form(...) + attachment_info: Any = Form(..., alias="attachment-info") + spam_score: Any = Form(...) + spam_report: Any = Form(...) @app.get("/api/health") @@ -167,6 +167,6 @@ async def post_index_route(payload: PageCreate, user=Depends(get_current_user)): @app.post("/api/email") -async def post_index_route(payload: Any = Body(None)): +async def post_index_route(payload: Email): print(payload) return "OK"