增加了结果中tag解析
This commit is contained in:
parent
f59b5ae76b
commit
97be17303f
@ -58,7 +58,7 @@ class tweetContent:
|
|||||||
self.variant_index = variant_index
|
self.variant_index = variant_index
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.title, self.content = self.split_content(result)
|
self.title, self.content, self.tag = self.split_content(result)
|
||||||
self.json_data = self.gen_result_json()
|
self.json_data = self.gen_result_json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to parse AI result for {article_index}_{variant_index}: {e}")
|
logging.error(f"Failed to parse AI result for {article_index}_{variant_index}: {e}")
|
||||||
@ -85,10 +85,13 @@ class tweetContent:
|
|||||||
if "</think>" in result:
|
if "</think>" in result:
|
||||||
processed_result = result.split("</think>", 1)[1] # Take part after </think>
|
processed_result = result.split("</think>", 1)[1] # Take part after </think>
|
||||||
|
|
||||||
title = processed_result.split("title>", 1)[1].split("</title>", 1)[0]
|
# 以json 格式输出
|
||||||
content = processed_result.split("content>", 1)[1].split("</content>", 1)[0]
|
json_data = json.loads(processed_result)
|
||||||
|
title = json_data.get("title")
|
||||||
|
content = json_data.get("content")
|
||||||
|
tag = json_data.get("tag")
|
||||||
# --- End Existing Logic ---
|
# --- End Existing Logic ---
|
||||||
return title.strip(), content.strip()
|
return title.strip(), content.strip(), tag.strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(f"解析内容时出错: {e}, 返回空字符串")
|
logging.warning(f"解析内容时出错: {e}, 返回空字符串")
|
||||||
return "", ""
|
return "", ""
|
||||||
@ -96,12 +99,14 @@ class tweetContent:
|
|||||||
def gen_result_json(self):
|
def gen_result_json(self):
|
||||||
json_file = {
|
json_file = {
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
"content": self.content
|
"content": self.content,
|
||||||
|
"tag": self.tag
|
||||||
}
|
}
|
||||||
# Add error flag if it exists
|
# Add error flag if it exists
|
||||||
if hasattr(self, 'json_data') and self.json_data.get('error'):
|
if hasattr(self, 'json_data') and self.json_data.get('error'):
|
||||||
json_file['error'] = True
|
json_file['error'] = True
|
||||||
json_file['raw_result'] = self.json_data.get('raw_result')
|
json_file['raw_result'] = self.json_data.get('raw_result')
|
||||||
|
logging.info(f"Generated JSON: {json_file}")
|
||||||
return json_file
|
return json_file
|
||||||
|
|
||||||
def get_json_data(self):
|
def get_json_data(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user