Я пытаюсь настроить собственный ресурс для ответов на вопросы в 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, и с тех пор макет изменился. Может ли кто-нибудь подсказать мне, где найти эти значения в последней панели мониторинга 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.');
}
});
Большинство решений, которые я нашел, похоже, основаны на более старой версии портала Azure, и с тех пор макет изменился. Может ли кто-нибудь подсказать мне, где найти эти значения в последней панели мониторинга Azure?
Используйте приведенный ниже код для вашего требования.
Код:
/**
* 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.