-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add plugin-azure
- Loading branch information
Showing
22 changed files
with
507 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
"@examples/tabs-custom", | ||
"@examples/tabs-routes", | ||
"@example/test-test", | ||
"@examples/azure", | ||
"umi-scripts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@alita/plugin-azure': patch | ||
--- | ||
|
||
feat: init azure |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT=8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/.env.local | ||
/.umirc.local.ts | ||
/.umirc.local.js | ||
/config/config.local.ts | ||
/config/config.local.js | ||
/src/.umi | ||
/.umi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { defineConfig } from 'alita'; | ||
|
||
export default defineConfig({ | ||
appType: 'h5', | ||
// 这个值在 appts 中被 getKeepAlive 修改 | ||
keepalive: [/./], | ||
mobileLayout: true, | ||
legacyBuild: false, | ||
// mainPath:'users', | ||
mfsu: false, | ||
hash: false, | ||
reactRouter5Compat: {}, | ||
exportStatic: {}, | ||
plugins: [ | ||
require.resolve('@alita/plugin-azure'), | ||
require.resolve('./pluginazure'), | ||
], | ||
azure: { | ||
apiVersion: '2023-07-01-preview', | ||
model: 'alita4', | ||
resource: 'alita', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IApi } from 'umi'; | ||
|
||
let _send = (_: any) => {}; | ||
export default (api: IApi) => { | ||
// @ts-ignore | ||
// api.onIntlAzure(async({send})=>{ | ||
// _send = send; | ||
// }) | ||
// api.onDevCompileDone(async()=>{ | ||
// const result = await _send('你好'); | ||
// console.log(result.choices[0]!.message?.content); | ||
// }) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@examples/azure", | ||
"private": true, | ||
"scripts": { | ||
"dev": "alita dev", | ||
"build": "alita build", | ||
"start": "npm run dev" | ||
}, | ||
"dependencies": { | ||
"@alita/flow": "workspace:*", | ||
"@alita/plugin-azure": "workspace:*", | ||
"alita": "workspace:*", | ||
"antd-mobile": "^5.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { | ||
NavBarListItem, | ||
NavBarProps, | ||
TabBarListItem, | ||
TabBarProps, | ||
TitleListItem, | ||
} from 'alita'; | ||
|
||
export const request = { | ||
prefix: '/api', | ||
method: 'get', | ||
errorHandler: (error) => { | ||
// 集中处理错误 | ||
console.log(error); | ||
}, | ||
}; | ||
|
||
const titleList: TitleListItem[] = [ | ||
{ | ||
pagePath: '/', | ||
title: '首页', | ||
}, | ||
{ | ||
pagePath: '/users', | ||
title: '列表', | ||
}, | ||
{ | ||
pagePath: '/users/foo', | ||
title: '设置', | ||
}, | ||
]; | ||
const navList: NavBarListItem[] = [ | ||
{ | ||
pagePath: '/', | ||
navBar: { | ||
pageBackground: '#fff', | ||
}, | ||
}, | ||
{ | ||
pagePath: '/users', | ||
navBar: { | ||
pageBackground: '#000', | ||
}, | ||
}, | ||
]; | ||
const navBar: NavBarProps = { | ||
navList, | ||
fixed: false, | ||
onLeftClick: () => { | ||
// router.goBack(); | ||
}, | ||
}; | ||
const tabList: TabBarListItem[] = []; | ||
|
||
const tabBar: TabBarProps = { | ||
color: `#999999`, | ||
selectedColor: '#00A0FF', | ||
borderStyle: 'white', | ||
position: 'bottom', | ||
list: tabList, | ||
}; | ||
|
||
export const mobileLayout = { | ||
documentTitle: '默认标题', | ||
navBar, | ||
tabBar, | ||
titleList, | ||
}; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.title { | ||
font-size: 30px; | ||
:global { | ||
.adm-button{ | ||
font-size: 30px | ||
} | ||
} | ||
} | ||
|
||
.adm-button{ | ||
font-size: 30px | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Button } from 'antd-mobile'; | ||
import React, { useState } from 'react'; | ||
import styles from './index.less'; | ||
import { sendOpenAI } from 'alita'; | ||
export default () => { | ||
const [message, setMessage] = useState<string | null>(); | ||
return ( | ||
<> | ||
<div className={styles['title']}> | ||
{message} | ||
<Button | ||
type="button" | ||
color="primary" | ||
fill="solid" | ||
block | ||
size="large" | ||
onClick={async () => { | ||
const result = await sendOpenAI('你好'); | ||
setMessage(result.choices[0]!.message?.content); | ||
}} | ||
> | ||
点我向 GPT 打招呼 | ||
</Button> | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./src/.umi/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'alita/typings'; |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# @alita/plugin-azure | ||
|
||
See our website [alitajs](https://alitajs.com) for more information. | ||
|
||
增加 azure api 对接插件 | ||
|
||
## 配置 | ||
|
||
配置中需要提供三个变量 | ||
|
||
```ts | ||
import { defineConfig } from 'alita'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
require.resolve('@alita/plugin-azure'), | ||
], | ||
azure: { | ||
apiVersion: '2023-07-01-preview', | ||
model: 'alita4', | ||
resource: 'alita', | ||
}, | ||
}); | ||
``` | ||
|
||
环境变量中必须提供 AZURE_OPENAI_API_KEY | ||
|
||
如 `.env.local` 中 | ||
|
||
```sh | ||
AZURE_OPENAI_API_KEY=azureee754027ac362ec351d6bd93 | ||
``` | ||
|
||
## 使用 | ||
|
||
### 项目中使用 | ||
|
||
从 alita 中导出 sendOpenAI 和 openai | ||
|
||
```tsx | ||
import { sendOpenAI, openai } from 'alita'; | ||
import { useState } from 'react'; | ||
|
||
export default () => { | ||
const [message, setMessage] = useState<string | null>(); | ||
return ( | ||
<> | ||
{message} | ||
<button | ||
onClick={async () => { | ||
const result = await sendOpenAI('你好'); | ||
setMessage(result.choices[0]!.message?.content); | ||
}} | ||
> | ||
点我向 GPT 打招呼 | ||
</button> | ||
</> | ||
); | ||
}; | ||
``` | ||
|
||
### 插件中使用 | ||
|
||
增加 umi 插件 api - onIntlAzure 可以取到 send 和 openai 对象,你可以保存下来,供其他生命周期使用 | ||
|
||
```ts | ||
import { IApi } from 'umi'; | ||
|
||
let _send = (_: any) => {}; | ||
export default (api: IApi) => { | ||
// @ts-ignore | ||
api.onIntlAzure(async({send,openai})=>{ | ||
_send = send; | ||
}) | ||
api.onDevCompileDone(async()=>{ | ||
const result = await _send('你好'); | ||
console.log(result.choices[0]!.message?.content); | ||
}) | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@alita/plugin-azure", | ||
"version": "3.0.0", | ||
"description": "@alita/plugin-azure", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "pnpm tsc", | ||
"build:deps": "umi-scripts bundleDeps", | ||
"dev": "pnpm build --watch" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alitajs/alita" | ||
}, | ||
"authors": [ | ||
"xiaohuoni <[email protected]> (https://github.com/xiaohuoni)" | ||
], | ||
"license": "MIT", | ||
"bugs": "https://github.com/alitajs/alita/issues", | ||
"homepage": "https://github.com/alitajs/alita/tree/master/packages/plugin-azure#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"openai": "^4.19.1" | ||
} | ||
} |
Oops, something went wrong.