Browse Source

feat(agent): 添加预设提示词功能支持音乐、导航等快捷操作

在文本输入模式下添加预设提示词功能,支持快速输入音乐、导航、天气、新闻和美食等常用指令。同时更新了中英文翻译文件并优化了界面显示逻辑。
weicu
lxm 1 year ago
parent
commit
fe975f4a2f
  1. 16
      lib/core/translations/language/en_us.dart
  2. 12
      lib/core/translations/language/zh_cn.dart
  3. 35
      lib/modules/agent/controllers/agent_controller.dart
  4. 183
      lib/modules/agent/views/agent_view.dart
  5. 32
      lib/modules/settings/views/settings_view.dart
  6. 108
      lib/modules/translation/views/translation_view.dart

16
lib/core/translations/language/en_us.dart

@ -305,8 +305,20 @@ const Map<String, String> enUS = {
"loadFailedClickRetry": "Load failed, click to retry", "loadFailedClickRetry": "Load failed, click to retry",
"swipeUpForMore": "Swipe up for more", "swipeUpForMore": "Swipe up for more",
// Agent Controller // Preset prompts
'welcomeMessage': 'Hello! I\'m **XiaoYan**, I can help you:\n\n' "presetMusic": "Play some music", // Play some music
"presetNavigation": "Navigation to", // Navigation
"presetWeather": "Today's weather", // Weather
"presetNews": "Today's news", // News
"presetFood": "Nearby food", // Food
"playSomeMusic": "Play some popular music", // 播放一些流行音乐
"navigationTo": "Please help me navigate to", // 导航到
"todayWeather": "How's the weather today?", // 今日天气
"todayNews": "What's the news today?", // 今日新闻
"nearbyFood": "What delicious food is nearby?", // 美食
// Agent controller
'welcomeMessage': 'Hello! I\'m **Xiaoyan**, I can help you:\n\n'
'• Answer questions and provide information\n\n' '• Answer questions and provide information\n\n'
'• Real-time voice translation\n\n' '• Real-time voice translation\n\n'
'• Recommend music and podcasts\n\n' '• Recommend music and podcasts\n\n'

12
lib/core/translations/language/zh_cn.dart

@ -295,6 +295,18 @@ const Map<String, String> zhCN = {
"loadFailedClickRetry": "加载失败,点击重试", "loadFailedClickRetry": "加载失败,点击重试",
"swipeUpForMore": "向上滑动查看更多", "swipeUpForMore": "向上滑动查看更多",
// 预设提示词
"presetMusic": "来点音乐", // 来点音乐
"presetNavigation": "导航到", // 导航
"presetWeather": "今日天气", // 今日天气
"presetNews": "今日新闻", // 今日新闻
"presetFood": "附近美食", // 美食
"playSomeMusic": "播放一些流行音乐", // 播放一些流行音乐
"navigationTo": "请帮我导航到", // 导航到
"todayWeather": "今天天气如何?", // 今日天气
"todayNews": "今天有哪些新闻?", // 今日新闻
"nearbyFood": "附近有哪些美食?", // 美食
// Agent controller // Agent controller
'welcomeMessage': '你好!我是**小言**,我能帮你:\n\n' 'welcomeMessage': '你好!我是**小言**,我能帮你:\n\n'
'• 答问题和提供信息\n\n' '• 答问题和提供信息\n\n'

35
lib/modules/agent/controllers/agent_controller.dart

@ -1287,6 +1287,41 @@ class AgentController extends GetxController {
useImagePrompt('请翻译这张图片中的文字'); useImagePrompt('请翻译这张图片中的文字');
} }
// 预设提示词处理(文本输入模式)
void preSetPromptAction(String presetType) {
// 确保在文本输入模式下
if (!isTextInputMode.value) {
// 如果不在文本模式,先切换到文本模式
isTextInputMode.value = true;
}
switch (presetType) {
case 'Music':
textController.text = 'playSomeMusic'.tr;
break;
case 'Navigation':
textController.text = 'navigationTo'.tr;
break;
case 'Weather':
textController.text = 'todayWeather'.tr;
break;
case 'News':
textController.text = 'todayNews'.tr;
break;
case 'Food':
textController.text = 'nearbyFood'.tr;
break;
default:
textController.text = presetType;
break;
}
// 自动发送消息
if (presetType != 'Navigation') {
sendMessage();
}
}
// 模式历史记录 // 模式历史记录
VoiceInputMode? _previousInputMode; VoiceInputMode? _previousInputMode;

183
lib/modules/agent/views/agent_view.dart

@ -341,80 +341,127 @@ class _AgentViewState extends State<AgentView> with WidgetsBindingObserver {
child: Column( child: Column(
children: [ children: [
// 图片预览区域 - 仅在图片输入模式下显示 // 图片预览区域 - 仅在图片输入模式下显示
Obx(() { Obx(
if (controller.isImageInputActive.value && () {
controller.selectedImagePath.value != null) { if (controller.isImageInputActive.value &&
return Column( controller.selectedImagePath.value != null) {
children: [ return Column(
// 图片预览和关闭按钮 children: [
Stack( // 图片预览和关闭按钮
children: [ Stack(
ClipRRect( children: [
borderRadius: BorderRadius.circular(12.w), ClipRRect(
child: Image.file( borderRadius: BorderRadius.circular(12.w),
File(controller.selectedImagePath.value!), child: Image.file(
height: 150.h, File(controller.selectedImagePath.value!),
width: double.infinity, height: 150.h,
fit: BoxFit.cover, width: double.infinity,
fit: BoxFit.cover,
),
), ),
), Positioned(
Positioned( top: 8.h,
top: 8.h, right: 8.w,
right: 8.w, child: GestureDetector(
child: GestureDetector( onTap: () => controller.clearImageInput(),
onTap: () => controller.clearImageInput(), child: Container(
child: Container( padding: EdgeInsets.all(4.w),
padding: EdgeInsets.all(4.w), decoration: BoxDecoration(
decoration: BoxDecoration( color: Colors.black.withOpacity(0.6),
color: Colors.black.withOpacity(0.6), shape: BoxShape.circle,
shape: BoxShape.circle, ),
), child: Icon(
child: Icon( Icons.close,
Icons.close, color: Colors.white,
color: Colors.white, size: 16.sp,
size: 16.sp, ),
), ),
), ),
), ),
),
],
),
// 预设提示选项
SizedBox(height: 12.h),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_buildPromptChip(
context: context,
label: 'summarizeImageContent'.tr, //总结图片内容
onTap: () => controller.summarizeImage(),
),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'extractImageText'.tr, //抽取图像文字
onTap: () =>
controller.extractTextFromImage(),
),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'translateImageText'.tr, //翻译图像文字
onTap: () =>
controller.translateImageText(),
),
], ],
), ),
),
SizedBox(height: 12.h), // 预设提示选项
], SizedBox(height: 12.h),
); SingleChildScrollView(
} else { scrollDirection: Axis.horizontal,
return const SizedBox.shrink(); child: Row(
} children: [
}), _buildPromptChip(
context: context,
label:
'summarizeImageContent'.tr, //总结图片内容
onTap: () => controller.summarizeImage(),
),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'extractImageText'.tr, //抽取图像文字
onTap: () =>
controller.extractTextFromImage(),
),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'translateImageText'.tr, //翻译图像文字
onTap: () =>
controller.translateImageText(),
),
],
),
),
SizedBox(height: 12.h),
],
);
} else if (controller.isTextInputMode.value &&
!controller.hasTextInput.value) {
// 文本输入模式下,且输入框为空
return Column(
children: [
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_buildPromptChip(
context: context,
label: 'presetMusic'.tr, // 来点音乐
onTap: () => controller
.preSetPromptAction('Music')),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'presetNavigation'.tr, // 导航
onTap: () =>
controller.preSetPromptAction(
'Navigation')),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'presetWeather'.tr, // 天气
onTap: () => controller
.preSetPromptAction('Weather')),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'presetNews'.tr, // 新闻
onTap: () => controller
.preSetPromptAction('News')),
SizedBox(width: 8.w),
_buildPromptChip(
context: context,
label: 'presetFood'.tr, // 美食
onTap: () => controller
.preSetPromptAction('Food')),
],
)),
SizedBox(height: 12.h),
],
);
} else {
return const SizedBox.shrink();
}
},
),
// 输入控件区域 - 包含输入行和展开的选项 // 输入控件区域 - 包含输入行和展开的选项
Column( Column(

32
lib/modules/settings/views/settings_view.dart

@ -515,22 +515,22 @@ class SettingsView extends GetView<SettingsController> {
// ? Colors.white.withOpacity(0.1) // ? Colors.white.withOpacity(0.1)
// : Colors.grey[200]), // : Colors.grey[200]),
//BLE测试 //BLE测试
_buildSimpleNavigationSetting( // _buildSimpleNavigationSetting(
title: 'opus解码测试', // title: 'opus解码测试',
subtitle: '测试opus解码', // subtitle: '测试opus解码',
icon: Icons.bluetooth_searching, // icon: Icons.bluetooth_searching,
iconBgColor: isDarkMode // iconBgColor: isDarkMode
? Colors.green[900]!.withOpacity(0.3) // ? Colors.green[900]!.withOpacity(0.3)
: Colors.green[100]!, // : Colors.green[100]!,
iconColor: // iconColor:
isDarkMode ? Colors.green[300]! : Colors.green[600]!, // isDarkMode ? Colors.green[300]! : Colors.green[600]!,
titleColor: isDarkMode ? Colors.white : null, // titleColor: isDarkMode ? Colors.white : null,
subtitleColor: isDarkMode ? Colors.white70 : null, // subtitleColor: isDarkMode ? Colors.white70 : null,
onTap: () { // onTap: () {
Get.toNamed(Routes.opusTest); // Get.toNamed(Routes.opusTest);
}, // },
isDarkMode: isDarkMode, // isDarkMode: isDarkMode,
), // ),
// Divider( // Divider(
// height: 1, // height: 1,
// color: isDarkMode // color: isDarkMode

108
lib/modules/translation/views/translation_view.dart

@ -523,63 +523,63 @@ class TranslationView extends GetView<TranslationController> {
), ),
// 添加间距 // 添加间距
SizedBox(height: 16.h), //SizedBox(height: 16.h),
// 语音识别结果显示框 // 语音识别结果显示框
Container( // Container(
width: double.infinity, // width: double.infinity,
padding: EdgeInsets.all(12.w), // padding: EdgeInsets.all(12.w),
decoration: BoxDecoration( // decoration: BoxDecoration(
color: isDarkMode ? Colors.grey[800] : Colors.grey[100], // color: isDarkMode ? Colors.grey[800] : Colors.grey[100],
borderRadius: BorderRadius.circular(8.r), // borderRadius: BorderRadius.circular(8.r),
border: Border.all( // border: Border.all(
color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!, // color: isDarkMode ? Colors.grey[600]! : Colors.grey[300]!,
width: 1, // width: 1,
), // ),
), // ),
child: Obx(() { // child: Obx(() {
// 显示最新的语音识别结果 // // 显示最新的语音识别结果
final recognitionText = controller.latestRecognitionText.value; // final recognitionText = controller.latestRecognitionText.value;
final detectedLanguage = controller.detectedLanguageCode1.value; // final detectedLanguage = controller.detectedLanguageCode1.value;
return Column( // return Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
// 标题 // // 标题
Text( // Text(
'麦头语音识别结果', // '麦头语音识别结果',
style: TextStyle( // style: TextStyle(
fontSize: 12.sp, // fontSize: 12.sp,
color: isDarkMode ? Colors.grey[400] : Colors.grey[600], // color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
fontWeight: FontWeight.w500, // fontWeight: FontWeight.w500,
), // ),
), // ),
SizedBox(height: 4.h), // SizedBox(height: 4.h),
// 识别文本 - 这里显示 finalResult1 的内容 // // 识别文本 - 这里显示 finalResult1 的内容
Text( // Text(
recognitionText.isEmpty ? '等待语音输入...' : recognitionText, // recognitionText.isEmpty ? '等待语音输入...' : recognitionText,
style: TextStyle( // style: TextStyle(
fontSize: 14.sp, // fontSize: 14.sp,
color: isDarkMode ? Colors.white : Colors.black87, // color: isDarkMode ? Colors.white : Colors.black87,
height: 1.3, // height: 1.3,
), // ),
), // ),
// 检测到的语言(如果有) // // 检测到的语言(如果有)
if (detectedLanguage.isNotEmpty) ...[ // if (detectedLanguage.isNotEmpty) ...[
SizedBox(height: 4.h), // SizedBox(height: 4.h),
Text( // Text(
'检测语言: $detectedLanguage', // '检测语言: $detectedLanguage',
style: TextStyle( // style: TextStyle(
fontSize: 10.sp, // fontSize: 10.sp,
color: // color:
isDarkMode ? Colors.grey[500] : Colors.grey[500], // isDarkMode ? Colors.grey[500] : Colors.grey[500],
), // ),
), // ),
], // ],
], // ],
); // );
}), // }),
), // ),
], ],
); );
}), }),

Loading…
Cancel
Save