Update run.py
#10
by Yasirkrauf - opened
run.py
CHANGED
|
@@ -1,17 +1,31 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
yield "You typed: " + message[: i + 1]
|
| 8 |
|
| 9 |
-
demo = gr.ChatInterface(
|
| 10 |
-
slow_echo,
|
| 11 |
-
flagging_mode="manual",
|
| 12 |
-
flagging_options=["Like", "Spam", "Inappropriate", "Other"],
|
| 13 |
-
save_history=True,
|
| 14 |
-
)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import PlainTextResponse
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
+
GROQ_API_KEY = "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"
|
| 7 |
+
GROQ_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 8 |
+
MODEL = "llama-3.3-70b-versatile"
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
+
class DiagnoseRequest(BaseModel):
|
| 14 |
+
workflow_description: str
|
| 15 |
+
|
| 16 |
+
@app.post("/diagnose", response_class=PlainTextResponse)
|
| 17 |
+
def diagnose(req: DiagnoseRequest):
|
| 18 |
+
headers = {
|
| 19 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 20 |
+
"Content-Type": "application/json",
|
| 21 |
+
}
|
| 22 |
+
payload = {
|
| 23 |
+
"model": MODEL,
|
| 24 |
+
"messages": [
|
| 25 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 26 |
+
{"role": "user", "content": req.workflow_description},
|
| 27 |
+
],
|
| 28 |
+
}
|
| 29 |
+
resp = requests.post(GROQ_URL, headers=headers, json=payload, timeout=60)
|
| 30 |
+
resp.raise_for_status()
|
| 31 |
+
return resp.json()["choices"][0]["message"]["content"]
|