如何在最新的 Azure 门户中查找 AZURE_ENDPOINT、AZURE_API_KEY 和 KNOWLEDGE_BASE_ID?

问题描述 投票:0回答:1

我正在尝试在 Azure 中设置自定义问答资源,但在新的 Azure 门户界面中找不到以下详细信息时遇到问题:

AZURE_ENDPOINT: The endpoint URL for the custom question-answering resource.
AZURE_API_KEY: The API key associated with the resource.
KNOWLEDGE_BASE_ID: The ID for the knowledge base.

我发现的大多数解决方案似乎都是基于旧版本的Azure Portal,并且从那时起布局已经发生了变化。有人可以指导我在最新的 Azure 仪表板中哪里可以找到这些值吗?

完整代码:

const functions = require('firebase-functions');
const { QnAMaker } = require('botbuilder-ai');
require('dotenv').config();

const qnaEndpoint = {
  endpoint: 'URL',
  endpointKey: process.env.AZURE_API_KEY,
  knowledgeBaseId: process.env.KNOWLEDGE_BASE_ID
};

const qnaMaker = new QnAMaker(qnaEndpoint);

exports.getAnswer = functions.https.onRequest(async (req, res) => {
  const question = req.query.question || req.body.question;

  if (!question) {
    return res.status(400).send('Please provide a question.');
  }

  try {
    const result = await qnaMaker.getAnswers({ question: question });
    if (result && result.length > 0) {
      return res.status(200).json({ answer: result[0].answer });
    } else {
      return res.status(200).json({ answer: 'No answer found.' });
    }
  } catch (error) {
    console.error('Error fetching answer:', error);
    return res.status(500).send('Error occurred while fetching answer.');
  }
});
node.js azure bots api-key
1个回答
0
投票

我发现的大多数解决方案似乎都是基于旧版本的Azure Portal,并且从那时起布局已经发生了变化。有人可以指导我在最新的 Azure 仪表板中哪里可以找到这些值吗?

enter image description here

  • 转到Azure 门户。导航到 Azure AI 服务 资源(以前称为 QnA Maker)。

enter image description here

  • 在资源菜单中,选择概览,您将发现管理键上列出的端点 URL。

enter image description here

使用以下代码满足您的要求。

代码:

/**
 * Import function triggers from their respective submodules:
 *
 * const {onCall} = require("firebase-functions/v2/https");
 * const {onDocumentWritten} = require("firebase-functions/v2/firestore");
 *
 * See a full list of supported triggers at https://firebase.google.com/docs/functions
 */

const {onRequest} = require("firebase-functions/v2/https");
const logger = require("firebase-functions/logger");

// Import necessary libraries
require("dotenv").config();
const {QnAMaker} = require("botbuilder-ai");

// Configure the QnA endpoint with environment variables
const qnaEndpoint = {
  endpoint: process.env.AZURE_ENDPOINT,
  endpointKey: process.env.AZURE_API_KEY,
  knowledgeBaseId: process.env.KNOWLEDGE_BASE_ID,
};

// Initialize QnAMaker with the endpoint configuration
const qnaMaker = new QnAMaker(qnaEndpoint);

// Define and export the HTTP-triggered function
exports.getAnswer = onRequest(async (request, response) => {
  // Extract question from query parameters or request body
  const question = request.query.question || request.body.question;

  // Check if a question was provided
  if (!question) {
    return response.status(400).send("Please provide a question.");
  }

  try {
    // Call QnA Maker to get answers
    const result = await qnaMaker.getAnswers({question: question});

    // eslint-disable-next-line max-len
    // If answers are found, send the first one; otherwise, inform that no answer was found
    if (result && result.length > 0) {
      return response.status(200).json({answer: result[0].answer});
    } else {
      return response.status(200).json({answer: "No answer found."});
    }
  } catch (error) {
    // Log and return error message in case of failure
    logger.error("Error fetching answer:", error);
    return response.status(500).send("Error occurred while fetching answer.");
  }
});

已登录 Firebase。

enter image description here

  • 您可以在语言项目中获取知识库 URL,您需要在此处登录Azure AI Language Studio),导航到部署知识页面。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.