@@ -20,7 +20,8 @@ def _load_prompts(self, prompt_key: str) -> Dict[str, Any]:
2020 """加载提示词配置"""
2121 prompt_templates_file = "conf/prompt_templates.yml"
2222 try :
23- with open (prompt_templates_file , "r" ) as file :
23+ # 在打开 YAML 文件时显式指定编码为 UTF-8,避免使用系统默认的 GBK 编码。
24+ with open (prompt_templates_file , "r" , encoding = "utf-8" ) as file :
2425 prompts = yaml .safe_load (file ).get (prompt_key , {})
2526 system_prompt = prompts .get ("system_prompt" )
2627 user_prompt = prompts .get ("user_prompt" )
@@ -55,7 +56,7 @@ class CodeReviewer(BaseReviewer):
5556 def __init__ (self ):
5657 super ().__init__ ("code_review_prompt" )
5758
58- def review_and_strip_code (self , changes_text : str , commits_text : str = '' ) -> str :
59+ def review_and_strip_code (self , changes_text : str , commits_text : str = "" ) -> str :
5960 """
6061 Review判断changes_text超出取前REVIEW_MAX_TOKENS个token,超出则截断changes_text,
6162 调用review_code方法,返回review_result,如果review_result是markdown格式,则去掉头尾的```
@@ -64,11 +65,11 @@ def review_and_strip_code(self, changes_text: str, commits_text: str = '') -> st
6465 :return:
6566 """
6667 # 如果超长,取前REVIEW_MAX_TOKENS个token
67- review_max_tokens = int (os .getenv (' REVIEW_MAX_TOKENS' , 10000 ))
68+ review_max_tokens = int (os .getenv (" REVIEW_MAX_TOKENS" , 10000 ))
6869 # 如果changes为空,打印日志
6970 if not changes_text :
70- logger .info (' 代码为空, diffs_text = %' , str (changes_text ))
71- return ' 代码为空'
71+ logger .info (" 代码为空, diffs_text = %" , str (changes_text ))
72+ return " 代码为空"
7273
7374 # 计算tokens数量,如果超过REVIEW_MAX_TOKENS,截断changes_text
7475 tokens_count = count_tokens (changes_text )
@@ -87,8 +88,7 @@ def review_code(self, diffs_text: str, commits_text: str = "") -> str:
8788 {
8889 "role" : "user" ,
8990 "content" : self .prompts ["user_message" ]["content" ].format (
90- diffs_text = diffs_text ,
91- commits_text = commits_text
91+ diffs_text = diffs_text , commits_text = commits_text
9292 ),
9393 },
9494 ]
0 commit comments