Browse Source

refactor error message of qwen (#3074)

### What problem does this PR solve?
#3055

### Type of change
- [x] Refactoring
tags/v0.13.0
Kevin Hu 1 year ago
parent
commit
f86826b7a0
No account linked to committer's email address
2 changed files with 6 additions and 4 deletions
  1. 3
    2
      rag/app/qa.py
  2. 3
    2
      rag/llm/chat_model.py

+ 3
- 2
rag/app/qa.py View File

for q, a in excel_parser(filename, binary, callback): for q, a in excel_parser(filename, binary, callback):
res.append(beAdoc(deepcopy(doc), q, a, eng)) res.append(beAdoc(deepcopy(doc), q, a, eng))
return res return res

elif re.search(r"\.(txt|csv)$", filename, re.IGNORECASE): elif re.search(r"\.(txt|csv)$", filename, re.IGNORECASE):
callback(0.1, "Start to parse.") callback(0.1, "Start to parse.")
txt = get_text(filename, binary) txt = get_text(filename, binary)
f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else ""))) f"{len(fails)} failure, line: %s..." % (",".join(fails[:3])) if fails else "")))


return res return res

elif re.search(r"\.pdf$", filename, re.IGNORECASE): elif re.search(r"\.pdf$", filename, re.IGNORECASE):
callback(0.1, "Start to parse.") callback(0.1, "Start to parse.")
pdf_parser = Pdf() pdf_parser = Pdf()
qai_list, tbls = pdf_parser(filename if not binary else binary, qai_list, tbls = pdf_parser(filename if not binary else binary,
from_page=0, to_page=10000, callback=callback) from_page=0, to_page=10000, callback=callback)

for q, a, image, poss in qai_list: for q, a, image, poss in qai_list:
res.append(beAdocPdf(deepcopy(doc), q, a, eng, image, poss)) res.append(beAdocPdf(deepcopy(doc), q, a, eng, image, poss))
return res return res

elif re.search(r"\.(md|markdown)$", filename, re.IGNORECASE): elif re.search(r"\.(md|markdown)$", filename, re.IGNORECASE):
callback(0.1, "Start to parse.") callback(0.1, "Start to parse.")
txt = get_text(filename, binary) txt = get_text(filename, binary)

+ 3
- 2
rag/llm/chat_model.py View File

# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import re

from openai.lib.azure import AzureOpenAI from openai.lib.azure import AzureOpenAI
from zhipuai import ZhipuAI from zhipuai import ZhipuAI
from dashscope import Generation from dashscope import Generation
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
yield ans yield ans
else: else:
yield ans + "\n**ERROR**: " + resp.message if str(resp.message).find(
"Access") < 0 else "Out of credit. Please set the API key in **settings > Model providers.**"
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.**"
except Exception as e: except Exception as e:
yield ans + "\n**ERROR**: " + str(e) yield ans + "\n**ERROR**: " + str(e)



Loading…
Cancel
Save