From ca5097a732d1c6c5f8659fea50445d6f51a00f2c Mon Sep 17 00:00:00 2001 From: zhurunlin Date: Fri, 15 Aug 2025 10:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=B7=B1?= =?UTF-8?q?=E5=BA=A6=E6=80=9D=E8=80=83=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spiders/ai_seo/deepseek.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spiders/ai_seo/deepseek.py b/spiders/ai_seo/deepseek.py index e9ec9ac..20beb3a 100644 --- a/spiders/ai_seo/deepseek.py +++ b/spiders/ai_seo/deepseek.py @@ -110,8 +110,10 @@ class DeepseekSpider(AbstractAiSeoSpider): return # 读取流式数据 response_text = '' + thinking_text = '' search_result_lists = list() start_content = False + start_thinking = False stream = await response.body() body = stream.decode('utf-8') datas = body.split("\n\n") @@ -147,6 +149,21 @@ class DeepseekSpider(AbstractAiSeoSpider): # self.ai_answer.search_result = ai_search_result_list # self.search_result_count = len(self.ai_answer.search_result) 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': start_content = True @@ -185,4 +202,5 @@ class DeepseekSpider(AbstractAiSeoSpider): self.search_result_count = len(self.ai_answer.search_result) logger.debug(response_text) self.ai_answer.answer = response_text + self.ai_answer.thinking = thinking_text self.completed_event.set()