Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from groq import Groq
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 9 |
+
client = Groq(api_key=groq_api_key)
|
| 10 |
+
|
| 11 |
+
class RequestData(BaseModel):
|
| 12 |
+
user_message: str
|
| 13 |
+
|
| 14 |
+
@app.post("/chat")
|
| 15 |
+
def chat(data: RequestData):
|
| 16 |
+
chat_completion = client.chat.completions.create(
|
| 17 |
+
messages=[
|
| 18 |
+
{"role": "system", "content": "You are a expert weather analysis agent. I will provide you historical and future data in tabular form and you have to generate insights for the given data, Also make sure that you mention any scope of natural calamities expected and stuff"},
|
| 19 |
+
{"role": "user", "content": data.user_message},
|
| 20 |
+
],
|
| 21 |
+
model="deepseek-r1-distill-qwen-32b",
|
| 22 |
+
temperature=0.5,
|
| 23 |
+
max_completion_tokens=1024,
|
| 24 |
+
top_p=1,
|
| 25 |
+
stop=None,
|
| 26 |
+
stream=False,
|
| 27 |
+
)
|
| 28 |
+
return {"response": chat_completion.choices[0].message.content}
|