use session_id
Browse files
src/talk_to_your_manual/use_aliyun.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from dashscope import Application
|
| 2 |
-
from fastapi import APIRouter
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
import os
|
| 5 |
|
|
@@ -7,6 +7,8 @@ router = APIRouter()
|
|
| 7 |
API_KEY = os.environ.get("API_KEY")
|
| 8 |
APP_ID = os.environ.get("APP_ID")
|
| 9 |
|
|
|
|
|
|
|
| 10 |
|
| 11 |
@router.get("/aliyun")
|
| 12 |
async def call_aliyun(prompt: str):
|
|
@@ -14,13 +16,22 @@ async def call_aliyun(prompt: str):
|
|
| 14 |
api_key=API_KEY,
|
| 15 |
app_id=APP_ID,
|
| 16 |
prompt=prompt,
|
|
|
|
| 17 |
)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from dashscope import Application
|
| 2 |
+
from fastapi import APIRouter, status
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
import os
|
| 5 |
|
|
|
|
| 7 |
API_KEY = os.environ.get("API_KEY")
|
| 8 |
APP_ID = os.environ.get("APP_ID")
|
| 9 |
|
| 10 |
+
session_id = None
|
| 11 |
+
|
| 12 |
|
| 13 |
@router.get("/aliyun")
|
| 14 |
async def call_aliyun(prompt: str):
|
|
|
|
| 16 |
api_key=API_KEY,
|
| 17 |
app_id=APP_ID,
|
| 18 |
prompt=prompt,
|
| 19 |
+
session_id=session_id,
|
| 20 |
)
|
| 21 |
+
if response.status_code != status.HTTP_200_OK:
|
| 22 |
+
session_id = response.output.session_id
|
| 23 |
+
return JSONResponse(
|
| 24 |
+
status_code=status.HTTP_200_OK,
|
| 25 |
+
content={
|
| 26 |
+
"request_id": response.request_id,
|
| 27 |
+
"answer": response.output.text,
|
| 28 |
+
},
|
| 29 |
+
)
|
| 30 |
+
else:
|
| 31 |
+
return JSONResponse(
|
| 32 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 33 |
+
content={
|
| 34 |
+
"code": response.code,
|
| 35 |
+
"message": response.message,
|
| 36 |
+
},
|
| 37 |
+
)
|