Skip to content

[AI优化] 智能快捷回复生成 - 上下文感知的快捷操作 #98

@hrygo

Description

@hrygo

问题描述

用户完成一轮对话后,需要手动输入下一步操作:

  • 创建日程后想设置提醒 → 需要完整输入 "帮我设置提醒"
  • 搜索笔记后想看更多 → 需要输入 "还有其他相关的吗"
  • 查看日程后想修改 → 需要输入 "把时间改成2点"

这增加了交互成本,尤其在移动端影响体验。

建议方案

后端: 生成快捷回复

// ai/agent/quick_replies.go
type QuickReply struct {
    ID          string `json:"id"`          // 唯一标识
    Label       string `json:"label"`       // 按钮文字
    Prompt      string `json:"prompt"`      // 点击后发送的内容
    Icon        string `json:"icon"`        // 可选图标
    Description string `json:"description"` // 可选描述
}

func (p *AmazingParrot) GenerateQuickReplies(
    ctx context.Context, 
    lastResponse string,
    workingState *WorkingState,
) []QuickReply {
    responseType := analyzeResponseType(lastResponse)
    
    switch responseType {
    case ResponseTypeScheduleCreated:
        return []QuickReply{
            {ID: "remind", Label: "设置提醒", Prompt: "帮我设置会议前15分钟提醒", Icon: "bell"},
            {ID: "view_day", Label: "查看当天", Prompt: "查看这天还有什么安排", Icon: "calendar"},
            {ID: "modify", Label: "修改时间", Prompt: "改成其他时间", Icon: "edit"},
        }
        
    case ResponseTypeMemoFound:
        return []QuickReply{
            {ID: "more", Label: "查看更多", Prompt: "还有其他相关的吗"},
            {ID: "schedule", Label: "创建日程", Prompt: "基于这个笔记创建日程"},
            {ID: "summarize", Label: "总结", Prompt: "帮我总结这些笔记的要点"},
        }
        
    case ResponseTypeScheduleQuery:
        return []QuickReply{
            {ID: "tomorrow", Label: "明天", Prompt: "明天有什么安排"},
            {ID: "week", Label: "本周", Prompt: "这周还有什么安排"},
            {ID: "add", Label: "添加日程", Prompt: "帮我添加一个新日程"},
        }
        
    case ResponseTypeFreeTimeFound:
        return []QuickReply{
            {ID: "book", Label: "预约这个时间", Prompt: "就这个时间吧"},
            {ID: "other", Label: "换个时间", Prompt: "有没有其他时间"},
        }
        
    default:
        return nil // 不显示快捷回复
    }
}

后端: 新增事件类型

const EventTypeQuickReplies = "quick_replies"

type QuickRepliesData struct {
    Replies []QuickReply `json:"replies"`
}

前端: QuickReplies 组件

// web/src/components/chat/QuickReplies.tsx
interface QuickRepliesProps {
  replies: QuickReply[];
  onSelect: (prompt: string) => void;
}

function QuickReplies({ replies, onSelect }: QuickRepliesProps) {
  if (!replies || replies.length === 0) return null;
  
  return (
    <div className="quick-replies">
      {replies.map(reply => (
        <button
          key={reply.id}
          className="quick-reply-btn"
          onClick={() => onSelect(reply.prompt)}
        >
          {reply.icon && <Icon name={reply.icon} />}
          <span>{reply.label}</span>
        </button>
      ))}
    </div>
  );
}

UI 设计

┌─────────────────────────────────────┐
│ 已为您创建日程:明天下午3点开会      │
│                                     │
│ ┌──────────┐ ┌──────────┐ ┌────────┐│
│ │🔔设置提醒│ │📅查看当天│ │✏️修改  ││
│ └──────────┘ └──────────┘ └────────┘│
└─────────────────────────────────────┘

文件变更

后端

  • ai/agent/quick_replies.go - 快捷回复生成逻辑
  • ai/agent/quick_replies_test.go - 单元测试
  • ai/agent/types.go - QuickReply 类型、EventTypeQuickReplies
  • ai/agent/amazing_parrot.go - 在回答后发送快捷回复

前端

  • web/src/components/chat/QuickReplies.tsx - 组件
  • web/src/components/chat/QuickReplies.css - 样式
  • web/src/hooks/useParrotChat.ts - 处理事件
  • web/src/types/aichat.ts - 类型定义

验收标准

  • 根据响应类型智能生成快捷回复
  • 点击后自动发送对应 prompt
  • 支持配置化的快捷回复规则
  • 移动端友好(触摸目标足够大)
  • 动画过渡流畅
  • 支持键盘导航

预估工时

2-3 天

相关 Issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    aienhancementNew feature or requestfrontendFrontend related changesux

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions