From 83d09ffb8d4e62c78ead270431340853f4fa7239 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Fri, 31 Aug 2018 12:52:52 -0500 Subject: [PATCH] Add colorful console log. Fix response format. --- BotSharp.Core/BotSharp.Core.csproj | 1 + BotSharp.Core/Engines/BotEngineBase.cs | 3 +++ BotSharp.Core/Engines/BotPredictor.cs | 3 +++ .../Engines/Classifiers/FasttextClassifier.cs | 13 ++++++++----- BotSharp.RestApi/Rasa/ParseController.cs | 3 +++ BotSharp.WebHost/BotSharp.WebHost.csproj | 8 ++++---- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/BotSharp.Core/BotSharp.Core.csproj b/BotSharp.Core/BotSharp.Core.csproj index 2c5cf3ad..15f6f290 100644 --- a/BotSharp.Core/BotSharp.Core.csproj +++ b/BotSharp.Core/BotSharp.Core.csproj @@ -51,6 +51,7 @@ + diff --git a/BotSharp.Core/Engines/BotEngineBase.cs b/BotSharp.Core/Engines/BotEngineBase.cs index 292cfba3..1d6301ba 100644 --- a/BotSharp.Core/Engines/BotEngineBase.cs +++ b/BotSharp.Core/Engines/BotEngineBase.cs @@ -9,8 +9,10 @@ using DotNetToolkit; using EntityFrameworkCore.BootKit; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Text; @@ -38,6 +40,7 @@ namespace BotSharp.Core.Engines { var preditor = new BotPredictor(); var doc = preditor.Predict(agent, request).Result; + var parameters = new Dictionary(); if(doc.Sentences[0].Entities == null) { diff --git a/BotSharp.Core/Engines/BotPredictor.cs b/BotSharp.Core/Engines/BotPredictor.cs index ebc410b7..38484dcb 100644 --- a/BotSharp.Core/Engines/BotPredictor.cs +++ b/BotSharp.Core/Engines/BotPredictor.cs @@ -8,10 +8,12 @@ using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Console = Colorful.Console; namespace BotSharp.Core.Engines { @@ -69,6 +71,7 @@ namespace BotSharp.Core.Engines await pipe.Predict(agent, data, meta.Pipeline.FirstOrDefault(x => x.Name == pipelines[pipeIdx])); } + Console.WriteLine($"Prediction result:", Color.Green); Console.WriteLine(JsonConvert.SerializeObject(data, new JsonSerializerSettings { Formatting = Formatting.Indented, diff --git a/BotSharp.Core/Engines/Classifiers/FasttextClassifier.cs b/BotSharp.Core/Engines/Classifiers/FasttextClassifier.cs index 1e8ae9a4..0f2ae607 100644 --- a/BotSharp.Core/Engines/Classifiers/FasttextClassifier.cs +++ b/BotSharp.Core/Engines/Classifiers/FasttextClassifier.cs @@ -29,12 +29,15 @@ namespace BotSharp.Core.Engines.Classifiers File.Delete(predictFileName); - doc.Sentences[0].Intent = new TextClassificationResult + if (!String.IsNullOrEmpty(output)) { - Classifier = "FasttextClassifier", - Label = output.Split(' ')[0].Split(new string[] { "__label__" }, StringSplitOptions.None)[1], - Confidence = decimal.Parse(output.Split(' ')[1]) - }; + doc.Sentences[0].Intent = new TextClassificationResult + { + Classifier = "FasttextClassifier", + Label = output.Split(' ')[0].Split(new string[] { "__label__" }, StringSplitOptions.None)[1], + Confidence = decimal.Parse(output.Split(' ')[1]) + }; + } return true; } diff --git a/BotSharp.RestApi/Rasa/ParseController.cs b/BotSharp.RestApi/Rasa/ParseController.cs index f6cdde8f..5e08ffbd 100644 --- a/BotSharp.RestApi/Rasa/ParseController.cs +++ b/BotSharp.RestApi/Rasa/ParseController.cs @@ -6,9 +6,11 @@ using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Text; +using Console = Colorful.Console; namespace BotSharp.RestApi.Rasa { @@ -47,6 +49,7 @@ namespace BotSharp.RestApi.Rasa body = reader.ReadToEnd(); } + Console.WriteLine($"Got message from {Request.Host}: {body}", Color.Green); if(request.Project ==null && !String.IsNullOrEmpty(body)) { request = JsonConvert.DeserializeObject(body); diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index bd2cd349..de054b8e 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -53,6 +53,10 @@ + + + + @@ -72,8 +76,4 @@ - - - -