imbajin commented on code in PR #212:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/212#discussion_r2053322251


##########
hugegraph-llm/src/hugegraph_llm/config/models/base_config.py:
##########
@@ -68,20 +68,51 @@ def update_env(self):
             log.info("Update %s: %s=%s", env_path, k, v)
             set_key(env_path, k, v if v else "", quote_mode="never")
 
+
     def check_env(self):
-        config_dict = self.model_dump()
-        config_dict = {k.upper(): v for k, v in config_dict.items()}
-        env_config = dotenv_values(f"{env_path}")
-        for k, v in config_dict.items():
-            if k in env_config:
-                continue
-            log.info("Update %s: %s=%s", env_path, k, v)
-            set_key(env_path, k, v if v else "", quote_mode="never")
+        try:
+            # 读取环境变量文件
+            env_config = dotenv_values(env_path)
+            # 获取当前对象的配置
+            config_dict = self.model_dump()
+            config_dict = {k.upper(): v for k, v in config_dict.items()}
+            # 检查环境变量文件中是否有对象中不存在的配置项
+            for k, v in env_config.items():
+                if k in config_dict:
+                    # 如果环境变量文件中的值与对象中的值不一致,更新对象中的值
+                    str_v = str(config_dict[k]) if config_dict[k] is not None 
else ""
+                    if v != str_v:
+                        log.info("从环境变量文件更新配置项: %s=%s (原值: %s)", k, v, str_v)
+                        # 更新对象中的值
+                        setattr(self, k.lower(), v)
+            # 检查对象中是否有环境变量文件中不存在的配置项
+            for k, v in config_dict.items():
+                if k not in env_config:
+                    # 如果对象中有环境变量文件中不存在的配置项,添加到文件中
+                    log.info("添加配置项到环境变量文件: %s=%s", k, v)
+                    str_v = str(v) if v is not None else ""
+                    set_key(env_path, k, str_v, quote_mode="never")
+            return True
+        except Exception as e:
+            # 记录错误日志
+            log.error("检查环境变量文件时发生错误: %s", str(e))
+            # 重新抛出异常,让调用者处理
+            raise

Review Comment:
   please use English comment, so as the log



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to