通过AzureOpenAI请求gpt-4.1-mini

The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

https://learn.microsoft.com/zh-cn/azure/ai-services/openai/how-to/create-resource?pivots=web-portal

https://ai.azure.com/build/deployments/model?wsid=/subscriptions/76b46e2c-41ac-407f-bc56-124f55f90dcc/resourceGroups/rg-13642061747-1824_ai/providers/Microsoft.MachineLearningServices/workspaces/13642061747-2861&tid=c60868ed-4b1e-488b-b146-7a0e22ceefc7

javascript 复制代码
import { AzureOpenAI } from "openai";

const endpoint = "https://ai-xxx.openai.azure.com/";
const modelName = "gpt-4.1-mini";
const deployment = "gpt-4.1-mini";

export async function main() {

  const apiKey = "<your-api-key>";
  const apiVersion = "2024-04-01-preview";
  const options = { endpoint, apiKey, deployment, apiVersion }

  const client = new AzureOpenAI(options);

  const response = await client.chat.completions.create({
    messages: [
      { role:"user", content: "你好" }
    ],
    max_completion_tokens: 800,
      temperature: 1,
      top_p: 1,
      frequency_penalty: 0,
      presence_penalty: 0,
      model: modelName
  });

  if (response?.error !== undefined && response.status !== "200") {
    throw response.error;
  }
  console.log(response.choices[0].message.content);
}

main().catch((err) => {
  console.error("The sample encountered an error:", err);
});
相关推荐
cxxcode几秒前
前端模块化发展
前端
不务正业的前端学徒4 分钟前
docker+nginx部署
前端
不务正业的前端学徒10 分钟前
webpack/vite配置
前端
hhcccchh26 分钟前
学习vue第八天 Vue3 模板语法和内置指令 - 简单入门
前端·vue.js·学习
yyf1989052528 分钟前
Vue 框架相关中文文献
前端·javascript·vue.js
粥里有勺糖34 分钟前
开发一个美观的 VitePress 图片预览插件
前端·vue.js·vitepress
陟上青云1 小时前
一篇文章带你搞懂原型和原型链
前端
我的写法有点潮1 小时前
推荐几个国外比较流行的UI库(上)
前端·javascript·css
鹏多多1 小时前
jsx/tsx使用cssModule和typescript-plugin-css-modules
前端·vue.js·react.js
ssshooter2 小时前
复古话题:Vue2 的空格间距切换到 Vite 后消失了
前端·vue.js·面试