Browse Source

添加获取深度思考文本

master
zhurunlin 2 months ago
parent
commit
ca5097a732
  1. 18
      spiders/ai_seo/deepseek.py

18
spiders/ai_seo/deepseek.py

@ -110,8 +110,10 @@ class DeepseekSpider(AbstractAiSeoSpider):
return return
# 读取流式数据 # 读取流式数据
response_text = '' response_text = ''
thinking_text = ''
search_result_lists = list() search_result_lists = list()
start_content = False start_content = False
start_thinking = False
stream = await response.body() stream = await response.body()
body = stream.decode('utf-8') body = stream.decode('utf-8')
datas = body.split("\n\n") datas = body.split("\n\n")
@ -147,6 +149,21 @@ class DeepseekSpider(AbstractAiSeoSpider):
# self.ai_answer.search_result = ai_search_result_list # self.ai_answer.search_result = ai_search_result_list
# self.search_result_count = len(self.ai_answer.search_result) # self.search_result_count = len(self.ai_answer.search_result)
continue continue
# 是否开始返回深度思考数据
if data.get('p', '') == 'response/thinking_content':
start_thinking = True
if data.get('p', '') == 'response/thinking_elapsed_secs':
start_thinking = False
if start_thinking:
# 获取深度思考回复
value = data.get('v', None)
if isinstance(value, dict):
continue
if value is None:
target = 'choices.0.delta.content'
value = glom(data, target, default="")
thinking_text = thinking_text + str(value)
# 是否开始返回回复数据 # 是否开始返回回复数据
if data.get('p', '') == 'response/content': if data.get('p', '') == 'response/content':
start_content = True start_content = True
@ -185,4 +202,5 @@ class DeepseekSpider(AbstractAiSeoSpider):
self.search_result_count = len(self.ai_answer.search_result) self.search_result_count = len(self.ai_answer.search_result)
logger.debug(response_text) logger.debug(response_text)
self.ai_answer.answer = response_text self.ai_answer.answer = response_text
self.ai_answer.thinking = thinking_text
self.completed_event.set() self.completed_event.set()
Loading…
Cancel
Save