From 1d5a9b74ff36bb1296ebf8402475457d6c111c9b Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Wed, 7 Aug 2024 19:16:46 +0800 Subject: [PATCH] fix add slef base url openai error (#1854) ### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/llm_app.py | 4 ++-- graphrag/index.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/apps/llm_app.py b/api/apps/llm_app.py index c4657c44c..3f5a0b7be 100644 --- a/api/apps/llm_app.py +++ b/api/apps/llm_app.py @@ -48,7 +48,7 @@ def set_api_key(): req["api_key"], llm.llm_name, base_url=req.get("base_url")) try: arr, tc = mdl.encode(["Test if the api key is available"]) - if len(arr[0]) == 0 or tc == 0: + if len(arr[0]) == 0: raise Exception("Fail") embd_passed = True except Exception as e: @@ -59,7 +59,7 @@ def set_api_key(): try: m, tc = mdl.chat(None, [{"role": "user", "content": "Hello! How are you doing!"}], {"temperature": 0.9,'max_tokens':50}) - if not tc: + if m.find("**ERROR**") >=0: raise Exception(m) except Exception as e: msg += f"\nFail to access model({llm.llm_name}) using this api key." + str( diff --git a/graphrag/index.py b/graphrag/index.py index 8b34e39f0..92649aa1b 100644 --- a/graphrag/index.py +++ b/graphrag/index.py @@ -35,7 +35,7 @@ def be_children(obj: dict, keyset:set): obj = [obj] if isinstance(obj, list): for i in obj: keyset.add(i) - return [{"id": i, "children":[]} for i in obj] + return [{"id": re.sub(r"\*+", "", i), "children":[]} for i in obj] arr = [] for k,v in obj.items(): k = re.sub(r"\*+", "", k)