Spaces:
Running
Running
Commit Β·
09fa85f
1
Parent(s): 6960d63
- routers/llm_router.py +25 -7
routers/llm_router.py
CHANGED
|
@@ -5,6 +5,7 @@ import requests
|
|
| 5 |
from fastapi import APIRouter, Form, File, UploadFile
|
| 6 |
from utils.common import CommonResponse
|
| 7 |
from utils.db import get_connection
|
|
|
|
| 8 |
|
| 9 |
router = APIRouter(
|
| 10 |
prefix="/llm",
|
|
@@ -12,8 +13,14 @@ router = APIRouter(
|
|
| 12 |
)
|
| 13 |
|
| 14 |
@router.post("/askllm")
|
| 15 |
-
def test_home(userquery: str = Form("")
|
|
|
|
| 16 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
with get_connection() as conn:
|
| 18 |
with conn.cursor() as cur:
|
| 19 |
cur.execute("""
|
|
@@ -55,15 +62,26 @@ def test_home(userquery: str = Form("")):
|
|
| 55 |
{
|
| 56 |
"role": "system",
|
| 57 |
"content": """
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
},
|
| 64 |
{
|
| 65 |
"role": "user",
|
| 66 |
-
"content":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
],
|
| 69 |
"temperature": 0.8,
|
|
|
|
| 5 |
from fastapi import APIRouter, Form, File, UploadFile
|
| 6 |
from utils.common import CommonResponse
|
| 7 |
from utils.db import get_connection
|
| 8 |
+
import json
|
| 9 |
|
| 10 |
router = APIRouter(
|
| 11 |
prefix="/llm",
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
@router.post("/askllm")
|
| 16 |
+
def test_home(userquery: str = Form("")
|
| 17 |
+
, selected_cards:str = Form("[]") ):
|
| 18 |
try:
|
| 19 |
+
cards=json.loads(selected_cards)
|
| 20 |
+
card_text = "\n".join([
|
| 21 |
+
f"- {card['position']} μμΉ: {card['name']} / {'μλ°©ν₯' if card['reversed'] else 'μ λ°©ν₯'}"
|
| 22 |
+
for card in cards
|
| 23 |
+
])
|
| 24 |
with get_connection() as conn:
|
| 25 |
with conn.cursor() as cur:
|
| 26 |
cur.execute("""
|
|
|
|
| 62 |
{
|
| 63 |
"role": "system",
|
| 64 |
"content": """
|
| 65 |
+
λΉμ μ μΉμ ν νλ‘ μλ΄μ¬μ
λλ€.
|
| 66 |
+
λ°λμ νκ΅μ΄λ‘ λ΅λ³νμΈμ.
|
| 67 |
+
λ΅λ³μ 5λ¬Έμ₯ μ΄λ΄λ‘ μ§§κ² νμΈμ.
|
| 68 |
+
볡μ‘ν μ€λͺ
μ νμ§ λ§μΈμ.
|
| 69 |
+
|
| 70 |
+
μ¬μ©μκ° μ νν μΉ΄λλ κ³Όκ±°, νμ¬, λ―Έλ μμμ
λλ€.
|
| 71 |
+
κ° μΉ΄λμ μ λ°©ν₯/μλ°©ν₯ μλ―Έλ₯Ό λ°μν΄μ λ΅λ³νμΈμ.
|
| 72 |
+
"""
|
| 73 |
},
|
| 74 |
{
|
| 75 |
"role": "user",
|
| 76 |
+
"content": f"""
|
| 77 |
+
μ¬μ©μ μ§λ¬Έ:
|
| 78 |
+
{userquery}
|
| 79 |
+
|
| 80 |
+
μ νλ νλ‘ μΉ΄λ:
|
| 81 |
+
{card_text}
|
| 82 |
+
|
| 83 |
+
μ μ§λ¬Έκ³Ό μ νλ μΉ΄λλ₯Ό λ°νμΌλ‘ μ§§κ² νλ‘ μλ΄μ ν΄μ£ΌμΈμ.
|
| 84 |
+
"""
|
| 85 |
}
|
| 86 |
],
|
| 87 |
"temperature": 0.8,
|