📅  最后修改于: 2023-12-03 15:12:06.249000             🧑  作者: Mango
MS 项目是微软公司针对云计算和人工智能领域推出的一系列解决方案和工具。MS 项目包括多个子项目,涉及面广,主要包括以下几个方面:
MS 项目提供丰富的文档和教程,开发者可以参考官方文档进行学习和使用。
Azure 提供了多种语言的 SDK,开发者可以利用其提供的 API 进行开发。例如,使用 C# 开发 Azure Function:
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage);
}
Bot Framework 提供了丰富的文档和教程,开发者可以在其网站上进行注册和创建聊天机器人。例如,使用 Node.js 创建聊天机器人:
const { ActivityHandler } = require('botbuilder');
class EchoBot extends ActivityHandler {
constructor() {
super();
this.onMessage(async (context, next) => {
const echoText = context.activity.text;
await context.sendActivity(`You said '${ echoText }'`);
await next();
});
}
}
module.exports.EchoBot = EchoBot;
Cognitive Services 提供了属于自己的 API 密钥,开发者可以直接调用 API 进行开发。例如,使用 Python 调用计算机视觉服务:
import os
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from msrest.authentication import CognitiveServicesCredentials
subscription_key = os.environ['COMPUTER_VISION_SUBSCRIPTION_KEY']
endpoint = os.environ['COMPUTER_VISION_ENDPOINT']
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
remote_image_url = "https://upload.wikimedia.org/wikipedia/commons/1/19/Bill_Gates_June_2015.jpg"
description_results = computervision_client.describe_image(remote_image_url )
for caption in description_results.captions:
print(caption.text)
.NET Core 提供了跨平台的方式,开发者可以在 Windows、Mac 或者 Linux 上进行开发。例如,使用 C# 构建 Web API:
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}