# @alita/plugin-azure

> @alita/plugin-azure

Latest version **3.2.3** (published 2024-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alita/plugin-azure
pnpm add @alita/plugin-azure
yarn add @alita/plugin-azure
bun add @alita/plugin-azure
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.3 |
| Published | 2024-11-04 |
| First published | 2023-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 806 |
| Maintainers | pengyh, ashoka_j, hang1017, hammersjs, cjy0208, xiaohuoni |

## Links

- npm: https://www.npmjs.com/package/@alita/plugin-azure
- Repository: https://github.com/alitajs/alita
- Homepage: https://github.com/alitajs/alita/tree/master/packages/plugin-azure#readme
- Issues: https://github.com/alitajs/alita/issues
- npm.io page: https://npm.io/package/@alita/plugin-azure

## Dependencies (2)

- [openai](https://npm.io/package/openai.md) ^4.19.1
- [@umijs/utils](https://npm.io/package/@umijs/utils.md) 4.3.30

## Recent versions

- 3.2.3 (latest) — 2024-11-04
- 4.0.0-alpha.1 (alpha) — 2025-08-08
- 3.2.2 — 2024-08-02
- 3.2.1 — 2024-07-29
- 3.2.0 — 2024-06-03
- 3.1.0 — 2024-05-21
- 3.0.7 — 2024-02-22
- 3.0.6 — 2023-12-12
- 3.0.5 — 2023-12-04
- 3.0.4 — 2023-11-27
- 3.0.3 — 2023-11-24
- 3.0.2 — 2023-11-23
- 3.0.1 — 2023-11-22
- 3.0.0 — 2023-11-22

## README

# @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';
import type { IOnIntlAzure, IAzureSend } from '@alita/plugin-azure';

let _send: IAzureSend;
export default (api: IApi & { onIntlAzure: IOnIntlAzure }) => {
  api.onIntlAzure(async ({ send }) => {
    _send = send;
  });
  api.onDevCompileDone(async () => {
    const result = await _send('你好');
    console.log(result.choices[0]!.message?.content);
  });
};
```

---
_Source: https://npm.io/package/@alita/plugin-azure · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
