fix swagger issue, fix logging
This commit is contained in:
parent
b481b0b6bf
commit
aa746f9204
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
|
@ -9,6 +10,6 @@ namespace BotSharp.Core.Abstractions
|
|||
public interface IInitializationLoader
|
||||
{
|
||||
int Priority { get; }
|
||||
void Initialize(IConfiguration config, IHostingEnvironment env);
|
||||
void Initialize(IConfiguration config, IWebHostEnvironment env);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using BotSharp.Platform.Models;
|
||||
using BotSharp.Platform.Models;
|
||||
using BotSharp.Platform.Models.AiRequest;
|
||||
using BotSharp.Platform.Models.AiResponse;
|
||||
using BotSharp.Platform.Models.Entities;
|
||||
|
|
@ -27,7 +27,7 @@ namespace BotSharp.Core.Engines
|
|||
Dc = new DefaultDataContextLoader().GetDefaultDc();
|
||||
}
|
||||
|
||||
public async Task<AiResponse> TextRequest(AiRequest request)
|
||||
public Task<AiResponse> TextRequest(AiRequest request)
|
||||
{
|
||||
var preditor = new BotPredictor();
|
||||
var doc = preditor.Predict(Agent, new AiRequest
|
||||
|
|
@ -44,8 +44,7 @@ namespace BotSharp.Core.Engines
|
|||
doc.Sentences[0].Entities = new List<NlpEntity>();
|
||||
}
|
||||
doc.Sentences[0].Entities.ForEach(x => parameters[x.Entity] = x.Value);
|
||||
|
||||
return new AiResponse
|
||||
return Task.FromResult(new AiResponse
|
||||
{
|
||||
/*Lang = request.Language,
|
||||
Timestamp = DateTime.UtcNow,
|
||||
|
|
@ -66,7 +65,7 @@ namespace BotSharp.Core.Engines
|
|||
IntentName = doc.Sentences[0].Intent?.Label
|
||||
}
|
||||
}*/
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/*public TrainingCorpus GetIntentExpressions(AgentBase agent)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using BotSharp.Core.Abstractions;
|
||||
using BotSharp.Core.Abstractions;
|
||||
using DotNetToolkit;
|
||||
using EntityFrameworkCore.BootKit;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
|
@ -14,7 +14,7 @@ namespace BotSharp.Core.Engines
|
|||
{
|
||||
public int Priority => 1;
|
||||
|
||||
public void Initialize(IConfiguration config, IHostingEnvironment env)
|
||||
public void Initialize(IConfiguration config, IWebHostEnvironment env)
|
||||
{
|
||||
var dc = new DefaultDataContextLoader().GetDefaultDc();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>0.2.2</Version>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Authors>Haiping Chen</Authors>
|
||||
<Description>BotSharp platform emulator which is compatible with Google Dialogflow.</Description>
|
||||
<PackageProjectUrl>https://github.com/Oceania2018/botsharp-dialogflow</PackageProjectUrl>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using BotSharp.Platform.Dialogflow.Models;
|
||||
using BotSharp.Platform.Dialogflow.Models;
|
||||
using BotSharp.Platform.Dialogflow.ViewModels;
|
||||
using BotSharp.Platform.Models.Agents;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -31,7 +31,7 @@ namespace BotSharp.Platform.Dialogflow.Controllers
|
|||
/// <summary>
|
||||
/// Import a agent from a uploaded zip file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="uploadedFile">Upload Zip File, meta.json is the extra data for customized function.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("import")]
|
||||
[ProducesResponseType(typeof(ImportedAgentViewModel), 200)]
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
{
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"Debug": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"Console": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
}
|
||||
//"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}//,
|
||||
//"Debug": {
|
||||
// "LogLevel": {
|
||||
// "Default": "Warning"
|
||||
// }
|
||||
//},
|
||||
//"Console": {
|
||||
// "LogLevel": {
|
||||
// "Default": "Warning"
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using Swashbuckle.AspNetCore.Swagger;
|
|||
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -59,14 +60,20 @@ namespace BotSharp.WebHost
|
|||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
var scheme = new OpenApiSecurityScheme()
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
||||
{
|
||||
In = ParameterLocation.Header,
|
||||
Description = "Please insert JWT with Bearer schema. Example: \"Authorization: Bearer {token}\"",
|
||||
Name = "Authorization",
|
||||
Type = SecuritySchemeType.ApiKey
|
||||
};
|
||||
c.AddSecurityDefinition("Bearer", scheme);
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{ new OpenApiSecurityScheme(){
|
||||
Reference = new OpenApiReference{Type = ReferenceType.SecurityScheme ,Id = "Bearer"}
|
||||
}, new List<string>(0) }
|
||||
});
|
||||
|
||||
var info = Configuration.GetSection("Swagger").Get<OpenApiInfo>();
|
||||
c.SwaggerDoc(info.Version, info);
|
||||
|
|
@ -76,9 +83,14 @@ namespace BotSharp.WebHost
|
|||
{
|
||||
c.IncludeXmlComments(filePath);
|
||||
}
|
||||
|
||||
|
||||
//c.OperationFilter<SwaggerFileUploadOperation>();
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, "BotSharp.Platform.Dialogflow.xml");
|
||||
if (File.Exists(xmlPath))
|
||||
{
|
||||
c.IncludeXmlComments(xmlPath);
|
||||
}
|
||||
|
||||
c.OperationFilter<SwaggerFileUploadOperation>();
|
||||
}).AddSwaggerGenNewtonsoftSupport();
|
||||
|
||||
// register platform dependency
|
||||
|
|
|
|||
|
|
@ -8,26 +8,20 @@ using System.Text;
|
|||
|
||||
namespace BotSharp.WebHost
|
||||
{
|
||||
//public class SwaggerFileUploadOperation : IOperationFilter
|
||||
//{
|
||||
public class SwaggerFileUploadOperation : IOperationFilter
|
||||
{
|
||||
|
||||
// public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
// {
|
||||
// if (operation.OperationId == "Import")
|
||||
// {
|
||||
// operation.Parameters.Clear();
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
if(context.MethodInfo.Name == "Import")
|
||||
{
|
||||
if(operation.RequestBody.Content.FirstOrDefault().Value?.Schema?.Properties.ContainsKey("uploadedFile") == true)
|
||||
{
|
||||
var p = operation.RequestBody.Content.FirstOrDefault();
|
||||
p.Value.Schema.Properties["uploadedFile"].Description = "Upload Zip File, meta.json is the extra data for customized function.";
|
||||
}
|
||||
}
|
||||
|
||||
// operation.Parameters.Add(new OpenApiParameter
|
||||
// {
|
||||
// Name = "uploadedFile",
|
||||
// In = "formData",
|
||||
// Description = "Upload Zip File, meta.json is the extra data for customized function.",
|
||||
// Required = true,
|
||||
// Type = "file"
|
||||
// });
|
||||
// operation.Consumes.Add("multipart/form-data");
|
||||
// operation.
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue