diff --git a/zh-cn/application-dev/application-models/insight-intent-form.md b/zh-cn/application-dev/application-models/insight-intent-form.md new file mode 100644 index 0000000000000000000000000000000000000000..71c2c32851e4b2f6b23c0ebc1dfe9647b4af5341 --- /dev/null +++ b/zh-cn/application-dev/application-models/insight-intent-form.md @@ -0,0 +1,119 @@ +# 通过意图调用卡片 + +## 适用场景 + +通过意图调用卡片适用于将卡片展示在AI入口的场景。 + +## 运行机制 + +1. 开发意图,配置意图对应的卡片组件。 +2. 通过意图调用卡片时,需要与[UIExtensionComponent](../reference/apis-arkui/arkui-ts/ts-container-ui-extension-component-sys.md)配合使用。 + +## 规格约束 + +意图装饰器的通用约束详见[意图装饰器约束](../reference/apis-ability-kit/js-apis-app-ability-InsightIntentDecorator.md#约束限制)。 + +## 接口说明 + +查看此功能的相关接口,可参考API文档: + +| **接口名** | **描述** | +| -------- | -------- | +| [InsightIntentForm](../reference/apis-ability-kit/js-apis-app-ability-InsightIntentDecorator.md#insightintentform) | Link类型意图装饰器。 | +| [FormIntentDecoratorInfo](../reference/apis-ability-kit/js-apis-app-ability-InsightIntentDecorator.md#formintentdecoratorinfo) | 用于描述[@InsightIntentForm](../reference/apis-ability-kit/js-apis-app-ability-InsightIntentDecorator.md#insightintentform)装饰器支持的参数。 | + +## 开发步骤 + +### 开发标准意图 + +以[查看快递](./insight-intent-access-specifications.md#查看快递)举例。 + +```ts + import { formBindingData, FormExtensionAbility } from '@kit.FormKit'; + import { insightIntent, Want, InsightIntentForm } from '@kit.AbilityKit'; + + // 标准意图定义 + @InsightIntentForm({ + // 意图名称 + intentName: 'ViewLogistics', + // 意图垂域名称 + domain: 'LocalDomain', + intentVersion: '1.0.1', + displayName: '查询快递', + displayDescription: '根据快递单号查询快递信息', + schema: 'ViewLogistics', + icon: $r("app.media.viewLogistics"), + llmDescription: '支持传递歌曲名称,播放音乐', + keywords: ['音乐播放', '播放歌曲', 'PlayMusic'], + // 卡片组件名称,需开发者替换为具体卡片名称 + formName: 'ViewLogisticsWidget' + }) + export default class EntryFormAbility extends FormExtensionAbility { + //... + } +``` + +### 开发自定义意图 + +应用自定义意图大语言模型描述、意图执行相关属性和参数定义。 + +```ts + import { formBindingData, FormExtensionAbility } from '@kit.FormKit'; + import { insightIntent, Want, InsightIntentForm } from '@kit.AbilityKit'; + + // 自定义意图 + @InsightIntentForm({ + intentName: 'PlayMusic', + domain: 'MusicDomain', + intentVersion: '1.0.1', + displayName: '播放歌曲', + displayDescription: '播放音乐意图', + icon: $r('app.media.app_icon'), + llmDescription: '支持传递歌曲名称,播放音乐', + keywords: ['音乐播放', '播放歌曲', 'PlayMusic'], + parameters: { + 'type': 'object', + 'title': 'Song Schema', + 'description': 'A schema for describing songs and their artists', + 'properties': { + 'songName': { + 'type': 'string', + 'description': 'The name of the song', + 'minLength': 1 + }, + 'artist': { + 'type': 'object', + 'description': 'Information about the artist', + 'properties': { + 'country': { + 'type': 'string', + 'description': 'The artist\'s country of origin', + 'default': 'zh' + }, + 'city': { + 'type': 'object', + 'description': 'The artist\' city of origin' + }, + 'name': { + 'type': 'string', + 'description': 'The name of the artist', + 'minLength': 1 + } + }, + 'required': ['name'] + } + }, + 'required': ['songName'] + }, + formName: 'PlayMusicWidget' + }) + export default class EntryFormAbility extends FormExtensionAbility { + songName: string = ''; + + onAddForm(want: Want) { + // 该方法被调用时,将返回FormBindingData对象 + let formData = ''; + return formBindingData.createFormBindingData(formData); + } + } +```