通过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);
});
相关推荐
powerfulhell5 小时前
寒假python作业5
java·前端·python
木子啊6 小时前
前端组件化:模板继承拯救发际线
前端
三十_A6 小时前
零基础通过 Vue 3 实现前端视频录制 —— 从原理到实战
前端·vue.js·音视频
前端小菜袅6 小时前
PC端原样显示移动端页面方案
开发语言·前端·javascript·postcss·px-to-viewport·移动端适配pc端
We་ct6 小时前
LeetCode 228. 汇总区间:解题思路+代码详解
前端·算法·leetcode·typescript
爱问问题的小李6 小时前
ue 动态 Key 导致组件无限重置与 API 重复提交
前端·javascript·vue.js
子兮曰6 小时前
深入Vue 3响应式系统:为什么嵌套对象修改后界面不更新?
前端·javascript·vue.js
CHU7290356 小时前
直播商城APP前端功能全景解析:打造沉浸式互动购物新体验
java·前端·小程序
枫叶丹46 小时前
【Qt开发】Qt界面优化(一)-> Qt样式表(QSS) 背景介绍
开发语言·前端·qt·系统架构
子兮曰13 小时前
OpenClaw入门:从零开始搭建你的私有化AI助手
前端·架构·github