From 254efaa26c027ce50054b1190601c815b5bdd8ef Mon Sep 17 00:00:00 2001 From: xiaohuoni Date: Wed, 22 Nov 2023 17:38:24 +0800 Subject: [PATCH] docs: types --- .changeset/forty-bobcats-move.md | 5 +++++ examples/with-azure/config/pluginazure.ts | 14 +++++++------- packages/plugin-azure/README.md | 14 +++++++------- packages/plugin-azure/package.json | 2 +- packages/plugin-azure/src/index.ts | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 .changeset/forty-bobcats-move.md diff --git a/.changeset/forty-bobcats-move.md b/.changeset/forty-bobcats-move.md new file mode 100644 index 00000000..e67d534d --- /dev/null +++ b/.changeset/forty-bobcats-move.md @@ -0,0 +1,5 @@ +--- +'@alita/plugin-azure': patch +--- + +docs: add types diff --git a/examples/with-azure/config/pluginazure.ts b/examples/with-azure/config/pluginazure.ts index 8e209b37..f1a1005c 100644 --- a/examples/with-azure/config/pluginazure.ts +++ b/examples/with-azure/config/pluginazure.ts @@ -1,13 +1,13 @@ import { IApi } from 'umi'; +import type { IOnIntlAzure, IAzureSend } from '@alita/plugin-azure'; -let _send = (_: any) => {}; -export default (api: IApi) => { - // @ts-ignore - // api.onIntlAzure(async({send})=>{ +let _send: IAzureSend; +export default (api: IApi & { onIntlAzure: IOnIntlAzure }) => { + // api.onIntlAzure(async ({ send }) => { // _send = send; - // }) - // api.onDevCompileDone(async()=>{ + // }); + // api.onDevCompileDone(async () => { // const result = await _send('你好'); // console.log(result.choices[0]!.message?.content); - // }) + // }); }; diff --git a/packages/plugin-azure/README.md b/packages/plugin-azure/README.md index 9ee57e90..7b46171c 100644 --- a/packages/plugin-azure/README.md +++ b/packages/plugin-azure/README.md @@ -65,16 +65,16 @@ export default () => { ```ts import { IApi } from 'umi'; +import type { IOnIntlAzure, IAzureSend } from '@alita/plugin-azure'; -let _send = (_: any) => {}; -export default (api: IApi) => { - // @ts-ignore - api.onIntlAzure(async({send,openai})=>{ +let _send: IAzureSend; +export default (api: IApi & { onIntlAzure: IOnIntlAzure }) => { + api.onIntlAzure(async ({ send }) => { _send = send; - }) - api.onDevCompileDone(async()=>{ + }); + api.onDevCompileDone(async () => { const result = await _send('你好'); console.log(result.choices[0]!.message?.content); - }) + }); }; ``` \ No newline at end of file diff --git a/packages/plugin-azure/package.json b/packages/plugin-azure/package.json index 50dfabba..3861d125 100644 --- a/packages/plugin-azure/package.json +++ b/packages/plugin-azure/package.json @@ -1,6 +1,6 @@ { "name": "@alita/plugin-azure", - "version": "3.0.0", + "version": "3.0.1", "description": "@alita/plugin-azure", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/plugin-azure/src/index.ts b/packages/plugin-azure/src/index.ts index 679213bc..b5b72d40 100644 --- a/packages/plugin-azure/src/index.ts +++ b/packages/plugin-azure/src/index.ts @@ -1,6 +1,24 @@ import { IApi } from 'umi'; import { dirname } from 'path'; import OpenAI from 'openai'; +export interface IEvent { + (fn: { (args: T): void }): void; + (args: { + fn: { + (args: T): void; + }; + name?: string; + before?: string | string[]; + stage?: number; + }): void; +} +export declare type IAzureSend = ( + content: string | Array, +) => Promise; +export declare type IOnIntlAzure = IEvent<{ + openapi: OpenAI; + send: IAzureSend; +}>; export default (api: IApi) => { api.describe({