| 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"] |