Kevin Hu
commited on
Commit
路
5381c23
1
Parent(s):
79cd49c
refactor error message of qwen (#3074)
Browse files### What problem does this PR solve?
#3055
### Type of change
- [x] Refactoring
- rag/app/qa.py +3 -2
- rag/llm/chat_model.py +3 -2
rag/app/qa.py
CHANGED
|
@@ -315,6 +315,7 @@ def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs):
|
|
| 315 |
for q, a in excel_parser(filename, binary, callback):
|
| 316 |
res.append(beAdoc(deepcopy(doc), q, a, eng))
|
| 317 |
return res
|
|
|
|
| 318 |
elif re.search(r"\.(txt|csv)$", filename, re.IGNORECASE):
|
| 319 |
callback(0.1, "Start to parse.")
|
| 320 |
txt = get_text(filename, binary)
|
|
@@ -348,16 +349,16 @@ def chunk(filename, binary=None, lang="Chinese", callback=None, **kwargs):
|
|
| 348 |
f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else "")))
|
| 349 |
|
| 350 |
return res
|
|
|
|
| 351 |
elif re.search(r"\.pdf$", filename, re.IGNORECASE):
|
| 352 |
callback(0.1, "Start to parse.")
|
| 353 |
pdf_parser = Pdf()
|
| 354 |
qai_list, tbls = pdf_parser(filename if not binary else binary,
|
| 355 |
from_page=0, to_page=10000, callback=callback)
|
| 356 |
-
|
| 357 |
-
|
| 358 |
for q, a, image, poss in qai_list:
|
| 359 |
res.append(beAdocPdf(deepcopy(doc), q, a, eng, image, poss))
|
| 360 |
return res
|
|
|
|
| 361 |
elif re.search(r"\.(md|markdown)$", filename, re.IGNORECASE):
|
| 362 |
callback(0.1, "Start to parse.")
|
| 363 |
txt = get_text(filename, binary)
|
|
|
|
| 315 |
for q, a in excel_parser(filename, binary, callback):
|
| 316 |
res.append(beAdoc(deepcopy(doc), q, a, eng))
|
| 317 |
return res
|
| 318 |
+
|
| 319 |
elif re.search(r"\.(txt|csv)$", filename, re.IGNORECASE):
|
| 320 |
callback(0.1, "Start to parse.")
|
| 321 |
txt = get_text(filename, binary)
|
|
|
|
| 349 |
f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else "")))
|
| 350 |
|
| 351 |
return res
|
| 352 |
+
|
| 353 |
elif re.search(r"\.pdf$", filename, re.IGNORECASE):
|
| 354 |
callback(0.1, "Start to parse.")
|
| 355 |
pdf_parser = Pdf()
|
| 356 |
qai_list, tbls = pdf_parser(filename if not binary else binary,
|
| 357 |
from_page=0, to_page=10000, callback=callback)
|
|
|
|
|
|
|
| 358 |
for q, a, image, poss in qai_list:
|
| 359 |
res.append(beAdocPdf(deepcopy(doc), q, a, eng, image, poss))
|
| 360 |
return res
|
| 361 |
+
|
| 362 |
elif re.search(r"\.(md|markdown)$", filename, re.IGNORECASE):
|
| 363 |
callback(0.1, "Start to parse.")
|
| 364 |
txt = get_text(filename, binary)
|
rag/llm/chat_model.py
CHANGED
|
@@ -13,6 +13,8 @@
|
|
| 13 |
# See the License for the specific language governing permissions and
|
| 14 |
# limitations under the License.
|
| 15 |
#
|
|
|
|
|
|
|
| 16 |
from openai.lib.azure import AzureOpenAI
|
| 17 |
from zhipuai import ZhipuAI
|
| 18 |
from dashscope import Generation
|
|
@@ -275,8 +277,7 @@ class QWenChat(Base):
|
|
| 275 |
[ans]) else "路路路路路路\n鐢变簬闀垮害鐨勫師鍥狅紝鍥炵瓟琚埅鏂簡锛岃缁х画鍚楋紵"
|
| 276 |
yield ans
|
| 277 |
else:
|
| 278 |
-
yield ans + "\n**ERROR**: " + resp.message if str(resp.message).
|
| 279 |
-
"Access") < 0 else "Out of credit. Please set the API key in **settings > Model providers.**"
|
| 280 |
except Exception as e:
|
| 281 |
yield ans + "\n**ERROR**: " + str(e)
|
| 282 |
|
|
|
|
| 13 |
# See the License for the specific language governing permissions and
|
| 14 |
# limitations under the License.
|
| 15 |
#
|
| 16 |
+
import re
|
| 17 |
+
|
| 18 |
from openai.lib.azure import AzureOpenAI
|
| 19 |
from zhipuai import ZhipuAI
|
| 20 |
from dashscope import Generation
|
|
|
|
| 277 |
[ans]) else "路路路路路路\n鐢变簬闀垮害鐨勫師鍥狅紝鍥炵瓟琚埅鏂簡锛岃缁х画鍚楋紵"
|
| 278 |
yield ans
|
| 279 |
else:
|
| 280 |
+
yield ans + "\n**ERROR**: " + resp.message if not re.search(r" (key|quota)", str(resp.message).lower()) else "Out of credit. Please set the API key in **settings > Model providers.**"
|
|
|
|
| 281 |
except Exception as e:
|
| 282 |
yield ans + "\n**ERROR**: " + str(e)
|
| 283 |
|