Код: Выделить всё
Debug.WriteLine("beginning of the try");
string azureEndpoint = "https://redacted.cognitiveservices.azure.com/"; // Replace with your actual endpoint URL
string subscriptionKey = "redacted"; // Replace with your actual subscription key
Uri endpoint = new Uri(azureEndpoint);
AzureKeyCredential credential = new AzureKeyCredential(subscriptionKey);
QuestionAnsweringClient client = new QuestionAnsweringClient(endpoint, credential);
string projectName = "redacted";
string deploymentName = "production";
QuestionAnsweringProject project = new QuestionAnsweringProject(projectName, deploymentName);
Response response = client.GetAnswers("Where is your headquarters?", project);
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
{
Debug.WriteLine($"({answer.Confidence:P2}) {answer.Answer}");
Debug.WriteLine($"Source: {answer.Source}");
Debug.WriteLine($"Confidence: {answer.Confidence}");
}
Код: Выделить всё
private void button7_Click(object sender, RibbonControlEventArgs e)
{
var rng = Globals.ThisAddIn.Application.Selection.Range;
rng.Select();
var selectedText = rng.Text;
try
{
Debug.WriteLine("beginning of the try");
string azureEndpoint = "https://redacted.cognitiveservices.azure.com/"; // Replace with your actual endpoint URL
string subscriptionKey = "redacted"; // Replace with your actual subscription key
Uri endpoint = new Uri(azureEndpoint);
AzureKeyCredential credential = new AzureKeyCredential(subscriptionKey);
QuestionAnsweringClient client = new QuestionAnsweringClient(endpoint, credential);
string projectName = "redacted";
string deploymentName = "production";
QuestionAnsweringProject project = new QuestionAnsweringProject(projectName, deploymentName);
Response response = client.GetAnswers("Where is your headquarters?", project);
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
{
Debug.WriteLine($"({answer.Confidence:P2}) {answer.Answer}");
Debug.WriteLine($"Source: {answer.Source}");
Debug.WriteLine($"Confidence: {answer.Confidence}");
}
}
catch (Exception ex)
{
// Handle any exceptions (e.g., network errors, invalid response)
MessageBox.Show("Error calling Azure Language Service API: " + ex.Message );
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... ord-add-in
Мобильная версия