File size: 1,094 Bytes
5a0e691
 
 
 
 
 
 
 
f42f5a6
5a0e691
 
 
 
 
 
 
 
 
51ed454
5a0e691
 
 
 
 
 
 
 
51ed454
5a0e691
 
 
 
 
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
import json
import os
from fastapi import APIRouter, HTTPException, Depends
from fastapi.responses import StreamingResponse
from pydantic import BaseModel
from app.ai.interpreter import interpret_stream
from app.ai.llm_client import llm_client
from app.services.rate_limit import check_daily_limit
from app.models.responses import InterpretResponse

router = APIRouter()


class InterpretRequest(BaseModel):
    pipeline_type: str = "protein_analysis"
    context: dict = {}


@router.post("/interpret", response_model=InterpretResponse)
async def interpret_full_context(req: InterpretRequest):
    if not llm_client.has_api_key():
        raise HTTPException(status_code=502, detail="GROQ_API_KEY is not configured")

    prompt = llm_client.build_prompt(req.pipeline_type, req.context)
    return {"prompt": prompt, "context_size": len(json.dumps(req.context))}


@router.post("/interpret/stream")
async def interpret_stream_endpoint(req: InterpretRequest):
    return StreamingResponse(
        interpret_stream(req.pipeline_type, req.context),
        media_type="text/event-stream",
    )