File size: 1,025 Bytes
b554ca5
 
 
 
 
 
8a1317a
 
 
b554ca5
1241903
 
 
 
 
 
9b330cf
 
9914e5e
 
1241903
 
b554ca5
8a1317a
 
 
b554ca5
 
 
 
 
 
 
 
 
 
 
 
214baa8
b554ca5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.security import APIKeyHeader

from src.services import summarize_note, assign_tag, analyze_sentiment


app = FastAPI()


API_KEY_NAME = "X-API-KEY"
API_KEY = os.environ.get("API_KEY")
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)


async def get_api_key(api_key: str = Depends(api_key_header)):
    print(f"Received API Key: {api_key}")
    print(f"Expected API Key from environment: {API_KEY}")
    # if api_key != API_KEY:
    #     raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid API Key")
    return api_key


@app.get("/")
def health_check():
    return {"status": "ok"}



@app.post("/ai/analyze")
def analyze_note(note_data: dict, api_key: str = Depends(get_api_key)):
    summary = summarize_note(note_data)
    tag = assign_tag(note_data)
    sentiment = analyze_sentiment(note_data)

    return {
        "summary": summary,
        "tag": tag,
        "sentiment": sentiment
    }