Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Union
|
2 |
+
|
3 |
+
from fastapi import FastAPI
|
4 |
+
import asyncio
|
5 |
+
|
6 |
+
from groq import Groq, AsyncGroq
|
7 |
+
|
8 |
+
client = AsyncGroq(
|
9 |
+
api_key="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",
|
10 |
+
)
|
11 |
+
|
12 |
+
SYSTEM_PROMPT = """
|
13 |
+
Ты ассистент, помогай людям!
|
14 |
+
"""
|
15 |
+
|
16 |
+
app = FastAPI()
|
17 |
+
|
18 |
+
|
19 |
+
@app.post("/get_response")
|
20 |
+
async def read_root(messages: list[dict]):
|
21 |
+
messages.insert(0, {
|
22 |
+
"role": "system",
|
23 |
+
"content": SYSTEM_PROMPT
|
24 |
+
}
|
25 |
+
)
|
26 |
+
chat_completion = await client.chat.completions.create(
|
27 |
+
messages=messages,
|
28 |
+
model="llama3-70b-8192",
|
29 |
+
)
|
30 |
+
return chat_completion.choices[0].message.content
|
31 |
+
|
32 |
+
|
33 |
+
|