From 503cc55b220995da881431c05b2a845c1046681a Mon Sep 17 00:00:00 2001 From: KeepingRunning <1599949878@qq.com> Date: Tue, 20 May 2025 03:27:46 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20=E4=BF=9D=E6=8C=81=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/official_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 6ad4648ba..807b9e8c0 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -64,7 +64,7 @@ class IdentityConfig(ConfigBase): height: int = 170 """身高(单位:厘米)""" - weight: float = 50 + weight: int = 50 """体重(单位:千克)""" age: int = 18 From 6b62c0daeeabb1c06c655711543c17cc9367aa84 Mon Sep 17 00:00:00 2001 From: infinitycat Date: Tue, 20 May 2025 19:22:48 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0docker-compose?= =?UTF-8?q?=E7=9A=84tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index ba56b0c24..f9b5e6658 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,6 +9,8 @@ on: tags: - "v*.*.*" - "v*" + - "*.*.*" + - "*.*.*-*" jobs: build-amd64: @@ -47,6 +49,7 @@ jobs: tags: | type=ref,event=branch type=ref,event=tag + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} @@ -109,6 +112,7 @@ jobs: tags: | type=ref,event=branch type=ref,event=tag + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} @@ -153,6 +157,7 @@ jobs: tags: | type=ref,event=branch type=ref,event=tag + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} From 10a6f91df49a3593d2476e1e174c8192cdc13377 Mon Sep 17 00:00:00 2001 From: KeepingRunning <1599949878@qq.com> Date: Wed, 21 May 2025 02:00:42 +0800 Subject: [PATCH 3/8] =?UTF-8?q?fix:=20=E5=85=A8=E9=83=A8=E6=94=B9=E6=88=90?= =?UTF-8?q?float?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/official_configs.py | 2 +- src/individuality/identity.py | 6 +++--- src/individuality/individuality.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 807b9e8c0..6ad4648ba 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -64,7 +64,7 @@ class IdentityConfig(ConfigBase): height: int = 170 """身高(单位:厘米)""" - weight: int = 50 + weight: float = 50 """体重(单位:千克)""" age: int = 18 diff --git a/src/individuality/identity.py b/src/individuality/identity.py index fd0d70f38..f79da547a 100644 --- a/src/individuality/identity.py +++ b/src/individuality/identity.py @@ -8,7 +8,7 @@ class Identity: identity_detail: List[str] # 身份细节描述 height: int # 身高(厘米) - weight: int # 体重(千克) + weight: float # 体重(千克) age: int # 年龄 gender: str # 性别 appearance: str # 外貌特征 @@ -24,7 +24,7 @@ class Identity: self, identity_detail: List[str] = None, height: int = 0, - weight: int = 0, + weight: float = 0, age: int = 0, gender: str = "", appearance: str = "", @@ -61,7 +61,7 @@ class Identity: @classmethod def initialize( - cls, identity_detail: List[str], height: int, weight: int, age: int, gender: str, appearance: str + cls, identity_detail: List[str], height: int, weight: float, age: int, gender: str, appearance: str ) -> "Identity": """初始化身份特征 diff --git a/src/individuality/individuality.py b/src/individuality/individuality.py index 38131ea15..27d50268c 100644 --- a/src/individuality/individuality.py +++ b/src/individuality/individuality.py @@ -46,7 +46,7 @@ class Individuality: personality_sides: list, identity_detail: list, height: int, - weight: int, + weight: float, age: int, gender: str, appearance: str, From 8f4489a14566c9b1e5bccda6d0beca979d3f9739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Wed, 21 May 2025 09:16:01 +0800 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=E5=B0=9D=E8=AF=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8json=5Frepair=E5=BA=93=E4=BB=A3=E6=9B=BFHRAG=E7=9A=84J?= =?UTF-8?q?SON=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/knowledge/src/utils/json_fix.py | 76 ++++-------------------- 1 file changed, 12 insertions(+), 64 deletions(-) diff --git a/src/chat/knowledge/src/utils/json_fix.py b/src/chat/knowledge/src/utils/json_fix.py index a83eb4914..46da2d730 100644 --- a/src/chat/knowledge/src/utils/json_fix.py +++ b/src/chat/knowledge/src/utils/json_fix.py @@ -1,76 +1,24 @@ import json +from json_repair import repair_json +# 以下代码用于修复损坏的 JSON 字符串。 -def _find_unclosed(json_str): - """ - Identifies the unclosed braces and brackets in the JSON string. - - Args: - json_str (str): The JSON string to analyze. - - Returns: - list: A list of unclosed elements in the order they were opened. - """ - unclosed = [] - inside_string = False - escape_next = False - - for char in json_str: - if inside_string: - if escape_next: - escape_next = False - elif char == "\\": - escape_next = True - elif char == '"': - inside_string = False - else: - if char == '"': - inside_string = True - elif char in "{[": - unclosed.append(char) - elif char in "}]": - if unclosed and ((char == "}" and unclosed[-1] == "{") or (char == "]" and unclosed[-1] == "[")): - unclosed.pop() - - return unclosed - - -# The following code is used to fix a broken JSON string. -# From HippoRAG2 (GitHub: OSU-NLP-Group/HippoRAG) def fix_broken_generated_json(json_str: str) -> str: """ - Fixes a malformed JSON string by: - - Removing the last comma and any trailing content. - - Iterating over the JSON string once to determine and fix unclosed braces or brackets. - - Ensuring braces and brackets inside string literals are not considered. + 使用 json-repair 库修复格式错误的 JSON 字符串。 - If the original json_str string can be successfully loaded by json.loads(), will directly return it without any modification. + 如果原始 json_str 字符串可以被 json.loads() 成功加载,则直接返回而不进行任何修改。 - Args: - json_str (str): The malformed JSON string to be fixed. + 参数: + json_str (str): 需要修复的格式错误的 JSON 字符串。 - Returns: - str: The corrected JSON string. + 返回: + str: 修复后的 JSON 字符串。 """ - try: - # Try to load the JSON to see if it is valid + # 尝试加载 JSON 以查看其是否有效 json.loads(json_str) - return json_str # Return as-is if valid + return json_str # 如果有效则按原样返回 except json.JSONDecodeError: - pass - - # Step 1: Remove trailing content after the last comma. - last_comma_index = json_str.rfind(",") - if last_comma_index != -1: - json_str = json_str[:last_comma_index] - - # Step 2: Identify unclosed braces and brackets. - unclosed_elements = _find_unclosed(json_str) - - # Step 3: Append the necessary closing elements in reverse order of opening. - closing_map = {"{": "}", "[": "]"} - for open_char in reversed(unclosed_elements): - json_str += closing_map[open_char] - - return json_str + # 如果无效,则尝试修复它 + return repair_json(json_str) From 3b89eb6ea8a97ca7a045a08df639500257edf883 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 21 May 2025 01:16:20 +0000 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/knowledge/src/utils/json_fix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chat/knowledge/src/utils/json_fix.py b/src/chat/knowledge/src/utils/json_fix.py index 46da2d730..e9b13ea14 100644 --- a/src/chat/knowledge/src/utils/json_fix.py +++ b/src/chat/knowledge/src/utils/json_fix.py @@ -3,6 +3,7 @@ from json_repair import repair_json # 以下代码用于修复损坏的 JSON 字符串。 + def fix_broken_generated_json(json_str: str) -> str: """ 使用 json-repair 库修复格式错误的 JSON 字符串。 From e82a5f7d47bfe41d7d85ec1b6e3b40774f31d614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Wed, 21 May 2025 09:20:17 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20=E4=BF=9D=E7=95=99=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84=E4=BF=AE=E5=A4=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/knowledge/src/ie_process.py | 6 +- src/chat/knowledge/src/utils/json_fix.py | 76 +++++++++++++++++++++++- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/chat/knowledge/src/ie_process.py b/src/chat/knowledge/src/ie_process.py index 0bbe21698..ddc5eb023 100644 --- a/src/chat/knowledge/src/ie_process.py +++ b/src/chat/knowledge/src/ie_process.py @@ -6,7 +6,7 @@ from .global_logger import logger from . import prompt_template from .lpmmconfig import global_config, INVALID_ENTITY from .llm_client import LLMClient -from .utils.json_fix import fix_broken_generated_json +from .utils.json_fix import new_fix_broken_generated_json def _entity_extract(llm_client: LLMClient, paragraph: str) -> List[str]: @@ -24,7 +24,7 @@ def _entity_extract(llm_client: LLMClient, paragraph: str) -> List[str]: if "]" in request_result: request_result = request_result[: request_result.rindex("]") + 1] - entity_extract_result = json.loads(fix_broken_generated_json(request_result)) + entity_extract_result = json.loads(new_fix_broken_generated_json(request_result)) entity_extract_result = [ entity @@ -53,7 +53,7 @@ def _rdf_triple_extract(llm_client: LLMClient, paragraph: str, entities: list) - if "]" in request_result: request_result = request_result[: request_result.rindex("]") + 1] - entity_extract_result = json.loads(fix_broken_generated_json(request_result)) + entity_extract_result = json.loads(new_fix_broken_generated_json(request_result)) for triple in entity_extract_result: if len(triple) != 3 or (triple[0] is None or triple[1] is None or triple[2] is None) or "" in triple: diff --git a/src/chat/knowledge/src/utils/json_fix.py b/src/chat/knowledge/src/utils/json_fix.py index e9b13ea14..dd91499ee 100644 --- a/src/chat/knowledge/src/utils/json_fix.py +++ b/src/chat/knowledge/src/utils/json_fix.py @@ -1,10 +1,82 @@ import json from json_repair import repair_json -# 以下代码用于修复损坏的 JSON 字符串。 +def _find_unclosed(json_str): + """ + Identifies the unclosed braces and brackets in the JSON string. + + Args: + json_str (str): The JSON string to analyze. + + Returns: + list: A list of unclosed elements in the order they were opened. + """ + unclosed = [] + inside_string = False + escape_next = False + + for char in json_str: + if inside_string: + if escape_next: + escape_next = False + elif char == "\\": + escape_next = True + elif char == '"': + inside_string = False + else: + if char == '"': + inside_string = True + elif char in "{[": + unclosed.append(char) + elif char in "}]": + if unclosed and ((char == "}" and unclosed[-1] == "{") or (char == "]" and unclosed[-1] == "[")): + unclosed.pop() + + return unclosed +# The following code is used to fix a broken JSON string. +# From HippoRAG2 (GitHub: OSU-NLP-Group/HippoRAG) def fix_broken_generated_json(json_str: str) -> str: + """ + Fixes a malformed JSON string by: + - Removing the last comma and any trailing content. + - Iterating over the JSON string once to determine and fix unclosed braces or brackets. + - Ensuring braces and brackets inside string literals are not considered. + + If the original json_str string can be successfully loaded by json.loads(), will directly return it without any modification. + + Args: + json_str (str): The malformed JSON string to be fixed. + + Returns: + str: The corrected JSON string. + """ + + try: + # Try to load the JSON to see if it is valid + json.loads(json_str) + return json_str # Return as-is if valid + except json.JSONDecodeError: + pass + + # Step 1: Remove trailing content after the last comma. + last_comma_index = json_str.rfind(",") + if last_comma_index != -1: + json_str = json_str[:last_comma_index] + + # Step 2: Identify unclosed braces and brackets. + unclosed_elements = _find_unclosed(json_str) + + # Step 3: Append the necessary closing elements in reverse order of opening. + closing_map = {"{": "}", "[": "]"} + for open_char in reversed(unclosed_elements): + json_str += closing_map[open_char] + + return json_str + + +def new_fix_broken_generated_json(json_str: str) -> str: """ 使用 json-repair 库修复格式错误的 JSON 字符串。 @@ -22,4 +94,4 @@ def fix_broken_generated_json(json_str: str) -> str: return json_str # 如果有效则按原样返回 except json.JSONDecodeError: # 如果无效,则尝试修复它 - return repair_json(json_str) + return repair_json(json_str) \ No newline at end of file From 6730b60e0a5823eac2d66e4567f81f05d9908a4e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 21 May 2025 01:20:30 +0000 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/knowledge/src/utils/json_fix.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chat/knowledge/src/utils/json_fix.py b/src/chat/knowledge/src/utils/json_fix.py index dd91499ee..53fa8f36f 100644 --- a/src/chat/knowledge/src/utils/json_fix.py +++ b/src/chat/knowledge/src/utils/json_fix.py @@ -1,6 +1,7 @@ import json from json_repair import repair_json + def _find_unclosed(json_str): """ Identifies the unclosed braces and brackets in the JSON string. @@ -94,4 +95,4 @@ def new_fix_broken_generated_json(json_str: str) -> str: return json_str # 如果有效则按原样返回 except json.JSONDecodeError: # 如果无效,则尝试修复它 - return repair_json(json_str) \ No newline at end of file + return repair_json(json_str) From 86b777fe4df21c80f909bd89ca8dbfbb6f0a755a Mon Sep 17 00:00:00 2001 From: Oct-autumn Date: Wed, 21 May 2025 15:57:23 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E5=BF=83=E8=B7=B3403Error=E6=97=B6?= =?UTF-8?q?=E7=82=B8=E5=BF=83=E8=B7=B3=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/remote.py | 101 +++++++++++++++-------------- src/manager/local_store_manager.py | 10 ++- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/src/common/remote.py b/src/common/remote.py index 4b12e26ce..5ffc5ebc1 100644 --- a/src/common/remote.py +++ b/src/common/remote.py @@ -68,30 +68,30 @@ class TelemetryHeartBeatTask(AsyncTask): response = requests.post( f"{TELEMETRY_SERVER_URL}/stat/reg_client", json={"deploy_time": local_storage["deploy_time"]}, + timeout=5, # 设置超时时间为5秒 ) - - logger.debug(f"{TELEMETRY_SERVER_URL}/stat/reg_client") - - logger.debug(local_storage["deploy_time"]) - - logger.debug(response) - - if response.status_code == 200: - data = response.json() - client_id = data.get("mmc_uuid") - if client_id: - # 将UUID存储到本地 - local_storage["mmc_uuid"] = client_id - self.client_uuid = client_id - logger.info(f"成功获取UUID: {self.client_uuid}") - return True # 成功获取UUID,返回True - else: - logger.error("无效的服务端响应") - else: - logger.error(f"请求UUID失败,状态码: {response.status_code}, 响应内容: {response.text}") - except requests.RequestException as e: + except Exception as e: logger.error(f"请求UUID时出错: {e}") # 可能是网络问题 + logger.debug(f"{TELEMETRY_SERVER_URL}/stat/reg_client") + + logger.debug(local_storage["deploy_time"]) + + logger.debug(response) + + if response.status_code == 200: + data = response.json() + if client_id := data.get("mmc_uuid"): + # 将UUID存储到本地 + local_storage["mmc_uuid"] = client_id + self.client_uuid = client_id + logger.info(f"成功获取UUID: {self.client_uuid}") + return True # 成功获取UUID,返回True + else: + logger.error("无效的服务端响应") + else: + logger.error(f"请求UUID失败,状态码: {response.status_code}, 响应内容: {response.text}") + # 请求失败,重试次数+1 try_count += 1 if try_count > 3: @@ -100,47 +100,48 @@ class TelemetryHeartBeatTask(AsyncTask): return False else: # 如果可以重试,等待后继续(指数退避) + logger.info(f"获取UUID失败,将于 {4**try_count} 秒后重试...") await asyncio.sleep(4**try_count) async def _send_heartbeat(self): """向服务器发送心跳""" + headers = { + "Client-UUID": self.client_uuid, + "User-Agent": f"HeartbeatClient/{self.client_uuid[:8]}", + } + + logger.debug(f"正在发送心跳到服务器: {self.server_url}") + + logger.debug(headers) + try: - headers = { - "Client-UUID": self.client_uuid, - "User-Agent": f"HeartbeatClient/{self.client_uuid[:8]}", - } - - logger.debug(f"正在发送心跳到服务器: {self.server_url}") - - logger.debug(headers) - response = requests.post( f"{self.server_url}/stat/client_heartbeat", headers=headers, json=self.info_dict, + timeout=5, # 设置超时时间为5秒 ) - - logger.debug(response) - - # 处理响应 - if 200 <= response.status_code < 300: - # 成功 - logger.debug(f"心跳发送成功,状态码: {response.status_code}") - elif response.status_code == 403: - # 403 Forbidden - logger.error( - "心跳发送失败,403 Forbidden: 可能是UUID无效或未注册。" - "处理措施:重置UUID,下次发送心跳时将尝试重新注册。" - ) - self.client_uuid = None - del local_storage["mmc_uuid"] # 删除本地存储的UUID - else: - # 其他错误 - logger.error(f"心跳发送失败,状态码: {response.status_code}, 响应内容: {response.text}") - - except requests.RequestException as e: + except Exception as e: logger.error(f"心跳发送失败: {e}") + logger.debug(response) + + # 处理响应 + if 200 <= response.status_code < 300: + # 成功 + logger.debug(f"心跳发送成功,状态码: {response.status_code}") + elif response.status_code == 403: + # 403 Forbidden + logger.error( + "心跳发送失败,403 Forbidden: 可能是UUID无效或未注册。" + "处理措施:重置UUID,下次发送心跳时将尝试重新注册。" + ) + self.client_uuid = None + del local_storage["mmc_uuid"] # 删除本地存储的UUID + else: + # 其他错误 + logger.error(f"心跳发送失败,状态码: {response.status_code}, 响应内容: {response.text}") + async def run(self): # 发送心跳 if global_config.telemetry.enable: diff --git a/src/manager/local_store_manager.py b/src/manager/local_store_manager.py index f172d8890..33a30cec7 100644 --- a/src/manager/local_store_manager.py +++ b/src/manager/local_store_manager.py @@ -22,13 +22,21 @@ class LocalStoreManager: def __getitem__(self, item: str) -> str | list | dict | int | float | bool | None: """获取本地存储数据""" - return self.store.get(item, None) + return self.store.get(item) def __setitem__(self, key: str, value: str | list | dict | int | float | bool): """设置本地存储数据""" self.store[key] = value self.save_local_store() + def __delitem__(self, key: str): + """删除本地存储数据""" + if key in self.store: + del self.store[key] + self.save_local_store() + else: + logger.warning(f"尝试删除不存在的键: {key}") + def __contains__(self, item: str) -> bool: """检查本地存储数据是否存在""" return item in self.store