Skip to content

Commit

Permalink
refactor(types): sync components types
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Jun 17, 2023
1 parent 3e9f0f3 commit e1eee49
Show file tree
Hide file tree
Showing 123 changed files with 3,660 additions and 223 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ module.exports = {
'no-unused-expressions': 0,
'no-unused-vars': 'off',
'no-use-before-define': 0,
'object-curly-spacing': 2,
'no-empty': 1,
'prefer-spread': 0,
'prefer-rest-params': 0,
'react/jsx-uses-vars': 1,
'react/prop-types': 0,
'react/no-find-dom-node': 0,
'react/no-unknown-property': 0,
quotes: [2, 'single', { avoidEscape: true, allowTemplateLiterals: true }],
semi: [2, 'never'],
'simple-import-sort/imports': [2, {
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Node CI

on:
pull_request:
branches:
- master

permissions:
contents: read # to fetch code (actions/checkout)

env:
CI: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Cache pnpm modules and build
uses: actions/cache@v3
with:
path: |
node_modules
build/taro-docs
key: ${{ runner.os }}-github
restore-keys: |
${{ runner.os }}-
- name: install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
- name: Build
run: pnpm run build:github
165 changes: 165 additions & 0 deletions docs/apis/ai/inference/InferenceSession.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
title: InferenceSession
sidebar_label: InferenceSession
---

## 方法

### destroy

销毁 InferenceSession 实例

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/InferenceSession.destroy.html)
```tsx
() => void
```

### offError

取消监听模型加载失败事件. 传入指定回调函数则只取消指定回调,不传则取消所有回调

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/InferenceSession.offError.html)
```tsx
(callback?: OffErrorCallback) => void
```

| 参数 | 类型 |
| --- | --- |
| callback | `OffErrorCallback` |

### offLoad

取消监听模型加载完成事件

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/InferenceSession.offLoad.html)
```tsx
(callback?: OffLoadCallback) => void
```

| 参数 | 类型 |
| --- | --- |
| callback | `OffLoadCallback` |

### onError

监听模型加载失败事件

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/InferenceSession.onError.html)
```tsx
(callback: OnLoadCallback) => void
```

| 参数 | 类型 |
| --- | --- |
| callback | `OnLoadCallback` |

### onLoad

监听模型加载完成事件

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/InferenceSession.onLoad.html)
```tsx
(callback: OnLoadCallback) => void
```

| 参数 | 类型 |
| --- | --- |
| callback | `OnLoadCallback` |

### run

运行推断
需要在 session.onLoad 回调后使用。接口参数为 Tensors 对象,返回 Promise。
一个 InferenceSession 被创建完成后可以重复多次调用 InferenceSession.run(), 直到调用 session.destroy() 进行销毁。

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/InferenceSession.destroy.html)
```tsx
(option: Tensors) => Promise<Tensors>
```

| 参数 | 类型 |
| --- | --- |
| option | `Tensors` |

## 参数

### Type

### Tensor

| 参数 | 类型 | 说明 |
| --- | --- | --- |
| shape | `number[]` | Tensor shape (Tensor 形状,例如 [1, 3, 224, 224] 即表示一个4唯Tensor,每个维度的长度分别为1, 3, 224, 224) |
| data | `ArrayBuffer` | Tensor 值,一段 ArrayBuffer |
| type | `keyof Type` | ArrayBuffer 值的类型,合法值有 uint8, int8, uint32, int32, float32 |

### Tensors

| 参数 | 类型 |
| --- | --- |
| __index | `__index` |

### OffErrorCallback

模型加载失败回调函数。

```tsx
(res: TaroGeneral.CallbackResult) => void
```

| 参数 | 类型 |
| --- | --- |
| res | `TaroGeneral.CallbackResult` |

### OffLoadCallback

模型加载完成回调函数

```tsx
(res: TaroGeneral.CallbackResult) => void
```

| 参数 | 类型 |
| --- | --- |
| res | `TaroGeneral.CallbackResult` |

### OnLoadCallback

模型加载失败回调函数

```tsx
(res: TaroGeneral.CallbackResult) => void
```

| 参数 | 类型 |
| --- | --- |
| res | `TaroGeneral.CallbackResult` |

## API 支持度

| API | 微信小程序 | H5 | React Native | Harmony |
| :---: | :---: | :---: | :---: | :---: |
| InferenceSession.destroy | ✔️ | | | |
| InferenceSession.offError | ✔️ | | | |
| InferenceSession.offLoad | ✔️ | | | |
| InferenceSession.onError | ✔️ | | | |
| InferenceSession.onLoad | ✔️ | | | |
| InferenceSession.run | ✔️ | | | |
42 changes: 42 additions & 0 deletions docs/apis/ai/inference/createInferenceSession.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Taro.createInferenceSession(option)
sidebar_label: createInferenceSession
---

创建 AI 推理 Session

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/wx.createInferenceSession.html)
## 类型

```tsx
(option: Option) => InferenceSession
```

## 参数

| 参数 | 类型 |
| --- | --- |
| option | `Option` |

### Option

| 参数 | 类型 | 必填 | 说明 |
| --- | --- | :---: | --- |
| model | `string` || 模型文件路径,目前只执行后缀为.onnx格式(支持代码包路径,和本地文件系统路径) |
| precesionLevel | `PrecesionLevel` || 推理精度,有效值为 0 - 4。<br />一般来说,使用的precesionLevel等级越低,推理速度越快,但可能会损失精度。<br />推荐开发者在开发时,在效果满足需求时优先使用更低精度以提高推理速度,节约能耗。 |
| allowQuantize | `boolean` || 是否生成量化模型推理 |
| allowNPU | `boolean` || 是否使用NPU推理,仅对IOS有效 |
| typicalShape | `boolean` || 输入典型分辨率 |

### PrecesionLevel

| 参数 | 说明 |
| --- | --- |
| 0 | 使用fp16 存储浮点,fp16计算,Winograd 算法也采取fp16 计算,开启近似math计算 |
| 1 | 使用fp16 存储浮点,fp16计算,禁用 Winograd 算法,开启近似math计算 |
| 2 | 使用fp16 存储浮点,fp32计算,开启 Winograd,开启近似math计算 |
| 3 | 使用fp32 存储浮点,fp32计算,开启 Winograd,开启近似math计算 |
| 4 | 使用fp32 存储浮点,fp32计算,开启 Winograd,关闭近似math计算 |
36 changes: 36 additions & 0 deletions docs/apis/ai/inference/getInferenceEnvInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Taro.getInferenceEnvInfo(option)
sidebar_label: getInferenceEnvInfo
---

获取通用AI推理引擎版本

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/ai/inference/wx.getInferenceEnvInfo.html)
## 类型

```tsx
(option: Option) => void
```

## 参数

| 参数 | 类型 |
| --- | --- |
| option | `Option` |

### Option

| 参数 | 类型 | 必填 | 说明 |
| --- | --- | :---: | --- |
| complete | `(res: TaroGeneral.CallbackResult) => void` || 接口调用结束的回调函数(调用成功、失败都会执行) |
| fail | `(res: TaroGeneral.CallbackResult) => void` || 接口调用失败的回调函数 |
| success | `(result: SuccessCallbackResult) => void` || 接口调用成功的回调函数 |

### SuccessCallbackResult

| 参数 | 类型 | 说明 |
| --- | --- | --- |
| ver | `string` | AI推理引擎版本 |
2 changes: 1 addition & 1 deletion docs/apis/base/canIUse.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sidebar_label: canIUse

判断小程序的 API,回调,参数,组件等是否在当前版本可用。

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="抖音小程序" src={require('@site/static/img/platform/tt.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>
支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="字节跳动小程序" src={require('@site/static/img/platform/tt.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/base/wx.canIUse.html)
Expand Down
45 changes: 45 additions & 0 deletions docs/apis/base/performance/preloadAssets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Taro.preloadAssets(option)
sidebar_label: preloadAssets
---

为视图层预加载媒体资源文件, 目前支持:font,image

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/base/performance/wx.preloadAssets.html)
## 类型

```tsx
(option: Option) => Promise<TaroGeneral.CallbackResult>
```

## 参数

| 参数 | 类型 |
| --- | --- |
| option | `Option` |

### AssetsObjectType

| 参数 | 说明 |
| --- | --- |
| font | 字体 |
| image | 图片 |

### AssetsObject

| 参数 | 类型 | 说明 |
| --- | --- | --- |
| type | `keyof AssetsObjectType` | 类型 |
| src | `string` | 资源地址 |

### Option

| 参数 | 类型 | 必填 | 说明 |
| --- | --- | :---: | --- |
| data | `AssetsObjectType[]` || |
| complete | `(res: TaroGeneral.CallbackResult) => void` || 接口调用结束的回调函数(调用成功、失败都会执行) |
| fail | `(res: TaroGeneral.CallbackResult) => void` || 接口调用失败的回调函数 |
| success | `(res: TaroGeneral.CallbackResult) => void` || 接口调用成功的回调函数 |
30 changes: 30 additions & 0 deletions docs/apis/base/performance/preloadSkylineView.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Taro.preloadSkylineView(option)
sidebar_label: preloadSkylineView
---

预加载下个页面所需要的 Skyline 运行环境

支持情况:<img title="微信小程序" src={require('@site/static/img/platform/weapp.png').default} className="icon_platform" width="25px"/> <img title="H5" src={require('@site/static/img/platform/h5.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="React Native" src={require('@site/static/img/platform/rn.png').default} className="icon_platform icon_platform--not-support" width="25px"/> <img title="Harmony" src={require('@site/static/img/platform/harmony.png').default} className="icon_platform icon_platform--not-support" width="25px"/>

> [参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/base/performance/wx.preloadSkylineView.html)
## 类型

```tsx
(option: Option) => Promise<TaroGeneral.CallbackResult>
```

## 参数

| 参数 | 类型 |
| --- | --- |
| option | `Option` |

### Option

| 参数 | 类型 | 必填 | 说明 |
| --- | --- | :---: | --- |
| complete | `(res: TaroGeneral.CallbackResult) => void` || 接口调用结束的回调函数(调用成功、失败都会执行) |
| fail | `(res: TaroGeneral.CallbackResult) => void` || 接口调用失败的回调函数 |
| success | `(res: TaroGeneral.CallbackResult) => void` || 接口调用成功的回调函数 |
Loading

0 comments on commit e1eee49

Please sign in to comment.