Browse Source

更新通义改版后body为空的异常

master
zhurunlin 4 months ago
parent
commit
87be344876
  1. 9
      spiders/ai_seo/tongyi.py

9
spiders/ai_seo/tongyi.py

@ -91,6 +91,7 @@ class TongyiSpider(AbstractAiSeoSpider):
stream = await response.body() stream = await response.body()
response_text = stream.decode('utf-8') response_text = stream.decode('utf-8')
datas = response_text.split("\n") datas = response_text.split("\n")
# print("datas:",datas)
# 合规数据转成字典 # 合规数据转成字典
for data_str in datas: for data_str in datas:
if not data_str or data_str == 'data: [DONE]': if not data_str or data_str == 'data: [DONE]':
@ -111,9 +112,9 @@ class TongyiSpider(AbstractAiSeoSpider):
if content_type == 'plugin': if content_type == 'plugin':
logger.debug(f"获取到联网搜索结果") logger.debug(f"获取到联网搜索结果")
if self.think: if self.think:
search_result_list = glom(content, 'content.pluginResult', default=[])
search_result_list = glom(content, 'content.pluginResult.links', default=[])
else: else:
search_result_list = glom(content, 'content.pluginResult.-1.search_results', default=[])
search_result_list = glom(content, 'content.pluginResult.links.-1.search_results', default=[])
# for search_result in search_result_list: # for search_result in search_result_list:
# url = search_result.get('url', '') # url = search_result.get('url', '')
# title = search_result.get('title', '') # title = search_result.get('title', '')
@ -124,9 +125,9 @@ class TongyiSpider(AbstractAiSeoSpider):
# ai_search_result_list.append( # ai_search_result_list.append(
# AiSearchResult(title=title, url=url, body=body, host_name=host_name, publish_time=publish_time) # AiSearchResult(title=title, url=url, body=body, host_name=host_name, publish_time=publish_time)
# ) # )
if content_type == 'text':
if content_type == 'think':
logger.debug(f'获取到ai回复结果') logger.debug(f'获取到ai回复结果')
answer = content.get('content', '')
answer = content.get('content', '').get('content', '')
logger.debug(f"ai回复: {answer}") logger.debug(f"ai回复: {answer}")
self.ai_answer.answer = answer self.ai_answer.answer = answer
pattern = r'ty-reference]\((\d+)\)' pattern = r'ty-reference]\((\d+)\)'

Loading…
Cancel
Save