Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plugin-azure #623

Merged
merged 2 commits into from
Nov 22, 2023
Merged

feat: add plugin-azure #623

merged 2 commits into from
Nov 22, 2023

Conversation

xiaohuoni
Copy link
Member

@xiaohuoni xiaohuoni commented Nov 22, 2023

@alita/plugin-azure

增加 azure api 对接插件

配置

配置中需要提供三个变量

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

AZURE_OPENAI_API_KEY=azureee754027ac362ec351d6bd93

使用

项目中使用

从 alita 中导出 sendOpenAI 和 openai

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 对象,你可以保存下来,供其他生命周期使用

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);
  })
};

Copy link

changeset-bot bot commented Nov 22, 2023

🦋 Changeset detected

Latest commit: c4c24c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@alita/plugin-azure Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
alita-alita ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2023 7:32am

@xiaohuoni xiaohuoni merged commit ad1b1c8 into master Nov 22, 2023
3 checks passed
@xiaohuoni xiaohuoni deleted the feat-add-plugin-azure branch November 22, 2023 09:34
@github-actions github-actions bot mentioned this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant