From 78982d88e0c5195571b888a073387742ca821251 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Mon, 10 Feb 2025 16:47:53 +0800 Subject: [PATCH] Reformat error message. (#4829) ### What problem does this PR solve? #4828 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/llm_app.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/api/apps/llm_app.py b/api/apps/llm_app.py index 5acd764b3..ff78c65a0 100644 --- a/api/apps/llm_app.py +++ b/api/apps/llm_app.py @@ -209,21 +209,22 @@ def add_llm(): } msg = "" + mdl_nm = llm["llm_name"].split("___")[0] if llm["model_type"] == LLMType.EMBEDDING.value: mdl = EmbeddingModel[factory]( key=llm['api_key'], - model_name=llm["llm_name"], + model_name=mdl_nm, base_url=llm["api_base"]) try: arr, tc = mdl.encode(["Test if the api key is available"]) if len(arr[0]) == 0: raise Exception("Fail") except Exception as e: - msg += f"\nFail to access embedding model({llm['llm_name']})." + str(e) + msg += f"\nFail to access embedding model({mdl_nm})." + str(e) elif llm["model_type"] == LLMType.CHAT.value: mdl = ChatModel[factory]( key=llm['api_key'], - model_name=llm["llm_name"], + model_name=mdl_nm, base_url=llm["api_base"] ) try: @@ -232,12 +233,12 @@ def add_llm(): if not tc: raise Exception(m) except Exception as e: - msg += f"\nFail to access model({llm['llm_name']})." + str( + msg += f"\nFail to access model({mdl_nm})." + str( e) elif llm["model_type"] == LLMType.RERANK: mdl = RerankModel[factory]( key=llm["api_key"], - model_name=llm["llm_name"], + model_name=mdl_nm, base_url=llm["api_base"] ) try: @@ -245,12 +246,12 @@ def add_llm(): if len(arr) == 0: raise Exception("Not known.") except Exception as e: - msg += f"\nFail to access model({llm['llm_name']})." + str( + msg += f"\nFail to access model({mdl_nm})." + str( e) elif llm["model_type"] == LLMType.IMAGE2TEXT.value: mdl = CvModel[factory]( key=llm["api_key"], - model_name=llm["llm_name"], + model_name=mdl_nm, base_url=llm["api_base"] ) try: @@ -259,16 +260,16 @@ def add_llm(): if not tc: raise Exception(m) except Exception as e: - msg += f"\nFail to access model({llm['llm_name']})." + str(e) + msg += f"\nFail to access model({mdl_nm})." + str(e) elif llm["model_type"] == LLMType.TTS: mdl = TTSModel[factory]( - key=llm["api_key"], model_name=llm["llm_name"], base_url=llm["api_base"] + key=llm["api_key"], model_name=mdl_nm, base_url=llm["api_base"] ) try: for resp in mdl.tts("Hello~ Ragflower!"): pass except RuntimeError as e: - msg += f"\nFail to access model({llm['llm_name']})." + str(e) + msg += f"\nFail to access model({mdl_nm})." + str(e) else: # TODO: check other type of models pass