Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ async def send_chat_message(LLM_URL, LLM_API, category, file_url):
|
|
| 26 |
"query": category,
|
| 27 |
"conversation_id": "",
|
| 28 |
"user": USER_ID,
|
| 29 |
-
"response_mode": "streaming",
|
| 30 |
"files": [
|
| 31 |
{
|
| 32 |
"type": "image",
|
|
@@ -36,6 +36,7 @@ async def send_chat_message(LLM_URL, LLM_API, category, file_url):
|
|
| 36 |
]
|
| 37 |
}
|
| 38 |
|
|
|
|
| 39 |
async with aiohttp.ClientSession() as session:
|
| 40 |
async with session.post(
|
| 41 |
f"{LLM_URL}/chat-messages",
|
|
@@ -45,11 +46,16 @@ async def send_chat_message(LLM_URL, LLM_API, category, file_url):
|
|
| 45 |
},
|
| 46 |
json=payload
|
| 47 |
) as response:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# async def send_chat_message(LLM_URL, LLM_API, category, file_id):
|
| 55 |
# payload = {
|
|
|
|
| 26 |
"query": category,
|
| 27 |
"conversation_id": "",
|
| 28 |
"user": USER_ID,
|
| 29 |
+
"response_mode": "streaming",
|
| 30 |
"files": [
|
| 31 |
{
|
| 32 |
"type": "image",
|
|
|
|
| 36 |
]
|
| 37 |
}
|
| 38 |
|
| 39 |
+
answer = ""
|
| 40 |
async with aiohttp.ClientSession() as session:
|
| 41 |
async with session.post(
|
| 42 |
f"{LLM_URL}/chat-messages",
|
|
|
|
| 46 |
},
|
| 47 |
json=payload
|
| 48 |
) as response:
|
| 49 |
+
async for line_bytes in response.content:
|
| 50 |
+
line = line_bytes.decode("utf-8").strip()
|
| 51 |
+
if line.startswith("data: "):
|
| 52 |
+
try:
|
| 53 |
+
data = json.loads(line[6:])
|
| 54 |
+
if "answer" in data:
|
| 55 |
+
answer += data["answer"]
|
| 56 |
+
except:
|
| 57 |
+
continue
|
| 58 |
+
return answer or "No answer returned"
|
| 59 |
|
| 60 |
# async def send_chat_message(LLM_URL, LLM_API, category, file_id):
|
| 61 |
# payload = {
|