From 9e8291e8bda18ef087c0265b60a3e97c22255c32 Mon Sep 17 00:00:00 2001 From: selfrelease Date: Mon, 31 Aug 2026 17:11:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8D=A2=E4=B8=80=E6=89=B9=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E7=94=A8=E6=88=B7=E7=94=BB=E5=83=8F,=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=9B=B4=E8=B4=B4=E5=90=88=E7=94=A8=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E8=BA=AB=E7=9A=84=E7=A4=BA=E4=BE=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 10 ++++++++++ web2/src/components/common/ChatPanel.tsx | 6 ++++-- web2/src/lib/api.ts | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api.py b/api.py index 11926a5..b6b671d 100644 --- a/api.py +++ b/api.py @@ -312,6 +312,7 @@ class SampleRequest(BaseModel): scene: str = "legal" topic: str | None = None existing: list[str] | None = None # 已展示的示例,避免重复 + phone: str | None = None # 用户手机号,用于读取画像个性化推荐 class TopicsRequest(BaseModel): @@ -461,6 +462,15 @@ def generate_samples(req: SampleRequest): ) if req.topic: prompt += f"具体话题:{req.topic}\n\n" + # 注入用户画像,个性化推荐 + if req.phone: + try: + profile = profile_store.get(req.phone) + profile_ctx = build_profile_context(profile) + if profile_ctx: + prompt += f"用户画像(请结合画像生成更贴合用户自身情况的问题):\n{profile_ctx}\n\n" + except Exception: + pass if existing: prompt += "已展示过的问题(不要重复):\n" for s in existing: diff --git a/web2/src/components/common/ChatPanel.tsx b/web2/src/components/common/ChatPanel.tsx index 964c0f9..23e0562 100644 --- a/web2/src/components/common/ChatPanel.tsx +++ b/web2/src/components/common/ChatPanel.tsx @@ -38,6 +38,7 @@ import { DialogTrigger, } from '@/components/ui/dialog' import { api } from '@/lib/api' +import { getPhone } from '@/lib/auth' import { cn } from '@/lib/utils' import type { AskResponse, EmotionMode, ExpertService, HistoryMessage, KnowledgeDoc, RiskCard, Scene, SessionMode } from '@/types' @@ -544,11 +545,12 @@ export function ChatPanel({ }, answers.length > 0 ? answers : undefined) } - /** AI 换一批示例问题 */ + /** AI 换一批示例问题(注入用户画像,个性化推荐) */ const handleRefreshSamples = async () => { setRefreshing(true) try { - const res = await api.generateSamples(scene, topic, dynamicSamples) + const phone = getPhone() || undefined + const res = await api.generateSamples(scene, topic, dynamicSamples, phone) setDynamicSamples(res.samples) } catch { toast.error('换一批失败,请稍后重试') diff --git a/web2/src/lib/api.ts b/web2/src/lib/api.ts index 646e360..977f7e3 100644 --- a/web2/src/lib/api.ts +++ b/web2/src/lib/api.ts @@ -235,9 +235,9 @@ export const api = { request<{ topics: Array<{ title: string; desc: string; samples: string[] }> }>('/topics', { method: 'POST', body: JSON.stringify({ scene, existing }), }), - generateSamples: (scene: Scene = 'legal', topic?: string, existing?: string[]) => + generateSamples: (scene: Scene = 'legal', topic?: string, existing?: string[], phone?: string) => request<{ samples: string[] }>('/samples', { - method: 'POST', body: JSON.stringify({ scene, topic, existing }), + method: 'POST', body: JSON.stringify({ scene, topic, existing, phone }), }), // ===== 每日热点问题 =====