通过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);
});
相关推荐
wangan0944 分钟前
不带圆圈的二叉树
java·前端·javascript
狗哥哥4 分钟前
从零到一:打造企业级 Vue 3 高性能表格组件的设计哲学与实践
前端·vue.js·架构
疯狂平头哥7 分钟前
微信小程序真机预览-数字不等宽如何解决
前端
Drift_Dream9 分钟前
前端趣味交互:如何精准判断鼠标从哪个方向进入元素?
前端
hqk11 分钟前
鸿蒙ArkUI:状态管理、应用结构、路由全解析
android·前端·harmonyos
米思特儿林21 分钟前
NuxtImage 配置上传目录配置
前端
Mr_chiu28 分钟前
AI加持的交互革新:手把手教你用Vue3打造智能模板输入框
前端
精神状态良好30 分钟前
告别聊天式编程:引入 OpenSpec,构建结构化的 AI 开发工作流
前端
WangHappy34 分钟前
出海不愁!用Vue3 + Node.js + Stripe实现全球支付
前端·node.js
林希_Rachel_傻希希38 分钟前
手写Promise最终版本
前端·javascript·面试