File size: 955 Bytes
e72a470
 
 
 
af23863
e72a470
 
 
7020577
af23863
e72a470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse
from pydantic import BaseModel
import requests

GROQ_API_KEY = "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"
GROQ_URL = "https://api.groq.com/openai/v1/chat/completions"
MODEL = "llama-3.3-70b-versatile"


app = FastAPI()

class DiagnoseRequest(BaseModel):
    workflow_description: str

@app.post("/diagnose", response_class=PlainTextResponse)
def diagnose(req: DiagnoseRequest):
    headers = {
        "Authorization": f"Bearer {GROQ_API_KEY}",
        "Content-Type": "application/json",
    }
    payload = {
        "model": MODEL,
        "messages": [
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": req.workflow_description},
        ],
    }
    resp = requests.post(GROQ_URL, headers=headers, json=payload, timeout=60)
    resp.raise_for_status()
    return resp.json()["choices"][0]["message"]["content"]