Skip to content

Instantly share code, notes, and snippets.

View Adolfi's full-sized avatar

Dennis Adolfi Adolfi

View GitHub Profile
@Adolfi
Adolfi / How to install Umbraco 8 with Unit Testing, Dependency Injection, Custom Mappings and Route Hijacking.md
Last active November 8, 2021 17:38
How to install Umbraco 8 with Dependency Injection, Custom Mappings and Route Hijacking

Installing Umbraco 8.x:

Create an empty ASP.NET Web Application (.NET Framework) in Visual Studio. Then run this following NuGet command:

PM> Install-Package UmbracoCms

Some of the requirements has changed for Umbraco v8, so make sure you development environment is up to speed otherwise you'll get stuck before even getting started.

Most importantly you'll need:

using Azure;
using Azure.AI.OpenAI;
using OpenAI.Chat;
AzureOpenAIClient azureClient = new(
new Uri("YOUR_API_ENDPOINT"),
new AzureKeyCredential("YOUR_API_KEY"));
ChatCompletion completion = azureClient.GetChatClient("YOUR_DEPLOYMENT_NAME").CompleteChat([
new UserChatMessage("What is the capital of France?"),
using Microsoft.ML;
using Microsoft.ML.Data;
public class FAQModel
{
[ColumnName("Question")]
public string Question {get;set;}
[ColumnName("Answer")]
public string Answer {get;set;}
[HttpGet]
[Route("/api/ml/train")]
public IActionResult Train()
{
var nodes = this.GetData();
var dataView = context.Data.LoadFromEnumerable<FAQModel>(dataNodes);
var pipeline = context.Transforms.Conversion.MapValueToKey(outputColumnName: "Label", inputColumnName: "Answer")
.Append(context.Transforms.Text.FeaturizeText("Features","Question"))
.Append(context.MulticlassClassification.Trainers.SdcaMaximumEntropy(labelColumnName: "Label", featureColumnName: "Features"))
[HttpGet]
[Route("/api/ml/consume")]
public IActionResult Consume(string question)
{
var loadedModel = context.Model.Load(Path.Combine(Directory.GetCurrentDirectory(), "data/faq-model.zip"), out var modelInputSchema);
var predictionEngine = context.Model.CreatePredictionEngine<FAQModel, PredictionModel>(loadedModel);
var prediction = predictionEngine.Predict(new FAQModel() { Question = question });
return Ok(prediction.PredictedAnswer);