liuhua
liuhua
commited on
Commit
·
4c644f2
1
Parent(s):
6a90db1
Fix a bug in completions (#3632)
Browse files### What problem does this PR solve?
Fix a bug in completions
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
- api/apps/sdk/session.py +18 -16
api/apps/sdk/session.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
| 15 |
#
|
| 16 |
import re
|
| 17 |
import json
|
| 18 |
-
from
|
| 19 |
from uuid import uuid4
|
| 20 |
from api.db import LLMType
|
| 21 |
from flask import request, Response
|
|
@@ -155,6 +155,14 @@ def completion(tenant_id, chat_id):
|
|
| 155 |
|
| 156 |
def fillin_conv(ans):
|
| 157 |
reference = ans["reference"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
if "chunks" in reference:
|
| 159 |
chunks = reference.get("chunks")
|
| 160 |
chunk_list = []
|
|
@@ -165,7 +173,7 @@ def completion(tenant_id, chat_id):
|
|
| 165 |
"document_id": chunk["doc_id"],
|
| 166 |
"document_name": chunk["docnm_kwd"],
|
| 167 |
"dataset_id": chunk["kb_id"],
|
| 168 |
-
"image_id": chunk.get("
|
| 169 |
"similarity": chunk["similarity"],
|
| 170 |
"vector_similarity": chunk["vector_similarity"],
|
| 171 |
"term_similarity": chunk["term_similarity"],
|
|
@@ -173,13 +181,6 @@ def completion(tenant_id, chat_id):
|
|
| 173 |
}
|
| 174 |
chunk_list.append(new_chunk)
|
| 175 |
reference["chunks"] = chunk_list
|
| 176 |
-
nonlocal conv, message_id
|
| 177 |
-
if not conv.reference:
|
| 178 |
-
conv.reference.append(ans["reference"])
|
| 179 |
-
else:
|
| 180 |
-
conv.reference[-1] = ans["reference"]
|
| 181 |
-
conv.message[-1] = {"role": "assistant", "content": ans["answer"],
|
| 182 |
-
"id": message_id, "prompt": ans.get("prompt", "")}
|
| 183 |
ans["id"] = message_id
|
| 184 |
ans["session_id"]=session_id
|
| 185 |
|
|
@@ -271,6 +272,13 @@ def agent_completion(tenant_id, agent_id):
|
|
| 271 |
|
| 272 |
def fillin_conv(ans):
|
| 273 |
reference = ans["reference"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
if "chunks" in reference:
|
| 275 |
chunks = reference.get("chunks")
|
| 276 |
chunk_list = []
|
|
@@ -281,7 +289,7 @@ def agent_completion(tenant_id, agent_id):
|
|
| 281 |
"document_id": chunk["doc_id"],
|
| 282 |
"document_name": chunk["docnm_kwd"],
|
| 283 |
"dataset_id": chunk["kb_id"],
|
| 284 |
-
"image_id": chunk["
|
| 285 |
"similarity": chunk["similarity"],
|
| 286 |
"vector_similarity": chunk["vector_similarity"],
|
| 287 |
"term_similarity": chunk["term_similarity"],
|
|
@@ -289,12 +297,6 @@ def agent_completion(tenant_id, agent_id):
|
|
| 289 |
}
|
| 290 |
chunk_list.append(new_chunk)
|
| 291 |
reference["chunks"] = chunk_list
|
| 292 |
-
nonlocal conv, message_id
|
| 293 |
-
if not conv.reference:
|
| 294 |
-
conv.reference.append(ans["reference"])
|
| 295 |
-
else:
|
| 296 |
-
conv.reference[-1] = ans["reference"]
|
| 297 |
-
conv.message[-1] = {"role": "assistant", "content": ans["answer"], "id": message_id}
|
| 298 |
ans["id"] = message_id
|
| 299 |
ans["session_id"] = session_id
|
| 300 |
|
|
|
|
| 15 |
#
|
| 16 |
import re
|
| 17 |
import json
|
| 18 |
+
from copy import deepcopy
|
| 19 |
from uuid import uuid4
|
| 20 |
from api.db import LLMType
|
| 21 |
from flask import request, Response
|
|
|
|
| 155 |
|
| 156 |
def fillin_conv(ans):
|
| 157 |
reference = ans["reference"]
|
| 158 |
+
temp_reference = deepcopy(ans["reference"])
|
| 159 |
+
nonlocal conv, message_id
|
| 160 |
+
if not conv.reference:
|
| 161 |
+
conv.reference.append(temp_reference)
|
| 162 |
+
else:
|
| 163 |
+
conv.reference[-1] = temp_reference
|
| 164 |
+
conv.message[-1] = {"role": "assistant", "content": ans["answer"],
|
| 165 |
+
"id": message_id, "prompt": ans.get("prompt", "")}
|
| 166 |
if "chunks" in reference:
|
| 167 |
chunks = reference.get("chunks")
|
| 168 |
chunk_list = []
|
|
|
|
| 173 |
"document_id": chunk["doc_id"],
|
| 174 |
"document_name": chunk["docnm_kwd"],
|
| 175 |
"dataset_id": chunk["kb_id"],
|
| 176 |
+
"image_id": chunk.get("image_id", ""),
|
| 177 |
"similarity": chunk["similarity"],
|
| 178 |
"vector_similarity": chunk["vector_similarity"],
|
| 179 |
"term_similarity": chunk["term_similarity"],
|
|
|
|
| 181 |
}
|
| 182 |
chunk_list.append(new_chunk)
|
| 183 |
reference["chunks"] = chunk_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
ans["id"] = message_id
|
| 185 |
ans["session_id"]=session_id
|
| 186 |
|
|
|
|
| 272 |
|
| 273 |
def fillin_conv(ans):
|
| 274 |
reference = ans["reference"]
|
| 275 |
+
temp_reference = deepcopy(ans["reference"])
|
| 276 |
+
nonlocal conv, message_id
|
| 277 |
+
if not conv.reference:
|
| 278 |
+
conv.reference.append(temp_reference)
|
| 279 |
+
else:
|
| 280 |
+
conv.reference[-1] = temp_reference
|
| 281 |
+
conv.message[-1] = {"role": "assistant", "content": ans["answer"], "id": message_id}
|
| 282 |
if "chunks" in reference:
|
| 283 |
chunks = reference.get("chunks")
|
| 284 |
chunk_list = []
|
|
|
|
| 289 |
"document_id": chunk["doc_id"],
|
| 290 |
"document_name": chunk["docnm_kwd"],
|
| 291 |
"dataset_id": chunk["kb_id"],
|
| 292 |
+
"image_id": chunk["image_id"],
|
| 293 |
"similarity": chunk["similarity"],
|
| 294 |
"vector_similarity": chunk["vector_similarity"],
|
| 295 |
"term_similarity": chunk["term_similarity"],
|
|
|
|
| 297 |
}
|
| 298 |
chunk_list.append(new_chunk)
|
| 299 |
reference["chunks"] = chunk_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
ans["id"] = message_id
|
| 301 |
ans["session_id"] = session_id
|
| 302 |
|