通过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);
});
相关推荐
ZzMemory3 分钟前
深入理解JS(九):IIFE,即执函数的锁域魔法
前端·javascript·面试
兮漫天7 分钟前
bun + vite7 的结合,孕育的 Robot Admin 【靓仔出道】(九)
前端·vue.js
轻语呢喃8 分钟前
图片压缩技术:从网页交互到多线程处理
前端·javascript·html
MrSkye9 分钟前
🔥从进程线程聊到JS执行机制,这次彻底搞懂事件循环!(上)
前端
阿珊和她的猫12 分钟前
rem:CSS中的相对长度单位
前端·css
超级小忍16 分钟前
CSS 选择器进阶:用更聪明的方式定位元素
前端·css
我有一粒花生米17 分钟前
css 瀑布流布局
前端·javascript·css
赵不困888(合作私信)1 小时前
回答“启动速度,内存占用,流畅度 ,浏览器兼容,”
前端
子洋1 小时前
现代化 ls 命令替代工具:EZA
前端·后端·shell
二哈喇子!1 小时前
Vue3 路由
前端·javascript·vue.js