Cleanup and Backup Exists AiApi and Create a New .net 10 App and Configureit for using xDashboard ...
This commit is contained in:
-13
@@ -1,13 +0,0 @@
|
|||||||
#
|
|
||||||
bin
|
|
||||||
obj
|
|
||||||
|
|
||||||
#
|
|
||||||
Db/*
|
|
||||||
!Db/.gitkeep
|
|
||||||
|
|
||||||
#
|
|
||||||
Migrations/*
|
|
||||||
|
|
||||||
#
|
|
||||||
wwwroot/*
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Configuration.Entities
|
|
||||||
{
|
|
||||||
public class XAiConversationConfiguration : IEntityTypeConfiguration<XAiConversation>
|
|
||||||
{
|
|
||||||
public void Configure(EntityTypeBuilder<XAiConversation> builder)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Configure Navigations ...
|
|
||||||
builder
|
|
||||||
.HasMany(x => x.Messages)
|
|
||||||
.WithOne(x => x.Conversation)
|
|
||||||
.HasForeignKey(x => x.ConversationId)
|
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Configuration.Entities
|
|
||||||
{
|
|
||||||
public class XAiMessageConfiguration : IEntityTypeConfiguration<XAiMessage>
|
|
||||||
{
|
|
||||||
public void Configure(EntityTypeBuilder<XAiMessage> builder)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
builder
|
|
||||||
.HasOne(x => x.Conversation)
|
|
||||||
.WithMany(x => x.Messages)
|
|
||||||
.HasForeignKey(x => x.ConversationId)
|
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Configuration.Entities
|
|
||||||
{
|
|
||||||
public class XAiProjectConfiguration : IEntityTypeConfiguration<XAiProject>
|
|
||||||
{
|
|
||||||
public void Configure(EntityTypeBuilder<XAiProject> builder)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Configure Navigations ...
|
|
||||||
builder
|
|
||||||
.HasMany(x => x.Conversations)
|
|
||||||
.WithOne(x => x.Project)
|
|
||||||
.HasForeignKey(x => x.ProjectId)
|
|
||||||
.OnDelete(DeleteBehavior.NoAction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
namespace xAiApi.AI.Configuration
|
|
||||||
{
|
|
||||||
public class XAiApiConfiguration
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// AI Provider Client URL ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public string Url { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a System Message to Introduce Model ...
|
|
||||||
/// </summary>
|
|
||||||
public string Introduction { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Model Name ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public string Model { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Text Generator Model Name ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public string TextModel { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Code Generator Model Name ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public string CodeModel { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Image Generator Model Name ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public string ImageModel { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace xAiApi.AI.Constants
|
|
||||||
{
|
|
||||||
public partial struct ConfigurationNodeNames
|
|
||||||
{
|
|
||||||
public const string AI_API_SERVICE_NODE = "AiApiServiceConfiguration";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using xExceptions.Attributes;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Constants
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Several Ai Projects Type ...
|
|
||||||
/// </summary>
|
|
||||||
public enum XAiProjectEnum
|
|
||||||
{
|
|
||||||
[StringValue("None")]
|
|
||||||
None,
|
|
||||||
[StringValue("Default")]
|
|
||||||
Default,
|
|
||||||
[StringValue("Custom")]
|
|
||||||
Custom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xAiApi.AI.Interfaces;
|
|
||||||
using xAiApi.AI.Mppings;
|
|
||||||
using xAiApi.AI.Services;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DI
|
|
||||||
{
|
|
||||||
public static class AIExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Register AI Services ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
public static void AddXAIServices(
|
|
||||||
this IServiceCollection services
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Register AutoMapper Using Mapping Profiles ...
|
|
||||||
services.AddAutoMapper(typeof(MappingProfiles).Assembly);
|
|
||||||
|
|
||||||
//
|
|
||||||
// TODO: Remove this ...
|
|
||||||
services.AddSingleton<IXAIService, XAIService>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Since we Used Repositories in this Service,
|
|
||||||
// we have to Register it Scoped Lifetime ...
|
|
||||||
services.AddScoped<IXAiProvider, XAiProvider>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use AI Service Middlewares ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="builder"></param>
|
|
||||||
public static void UseXAIServices(this IApplicationBuilder builder)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Private ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Events;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.Events
|
|
||||||
{
|
|
||||||
public class XAiConversationEvents : XBaseRepositoryEvents<XAiConversation>, IXAiConversationEvents
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Events;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.Events
|
|
||||||
{
|
|
||||||
public class XAiMessageEvents : XBaseRepositoryEvents<XAiMessage>, IXAiMessageEvents
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Events;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.Events
|
|
||||||
{
|
|
||||||
public class XAiProjectEvents : XBaseRepositoryEvents<XAiProject>, IXAiProjectEvents
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiConversationGraphQLTypeHelper : XBaseGraphQLTypeHelper<XAiConversation, Guid>, IXAiConversationGraphQLTypeHelper
|
|
||||||
{
|
|
||||||
public XAiConversationGraphQLTypeHelper(
|
|
||||||
XDataServiceConfiguration configuration
|
|
||||||
) : base(configuration)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override string GetInQueryCollectionName()
|
|
||||||
{
|
|
||||||
return "aiConversations";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string GetInQuerySingleName()
|
|
||||||
{
|
|
||||||
return "aiConversation";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiConversationGraphQuery : XBaseGraphQLQuery<XAiConversation, Guid, XAiConversationGraphType, GuidGraphType>
|
|
||||||
{
|
|
||||||
public XAiConversationGraphQuery(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXAiConversationRepository repository,
|
|
||||||
IXAiConversationGraphQLTypeHelper helper
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
repository,
|
|
||||||
helper
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiConversationGraphSchema : Schema
|
|
||||||
{
|
|
||||||
public XAiConversationGraphSchema(IServiceProvider services) : base(services)
|
|
||||||
{
|
|
||||||
Query = (XAiConversationGraphQuery)services.GetService(typeof(XAiConversationGraphQuery));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiConversationGraphType : XBaseGraphObjectType<XAiConversation, Guid>
|
|
||||||
{
|
|
||||||
public XAiConversationGraphType() : base()
|
|
||||||
{
|
|
||||||
Field(x => x.Title);
|
|
||||||
Field(x => x.Messages);
|
|
||||||
Field(x => x.CreatedOn);
|
|
||||||
Field(x => x.UpdatedAt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiMessageGraphQLTypeHelper : XBaseGraphQLTypeHelper<XAiMessage, Guid>, IXAiMessageGraphQLTypeHelper
|
|
||||||
{
|
|
||||||
public XAiMessageGraphQLTypeHelper(
|
|
||||||
XDataServiceConfiguration configuration
|
|
||||||
) : base(configuration)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override string GetInQueryCollectionName()
|
|
||||||
{
|
|
||||||
return "aiMessages";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string GetInQuerySingleName()
|
|
||||||
{
|
|
||||||
return "aiMessage";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiMessageGraphQuery : XBaseGraphQLQuery<XAiMessage, Guid, XAiMessageGraphType, GuidGraphType>
|
|
||||||
{
|
|
||||||
public XAiMessageGraphQuery(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXAiMessageRepository repository,
|
|
||||||
IXAiMessageGraphQLTypeHelper helper
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
repository,
|
|
||||||
helper
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiMessageGraphSchema : Schema
|
|
||||||
{
|
|
||||||
public XAiMessageGraphSchema(IServiceProvider services) : base(services)
|
|
||||||
{
|
|
||||||
Query = (XAiMessageGraphQuery)services.GetService(typeof(XAiMessageGraphQuery));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiMessageGraphType : XBaseGraphObjectType<XAiMessage, Guid>
|
|
||||||
{
|
|
||||||
public XAiMessageGraphType() : base()
|
|
||||||
{
|
|
||||||
Field(x => x.Role);
|
|
||||||
Field(x => x.Content);
|
|
||||||
Field(x => x.Metadata);
|
|
||||||
Field(x => x.CreatedOn);
|
|
||||||
Field(x => x.UpdatedAt);
|
|
||||||
Field(x => x.ConversationId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiProjectGraphQLTypeHelper : XBaseGraphQLTypeHelper<XAiProject, Guid>, IXAiProjectGraphQLTypeHelper
|
|
||||||
{
|
|
||||||
public XAiProjectGraphQLTypeHelper(
|
|
||||||
XDataServiceConfiguration configuration
|
|
||||||
) : base(configuration)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override string GetInQueryCollectionName()
|
|
||||||
{
|
|
||||||
return "aiProjects";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string GetInQuerySingleName()
|
|
||||||
{
|
|
||||||
return "aiProjects";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiProjectGraphQuery : XBaseGraphQLQuery<XAiProject, Guid, XAiProjectGraphType, GuidGraphType>
|
|
||||||
{
|
|
||||||
public XAiProjectGraphQuery(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXAiProjectRepository repository,
|
|
||||||
IXAiProjectGraphQLTypeHelper helper
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
repository,
|
|
||||||
helper
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiProjectGraphSchema : Schema
|
|
||||||
{
|
|
||||||
public XAiProjectGraphSchema(IServiceProvider services) : base(services)
|
|
||||||
{
|
|
||||||
Query = (XAiProjectGraphQuery)services.GetService(typeof(XAiProjectGraphQuery));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.DataHelper.GraphQL
|
|
||||||
{
|
|
||||||
public class XAiProjectGraphType : XBaseGraphObjectType<XAiProject, Guid>
|
|
||||||
{
|
|
||||||
public XAiProjectGraphType() : base()
|
|
||||||
{
|
|
||||||
Field(x => x.Title);
|
|
||||||
Field(x => x.Prompt);
|
|
||||||
Field(x => x.CreatedOn);
|
|
||||||
Field(x => x.UpdatedAt);
|
|
||||||
Field(x => x.Description);
|
|
||||||
Field(x => x.Conversations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
using xCommons.Extensions;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiModels.Models;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Extensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extensions which used for AiModels ...
|
|
||||||
/// </summary>
|
|
||||||
public static class AiModelsExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Converts Entity to Dto regardsless of Owner and NavigationProperties ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static XAiMessageDto ToDto(this XAiMessage source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XAiMessageDto result = null;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!source.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = new XAiMessageDto();
|
|
||||||
result = result.UpdateData(
|
|
||||||
updateWith: source,
|
|
||||||
propertyBlackList: new List<string>
|
|
||||||
{
|
|
||||||
nameof(XAiMessage.Deleted),
|
|
||||||
nameof(XAiMessageDto.Owner),
|
|
||||||
nameof(XAiMessage.Conversation),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts Entity to Dto regardsless of Owner and NavigationProperties ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static XAiProjectDto ToDto(this XAiProject source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XAiProjectDto result = null;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!source.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = new XAiProjectDto();
|
|
||||||
result = result.UpdateData(
|
|
||||||
updateWith: source,
|
|
||||||
propertyBlackList: new List<string>
|
|
||||||
{
|
|
||||||
nameof(XAiProject.Deleted),
|
|
||||||
nameof(XAiProjectDto.Owner),
|
|
||||||
nameof(XAiProject.Conversations),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts Entity to Dto regardsless of Owner and NavigationProperties ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static XAiConversationDto ToDto(this XAiConversation source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XAiConversationDto result = null;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!source.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = new XAiConversationDto();
|
|
||||||
result = result.UpdateData(
|
|
||||||
updateWith: source,
|
|
||||||
propertyBlackList: new List<string>
|
|
||||||
{
|
|
||||||
nameof(XAiConversation.Deleted),
|
|
||||||
nameof(XAiConversation.Project),
|
|
||||||
nameof(XAiConversationDto.Owner),
|
|
||||||
nameof(XAiConversation.Messages),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xAiApi.AI.Configuration;
|
|
||||||
using xAiApi.AI.Constants;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Extensions
|
|
||||||
{
|
|
||||||
public static class XAiApiConfigurationExtension
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extract Configuration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static XAiApiConfiguration GetXAiApiConfiguration(this IConfiguration source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var section = source.GetSection(ConfigurationNodeNames.AI_API_SERVICE_NODE);
|
|
||||||
var result = section.Get<XAiApiConfiguration>();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add XAiApiConfiguration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <param name="configuration"></param>
|
|
||||||
public static void AddXAiApiConfiguration(
|
|
||||||
this IServiceCollection source,
|
|
||||||
XAiApiConfiguration configuration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (!configuration.IsValid())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
source.AddSingleton(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validate XAiApiConfiguration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="configuration"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsValid(this XAiApiConfiguration configuration)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result =
|
|
||||||
!configuration.IsNull() &&
|
|
||||||
!configuration.Url.IsNullOrEmpty() &&
|
|
||||||
configuration.Url.IsValidUrl() &&
|
|
||||||
!configuration.TextModel.IsNullOrEmpty();
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xPushService.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Hubs
|
|
||||||
{
|
|
||||||
public class XAiConversationEntityHub : XBaseEntityHub<XAiConversation, Guid>
|
|
||||||
{
|
|
||||||
public XAiConversationEntityHub(ILogger<XBaseHub> logger) : base(logger)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xPushService.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Hubs
|
|
||||||
{
|
|
||||||
public class XAiMessageEntityHub : XBaseEntityHub<XAiMessage, Guid>
|
|
||||||
{
|
|
||||||
public XAiMessageEntityHub(ILogger<XBaseHub> logger) : base(logger)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xPushService.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Hubs
|
|
||||||
{
|
|
||||||
public class XAiProjectEntityHub : XBaseEntityHub<XAiProject, Guid>
|
|
||||||
{
|
|
||||||
public XAiProjectEntityHub(ILogger<XBaseHub> logger) : base(logger)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiConversationEvents : IXBaseRepositoryEvents<XAiConversation>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiConversationGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XAiConversation, Guid>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiConversationRepository : IXBaseRepository<XAiConversation, Guid>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiMessageEvents : IXBaseRepositoryEvents<XAiMessage>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiMessageGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XAiMessage, Guid>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiMessageRepository : IXBaseRepository<XAiMessage, Guid>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiProjectEvents : IXBaseRepositoryEvents<XAiProject>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiProjectGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XAiProject, Guid>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces.Entities
|
|
||||||
{
|
|
||||||
public interface IXAiProjectRepository : IXBaseRepository<XAiProject, Guid>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXAIMemoryService
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.AI;
|
|
||||||
using Microsoft.SemanticKernel.ChatCompletion;
|
|
||||||
using xAiApi.AI.Configuration;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXAIService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides Options for Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
ChatOptions ChatOptions { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides History for Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
ChatHistory ChatHistory { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Client for Text Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
IChatClient TextGenreatorClient { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Client for Code Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
IChatClient CodeGenreatorClient { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Client for Image Chats ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
IChatClient ImageGenreatorClient { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configuration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
XAiApiConfiguration Configuration { get; }
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Text ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<string> GetTextResponseAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<ChatResponse> GetResponseAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">ChatMessage instance</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<ChatResponse> GetResponseByChatMessageAsync(
|
|
||||||
ChatMessage message,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messages">ChatMessage Enumerable instance</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<ChatResponse> GetResponseByChatMessagesAsync(
|
|
||||||
IEnumerable<ChatMessage> messages,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate Text Response Stream ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IAsyncEnumerable<ChatResponseUpdate> GetReponseStreamAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate Text Response Stream ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IAsyncEnumerable<string> GetTextReponseStreamAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using xAiApi.AI.Configuration;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xIdentityModels.Models;
|
|
||||||
using xModels.Dtos;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Interfaces
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provide Ai Capabilities Using AI Service ...
|
|
||||||
/// using User Data Info ...
|
|
||||||
/// </summary>
|
|
||||||
public interface IXAiProvider
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Configuration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public XAiApiConfiguration Configuration { get; }
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Helpers ...
|
|
||||||
/// <summary>
|
|
||||||
/// Converts Entity to Dto ...
|
|
||||||
/// <see cref="XAiProjectDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entity"><see cref="XAiProject"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XAiProjectDto> ToDto(
|
|
||||||
XAiProject entity,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts Entity to Dto ...
|
|
||||||
/// <see cref="XAiMessageDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entity"><see cref="XAiMessage"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XAiMessageDto> ToDto(
|
|
||||||
XAiMessage entity,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts Entity to Dto ...
|
|
||||||
/// <see cref="XAiConversationDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entity"><see cref="XAiConversation"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XAiConversationDto> ToDto(
|
|
||||||
XAiConversation entity,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a List of Entities to Dtos ...
|
|
||||||
/// <see cref="XAiProjectDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entities"><see cref="XAiProject"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<XAiProjectDto>> ToDtos(
|
|
||||||
IEnumerable<XAiProject> entities,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a List of Entities to Dtos ...
|
|
||||||
/// <see cref="XAiMessageDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entities"><see cref="XAiMessage"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<XAiMessageDto>> ToDtos(
|
|
||||||
IEnumerable<XAiMessage> entities,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a List of Entities to Dtos ...
|
|
||||||
/// <see cref="XAiConversationDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entities"><see cref="XAiConversation"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IEnumerable<XAiConversationDto>> ToDtos(
|
|
||||||
IEnumerable<XAiConversation> entities,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a QueryResult of Entities to Dtos ...
|
|
||||||
/// <see cref="XAiProjectDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="queryResult"><see cref="XAiProject"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XQueryResult<XAiProjectDto>> ToDtoQueryResult(
|
|
||||||
XQueryResult<XAiProject> queryResult,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a QueryResult of Entities to Dtos ...
|
|
||||||
/// <see cref="XAiMessageDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="queryResult"><see cref="XAiMessage"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XQueryResult<XAiMessageDto>> ToDtoQueryResult(
|
|
||||||
XQueryResult<XAiMessage> queryResult,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a QueryResult of Entities to Dtos ...
|
|
||||||
/// <see cref="XAiConversationDto"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="queryResult"><see cref="XAiConversation"/></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XQueryResult<XAiConversationDto>> ToDtoQueryResult(
|
|
||||||
XQueryResult<XAiConversation> queryResult,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check Permission for Ai Actions ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="userInfo"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<bool> HasPermission(
|
|
||||||
string projectId = null,
|
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepare Prompt ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="userInfo"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<string> PreparePrompt(
|
|
||||||
string prompt,
|
|
||||||
string projectId = null,
|
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Question ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="userInfo"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<XAiMessageDto> Ask(
|
|
||||||
string prompt,
|
|
||||||
string projectId = null,
|
|
||||||
string conversationId = null,
|
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Question in Streaming ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="userInfo"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
IAsyncEnumerable<XAiMessageUpdateDto> AskStream(
|
|
||||||
string prompt,
|
|
||||||
string projectId = null,
|
|
||||||
string conversationId = null,
|
|
||||||
XUserClaimsInfoDto userInfo = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using xModels.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Models.Dtos
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Ai Ask Request Data Transfer Object ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiAskRequestDto : XBaseDto
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provided Prompt for Ask ...
|
|
||||||
/// </summary>
|
|
||||||
[FromQuery]
|
|
||||||
public string Prompt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ai Selected Project Id, Optional ...
|
|
||||||
/// if null, Use Default Project for Authenticated User ...
|
|
||||||
/// </summary>
|
|
||||||
[FromQuery]
|
|
||||||
public string ProjectId { get; set; } = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ai Selected Conversation of Project, Optional ...
|
|
||||||
/// if null, Create new Conversation in Selected Project ...
|
|
||||||
/// </summary>
|
|
||||||
[FromQuery]
|
|
||||||
public string ConversationId { get; set; } = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Extensions.AI;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xModels.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Models.Dtos
|
|
||||||
{
|
|
||||||
public class XAiRequirementDto : XBaseDto
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Prepared Ai Project ...
|
|
||||||
/// if Exists one Using Project ID,
|
|
||||||
/// if not Created Default Project ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiProjectDto AiProject { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepared Ai Conversation ...
|
|
||||||
/// if Exists one Using Conversation ID,
|
|
||||||
/// if not Created new Conversation ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiConversationDto AiConversation { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prepared Chat History for Asking ...
|
|
||||||
/// including Asked Prompt ...
|
|
||||||
/// </summary>
|
|
||||||
public IList<ChatMessage> ChatHistory { get; set; } = new List<ChatMessage>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check User has Permission on
|
|
||||||
/// Project, Conversation and LLM Usages also ...
|
|
||||||
/// </summary>
|
|
||||||
public bool HasPermission { get; set; } = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check Ai Project is Default Project of Specified User or not ...
|
|
||||||
/// Default Project is Main Conversations Contains ...
|
|
||||||
/// </summary>
|
|
||||||
public bool IsDefaultProject { get; set; } = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check Ai Conversations is New Conversation or not ...
|
|
||||||
/// </summary>
|
|
||||||
public bool IsFirstConversation { get; set; } = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check Model is Validate or not ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool IsValid()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result =
|
|
||||||
HasPermission &&
|
|
||||||
!AiProject.IsNullOrDefault() &&
|
|
||||||
!AiConversation.IsNullOrDefault();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using xModels.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Models.Entities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Conversation Describe ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiConversation : XBaseGuidIDEntity
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// User Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
[Required]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string OwnerId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Title of Conversation ...
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string Title { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Created Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime CreatedOn { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updated Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Messages of Conversation ...
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<XAiMessage> Messages { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Project ID ...
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public Guid ProjectId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Project ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiProject Project { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using xModels.Base;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xAiModels.Constants;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Models.Entities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Message Model of Ai ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiMessage : XBaseGuidIDEntity
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// User Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
[Required]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string OwnerId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message of Chat ...
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public string Content { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Role of Message ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiChatRole Role { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Created Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime CreatedOn { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updated Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Conversation Id ...
|
|
||||||
/// </summary>
|
|
||||||
[StringLength(255)]
|
|
||||||
public Guid ConversationId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Conversation ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiConversation Conversation { get; set; }
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Meta Data Property ...
|
|
||||||
private string _metadata;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Meta Data of Message ...
|
|
||||||
/// </summary>
|
|
||||||
[NotMapped]
|
|
||||||
public IDictionary<string, object> Metadata { get; private set; } = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Meta Data of MEssage in Json ...
|
|
||||||
/// </summary>
|
|
||||||
public string MeatDatas
|
|
||||||
{
|
|
||||||
//
|
|
||||||
get => _metadata;
|
|
||||||
|
|
||||||
//
|
|
||||||
set
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Converts Json String to Dictionary ...
|
|
||||||
if (!value.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
Metadata = value.FromJSON<IDictionary<string, object>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
_metadata = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using xModels.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Models.Entities
|
|
||||||
{
|
|
||||||
public class XAiProject : XBaseGuidIDEntity
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// User Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
[Required]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string OwnerId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Title of Project ...
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
[StringLength(255)]
|
|
||||||
public string Title { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Description of Project ...
|
|
||||||
/// </summary>
|
|
||||||
[StringLength(1000)]
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Prompt for Project Start ...
|
|
||||||
/// </summary>
|
|
||||||
public string Prompt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Created Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime CreatedOn { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updated Time ...
|
|
||||||
/// </summary>
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Conversations ...
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<XAiConversation> Conversations { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiModels.Models;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Mppings
|
|
||||||
{
|
|
||||||
public class MappingProfiles : Profile
|
|
||||||
{
|
|
||||||
public MappingProfiles()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region Entity to Dto ...
|
|
||||||
//
|
|
||||||
CreateMap<XAiProject, XAiProjectDto>()
|
|
||||||
.ForMember(
|
|
||||||
x => x.Owner,
|
|
||||||
opt => opt.MapFrom<XAiProjectOwnerMappingResolver>()
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
CreateMap<XAiMessage, XAiMessageDto>()
|
|
||||||
.ForMember(
|
|
||||||
x => x.Owner,
|
|
||||||
opt => opt.MapFrom<XAiMessageOwnerMappingResolver>()
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
CreateMap<XAiConversation, XAiConversationDto>()
|
|
||||||
.ForMember(
|
|
||||||
x => x.Owner,
|
|
||||||
opt => opt.MapFrom<XAiConversationOwnerMappingResolver>()
|
|
||||||
);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Dto to Entity ...
|
|
||||||
CreateMap<XAiProjectDto, XAiProject>();
|
|
||||||
CreateMap<XAiMessageDto, XAiMessage>();
|
|
||||||
CreateMap<XAiConversationDto, XAiConversation>();
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Mppings
|
|
||||||
{
|
|
||||||
public class XAiConversationOwnerMappingResolver : XBaseOwnerMappingResolver<XAiConversation, XAiConversationDto>
|
|
||||||
{
|
|
||||||
public XAiConversationOwnerMappingResolver(
|
|
||||||
IXIdentityProvider identityProvider
|
|
||||||
) : base(identityProvider)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Mppings
|
|
||||||
{
|
|
||||||
public class XAiMessageOwnerMappingResolver : XBaseOwnerMappingResolver<XAiMessage, XAiMessageDto>
|
|
||||||
{
|
|
||||||
public XAiMessageOwnerMappingResolver(
|
|
||||||
IXIdentityProvider identityProvider
|
|
||||||
) : base(identityProvider)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Mppings
|
|
||||||
{
|
|
||||||
public class XAiProjectOwnerMappingResolver : XBaseOwnerMappingResolver<XAiProject, XAiProjectDto>
|
|
||||||
{
|
|
||||||
public XAiProjectOwnerMappingResolver(
|
|
||||||
IXIdentityProvider identityProvider
|
|
||||||
) : base(identityProvider)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using xModels.Dtos;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using xIdentityService.Extensions;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Mppings
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// an AutoMapper Value Resolver for Mapping TEntity to TDto
|
|
||||||
/// When TEntity Has OwnerId Property and Owner ...
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TEntity"></typeparam>
|
|
||||||
/// <typeparam name="TDto"></typeparam>
|
|
||||||
public abstract class XBaseOwnerMappingResolver<TEntity, TDto> : IValueResolver<TEntity, TDto, XPersonDto>
|
|
||||||
where TDto : class
|
|
||||||
where TEntity : class
|
|
||||||
{
|
|
||||||
//
|
|
||||||
private string destPropertyName = "Owner";
|
|
||||||
private string srcPropertyName = "OwnerId";
|
|
||||||
private readonly IXIdentityProvider identityProvider;
|
|
||||||
|
|
||||||
public XBaseOwnerMappingResolver(
|
|
||||||
IXIdentityProvider identityProvider
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.identityProvider = identityProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XPersonDto Resolve(
|
|
||||||
TEntity source,
|
|
||||||
TDto destination,
|
|
||||||
XPersonDto destMember,
|
|
||||||
ResolutionContext context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPersonDto result = null;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Source is not Null ...
|
|
||||||
if (source.IsNull())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check OwnerId Exists ...
|
|
||||||
var isOwnerExists = source.HasProperty(srcPropertyName);
|
|
||||||
if (!isOwnerExists)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve OwnerId from Source ...
|
|
||||||
var ownerId = source.GetProperty<TEntity, string>(srcPropertyName);
|
|
||||||
isOwnerExists = !ownerId.IsNullOrEmpty();
|
|
||||||
if (!isOwnerExists)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Private Trusted Device ...
|
|
||||||
var device = identityProvider.GetDevice();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Specified OwnerId's UserInfo ...
|
|
||||||
var userInfo = identityProvider.GetUserInfo(
|
|
||||||
device: device,
|
|
||||||
userSelectByParam: ownerId
|
|
||||||
).RunTask();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check UserInfo Exists ...
|
|
||||||
if (!userInfo.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Converts UserInfo to XPersonDto ...
|
|
||||||
result = userInfo.ToXPersonDto();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Setting Dest Member ...
|
|
||||||
destMember = result;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Setting Destination Property Value ...
|
|
||||||
destination.SetProperty(destPropertyName, result);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using xAiApi.AI.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Services
|
|
||||||
{
|
|
||||||
public class XAIMemoryService : IXAIMemoryService
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,425 +0,0 @@
|
|||||||
using System;
|
|
||||||
using OllamaSharp;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.AI;
|
|
||||||
using xAiApi.AI.Interfaces;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xExceptions.Constants;
|
|
||||||
using xAiApi.AI.Configuration;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.SemanticKernel.ChatCompletion;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace xAiApi.AI.Services
|
|
||||||
{
|
|
||||||
public class XAIService : IXAIService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provides Options for Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public ChatOptions ChatOptions { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides History for Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public ChatHistory ChatHistory { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Client for Text Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public IChatClient TextGenreatorClient { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Client for Code Chat ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public IChatClient CodeGenreatorClient { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a Client for Image Chats ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public IChatClient ImageGenreatorClient { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configuration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <value></value>
|
|
||||||
public XAiApiConfiguration Configuration { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructing Service ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="configuration">configuration ...</param>
|
|
||||||
public XAIService(
|
|
||||||
XAiApiConfiguration configuration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Configuration = configuration;
|
|
||||||
|
|
||||||
//
|
|
||||||
// here we are Initialize Text Generator Model ...
|
|
||||||
TextGenreatorClient = new ChatClientBuilder(new OllamaApiClient(
|
|
||||||
new Uri(configuration.Url),
|
|
||||||
configuration.TextModel
|
|
||||||
))
|
|
||||||
// .UseFunctionInvocation()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Code Generator Client ...
|
|
||||||
if (!configuration.CodeModel.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
CodeGenreatorClient = new ChatClientBuilder(new OllamaApiClient(
|
|
||||||
new Uri(configuration.Url),
|
|
||||||
configuration.CodeModel
|
|
||||||
))
|
|
||||||
// .UseFunctionInvocation()
|
|
||||||
.Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Image Generator Client ...
|
|
||||||
if (!configuration.ImageModel.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ImageGenreatorClient = new ChatClientBuilder(new OllamaApiClient(
|
|
||||||
new Uri(configuration.Url),
|
|
||||||
configuration.ImageModel
|
|
||||||
))
|
|
||||||
// .UseFunctionInvocation()
|
|
||||||
.Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Configuring Chant Options ...
|
|
||||||
ChatOptions = new ChatOptions()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Preparing Tools ...
|
|
||||||
// Tools = [
|
|
||||||
// //
|
|
||||||
// // Tempreature Tool ...
|
|
||||||
// AIFunctionFactory.Create((string location, string unit) => {
|
|
||||||
// //
|
|
||||||
// var temp = Random.Shared.Next(5, 20);
|
|
||||||
// var cond = Random.Shared.Next(0, 1) == 0 ? "sunny" : "rainy";
|
|
||||||
|
|
||||||
// //
|
|
||||||
// var result = $"The weather is {temp} degrees C and {cond}.";
|
|
||||||
|
|
||||||
// //
|
|
||||||
// return result;
|
|
||||||
// },
|
|
||||||
// "get_current_weather",
|
|
||||||
// "Get the current weather in given location"
|
|
||||||
// )
|
|
||||||
// ],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Text Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<ChatResponse> GetResponseAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid = !prompt.IsNullOrEmpty();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Preparing Prompt ...
|
|
||||||
prompt = await PreparePrompt(
|
|
||||||
prompt: prompt,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate Response ...
|
|
||||||
var result = await TextGenreatorClient
|
|
||||||
.GetResponseAsync(
|
|
||||||
chatMessage: prompt,
|
|
||||||
options: ChatOptions,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">ChatMessage instance</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<ChatResponse> GetResponseByChatMessageAsync(
|
|
||||||
ChatMessage message,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid = !message.IsNull() && !message.Contents.HasChild();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Preparing Prompt ...
|
|
||||||
var prompt = await PreparePrompt(
|
|
||||||
message: message,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate Response ...
|
|
||||||
var result = await TextGenreatorClient
|
|
||||||
.GetResponseAsync(
|
|
||||||
chatMessage: prompt,
|
|
||||||
options: ChatOptions,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Response ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messages">ChatMessage Enumerable instance</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<ChatResponse> GetResponseByChatMessagesAsync(
|
|
||||||
IEnumerable<ChatMessage> messages,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid = !messages.IsNull() && messages.HasChild();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Preparing Prompt ...
|
|
||||||
var prompt = await PreparePrompt(
|
|
||||||
messages: messages,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate Response ...
|
|
||||||
var result = await TextGenreatorClient
|
|
||||||
.GetResponseAsync(
|
|
||||||
messages: prompt,
|
|
||||||
options: ChatOptions,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generated Text ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<string> GetTextResponseAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var response = await GetResponseAsync(
|
|
||||||
prompt: prompt,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return response.Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate Text Response Stream ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async IAsyncEnumerable<string> GetTextReponseStreamAsync(
|
|
||||||
string prompt,
|
|
||||||
[EnumeratorCancellation]
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid = !prompt.IsNullOrEmpty();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Preparing Prompt ...
|
|
||||||
prompt = PreparePrompt(
|
|
||||||
prompt: prompt,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
)
|
|
||||||
.RunTask();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate Response ...
|
|
||||||
var stream = TextGenreatorClient
|
|
||||||
.GetStreamingResponseAsync(
|
|
||||||
chatMessage: prompt,
|
|
||||||
options: ChatOptions,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
await foreach (var response in stream)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (response.IsNull())
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var model = response.Text;
|
|
||||||
yield return model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate Text Response Stream ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public IAsyncEnumerable<ChatResponseUpdate> GetReponseStreamAsync(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid = !prompt.IsNullOrEmpty();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Preparing Prompt ...
|
|
||||||
prompt = PreparePrompt(
|
|
||||||
prompt: prompt,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
)
|
|
||||||
.RunTask();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate Response ...
|
|
||||||
var result = TextGenreatorClient
|
|
||||||
.GetStreamingResponseAsync(
|
|
||||||
chatMessage: prompt,
|
|
||||||
options: ChatOptions,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Code Actions ...
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Image Actions ...
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Private ...
|
|
||||||
/// <summary>
|
|
||||||
/// Preparing Prompt for AI ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task<string> PreparePrompt(
|
|
||||||
string prompt,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await Task.Run(() =>
|
|
||||||
{
|
|
||||||
return prompt;
|
|
||||||
}, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Preparing Prompt for AI ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task<ChatMessage> PreparePrompt(
|
|
||||||
ChatMessage message,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await Task.Run(() =>
|
|
||||||
{
|
|
||||||
return message;
|
|
||||||
}, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Preparing Prompt for AI ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messages"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task<IEnumerable<ChatMessage>> PreparePrompt(
|
|
||||||
IEnumerable<ChatMessage> messages,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await Task.Run(() =>
|
|
||||||
{
|
|
||||||
return messages;
|
|
||||||
}, cancellationToken);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using xCommons.Controllers;
|
using xCommons.Controllers;
|
||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
|
|||||||
@@ -1,193 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xCommons.Attributes;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityHelper;
|
|
||||||
using xIdentityService.Controllers;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Test all Authentication Policies ...
|
|
||||||
/// </summary>
|
|
||||||
[RequireXPowered(false)]
|
|
||||||
public class TestIdentity : XIBaseController
|
|
||||||
{
|
|
||||||
public TestIdentity(
|
|
||||||
ILogger<TestIdentity> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Test Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// API Read Scope
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message</returns>
|
|
||||||
[HttpGet("PassReadAccess")]
|
|
||||||
[Authorize(Policy = XPolicies.ReadAccess)]
|
|
||||||
public ActionResult<string> PassReadAccess()
|
|
||||||
{
|
|
||||||
return Ok("Read Access Passed ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API Write Scope
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message</returns>
|
|
||||||
[HttpGet("PassWriteAccess")]
|
|
||||||
[Authorize(Policy = XPolicies.WriteAccess)]
|
|
||||||
public ActionResult<string> PassWriteAccess()
|
|
||||||
{
|
|
||||||
return Ok("Write Access Passed ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API Admin Scope
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message</returns>
|
|
||||||
[HttpGet("PassAdminAccess")]
|
|
||||||
[Authorize(Policy = XPolicies.AdminAccess)]
|
|
||||||
public ActionResult<string> PassAdminAccess()
|
|
||||||
{
|
|
||||||
return Ok("Admin Access Passed ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// API Manage Scop
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message</returns>
|
|
||||||
[HttpGet("PassManageAccess")]
|
|
||||||
[Authorize(Policy = XPolicies.ManageAccess)]
|
|
||||||
public ActionResult<string> PassManageAccess()
|
|
||||||
{
|
|
||||||
return Ok("Manage Access Passed ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Action which returns a List of Authenticated User Claims
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which represent current user's claims</returns>
|
|
||||||
[HttpGet("HiClaims")]
|
|
||||||
[Authorize(Policy = XPolicies.User)]
|
|
||||||
public ActionResult<string> HiClaims()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = new
|
|
||||||
{
|
|
||||||
name = User.Identity.Name,
|
|
||||||
claims = User.Claims.Select(c => new
|
|
||||||
{
|
|
||||||
c.Type,
|
|
||||||
c.Value
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Hello User for Checking Authentication and Policy
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which contains authenticated user name</returns>
|
|
||||||
[HttpGet("HiUser")]
|
|
||||||
[Authorize(Policy = XPolicies.User)]
|
|
||||||
public ActionResult<string> HiUser()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = $"Hi User: {User.Identity.Name} ...";
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Hello User for Checking Authentication and Policy
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which contains authenticated user name</returns>
|
|
||||||
[HttpGet("HiEnabledUser")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public ActionResult<string> HiEnabledUser()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = $"Hi User: {User.Identity.Name} is Enabled ...";
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Hello User for Checking Authentication and Policy
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which contains authenticated user name</returns>
|
|
||||||
[HttpGet("HiAgent")]
|
|
||||||
[Authorize(Policy = XPolicies.Agent)]
|
|
||||||
public ActionResult<string> HiAgent()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = $"Hi Agent: {User.Identity.Name} ...";
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Hello User for Checking Authentication and Policy
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which contains authenticated user name</returns>
|
|
||||||
[HttpGet("HiEnabledAgent")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAgent)]
|
|
||||||
public ActionResult<string> HiEnabledAgent()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = $"Hi Agent: {User.Identity.Name} is Enabled ...";
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Hello User for Checking Authentication and Policy
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which contains authenticated user name</returns>
|
|
||||||
[HttpGet("HiAdmin")]
|
|
||||||
[Authorize(Policy = XPolicies.Admin)]
|
|
||||||
public ActionResult<string> HiAdmin()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = $"Hi Admin: {User.Identity.Name} ...";
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a simple Hello User for Checking Authentication and Policy
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string message which contains authenticated user name</returns>
|
|
||||||
[HttpGet("HiEnabledAdmin")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
||||||
public ActionResult<string> HiEnabledAdmin()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xIdentityHelper;
|
||||||
|
using xIdentityService.Controllers;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
|
||||||
|
namespace xAiApi.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Test all Authentication Policies ...
|
||||||
|
/// </summary>
|
||||||
|
[RequireXPowered(false)]
|
||||||
|
public class TestIdentityController : XBaseIdentityController
|
||||||
|
{
|
||||||
|
public TestIdentityController(
|
||||||
|
ILogger<TestIdentityController> logger,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
XValidationProvider validationProvider
|
||||||
|
) : base(
|
||||||
|
logger,
|
||||||
|
appConfiguration,
|
||||||
|
identityProvider,
|
||||||
|
validationProvider
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Test Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// API Read Scope
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[HttpGet ("PassReadAccess")]
|
||||||
|
[Authorize (Policy = XPolicies.ReadAccess)]
|
||||||
|
public ActionResult<string> PassReadAccess () {
|
||||||
|
return Ok ("Read Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Write Scope
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[HttpGet ("PassWriteAccess")]
|
||||||
|
[Authorize (Policy = XPolicies.WriteAccess)]
|
||||||
|
public ActionResult<string> PassWriteAccess () {
|
||||||
|
return Ok ("Write Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Admin Scope
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[HttpGet ("PassAdminAccess")]
|
||||||
|
[Authorize (Policy = XPolicies.AdminAccess)]
|
||||||
|
public ActionResult<string> PassAdminAccess () {
|
||||||
|
return Ok ("Admin Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Manage Scop
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[HttpGet ("PassManageAccess")]
|
||||||
|
[Authorize (Policy = XPolicies.ManageAccess)]
|
||||||
|
public ActionResult<string> PassManageAccess () {
|
||||||
|
return Ok ("Manage Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Action which returns a List of Authenticated User Claims
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which represent current user's claims</returns>
|
||||||
|
[HttpGet ("HiClaims")]
|
||||||
|
[Authorize (Policy = XPolicies.User)]
|
||||||
|
public ActionResult<string> HiClaims () {
|
||||||
|
//
|
||||||
|
var result = new {
|
||||||
|
name = User?.Identity?.Name,
|
||||||
|
claims = User?.Claims.Select (c => new {
|
||||||
|
c.Type, c.Value
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[HttpGet ("HiUser")]
|
||||||
|
[Authorize (Policy = XPolicies.User)]
|
||||||
|
public ActionResult<string> HiUser () {
|
||||||
|
//
|
||||||
|
var result = $"Hi User: {User?.Identity?.Name} ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[HttpGet ("HiEnabledUser")]
|
||||||
|
[Authorize (Policy = XPolicies.EnabledUser)]
|
||||||
|
public ActionResult<string> HiEnabledUser () {
|
||||||
|
//
|
||||||
|
var result = $"Hi User: {User?.Identity?.Name} is Enabled ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[HttpGet ("HiAgent")]
|
||||||
|
[Authorize (Policy = XPolicies.Agent)]
|
||||||
|
public ActionResult<string> HiAgent () {
|
||||||
|
//
|
||||||
|
var result = $"Hi Agent: {User?.Identity?.Name} ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[HttpGet ("HiEnabledAgent")]
|
||||||
|
[Authorize (Policy = XPolicies.EnabledAgent)]
|
||||||
|
public ActionResult<string> HiEnabledAgent () {
|
||||||
|
//
|
||||||
|
var result = $"Hi Agent: {User?.Identity?.Name} is Enabled ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[HttpGet ("HiAdmin")]
|
||||||
|
[Authorize (Policy = XPolicies.Admin)]
|
||||||
|
public ActionResult<string> HiAdmin () {
|
||||||
|
//
|
||||||
|
var result = $"Hi Admin: {User?.Identity?.Name} ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[HttpGet ("HiEnabledAdmin")]
|
||||||
|
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
||||||
|
public ActionResult<string> HiEnabledAdmin () {
|
||||||
|
//
|
||||||
|
var result = $"Hi Admin: {User?.Identity?.Name} is Enabled ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok (result);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,313 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.AI;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using OpenAI.Realtime;
|
|
||||||
using xAiApi.AI.Interfaces;
|
|
||||||
using xAiApi.AI.Models.Dtos;
|
|
||||||
using xAiApi.Base;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xExceptions.Constants;
|
|
||||||
using xIdentityHelper;
|
|
||||||
using xIdentityService.Constants;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers.V1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Controller Which Provides Actions for
|
|
||||||
/// using Ai Service ...
|
|
||||||
/// </summary>
|
|
||||||
public class AIController : XIBaseV1Controller
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Ai Provider ...
|
|
||||||
/// </summary>
|
|
||||||
private readonly IXAiProvider aiService;
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Constructor ...
|
|
||||||
public AIController(
|
|
||||||
IXAiProvider aiService,
|
|
||||||
ILogger<XIBaseV1Controller> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.aiService = aiService;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// As a Message from Ai ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Ask")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public async Task<ActionResult<XAiMessageDto>> Ask(
|
|
||||||
[FromQuery] XAiAskRequestDto request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Model ...
|
|
||||||
var isValid =
|
|
||||||
ModelState.IsValid &&
|
|
||||||
!request.IsNull() &&
|
|
||||||
!request.Prompt.IsNullOrEmpty();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve User Info ...
|
|
||||||
var userInfo = await GetUserInfo();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Result ...
|
|
||||||
var result = await aiService
|
|
||||||
.Ask(
|
|
||||||
userInfo: userInfo,
|
|
||||||
prompt: request.Prompt,
|
|
||||||
projectId: request.ProjectId,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
conversationId: request.ConversationId
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result.ToDynamicObject());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// As a Message from Ai ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="prompt">specified prompt</param>
|
|
||||||
/// <param name="projectId">active Project Id</param>
|
|
||||||
/// <param name="conversationId">active Conversation Id</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns>Ai Model's answer <see cref="XAiMessageDto"/></returns>
|
|
||||||
[HttpGet("AskAI")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public async Task<ActionResult<XAiMessageDto>> AskAI(
|
|
||||||
[FromQuery] string prompt,
|
|
||||||
[FromQuery] string projectId = null,
|
|
||||||
[FromQuery] string conversationId = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var userInfo = await GetUserInfo();
|
|
||||||
var result = await aiService
|
|
||||||
.Ask(
|
|
||||||
prompt: prompt,
|
|
||||||
userInfo: userInfo,
|
|
||||||
projectId: projectId,
|
|
||||||
conversationId: conversationId,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result.ToDynamicObject());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Message from Ai using Streamin Pattern ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("AskStream")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public async Task AskStream(
|
|
||||||
[FromQuery] XAiAskRequestDto request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Model ...
|
|
||||||
var isValid =
|
|
||||||
ModelState.IsValid &&
|
|
||||||
!request.IsNull() &&
|
|
||||||
!request.Prompt.IsNullOrEmpty();
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Adding Content Type ...
|
|
||||||
Response.Headers
|
|
||||||
.Append("Content-Type", "text/event-stream");
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve User Info ...
|
|
||||||
var userInfo = await GetUserInfo();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Access Async Enumerable ...
|
|
||||||
var stream = aiService
|
|
||||||
.AskStream(
|
|
||||||
userInfo: userInfo,
|
|
||||||
prompt: request.Prompt,
|
|
||||||
projectId: request.ProjectId,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
conversationId: request.ConversationId
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Loop through Enumerable ...
|
|
||||||
await foreach (var message in stream)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Converts Model to Json String ...
|
|
||||||
var json = message.ToJSON();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generates Json byte[] ...
|
|
||||||
var bytes = json.ToBytes();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Write Bytes to Stream ...
|
|
||||||
await Response.Body.WriteAsync(
|
|
||||||
bytes,
|
|
||||||
0,
|
|
||||||
bytes.Length,
|
|
||||||
cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Flushing Stream ...
|
|
||||||
await Response.Body.FlushAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Closing Connection ...
|
|
||||||
await Response.Body.FlushAsync();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ask a Message from Ai using Streamin Pattern ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prompt"></param>
|
|
||||||
/// <param name="projectId"></param>
|
|
||||||
/// <param name="conversationId"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("AskAIStream")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public async Task AskAIStream(
|
|
||||||
[FromQuery] string prompt,
|
|
||||||
[FromQuery] string projectId = null,
|
|
||||||
[FromQuery] string conversationId = null,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Adding Content Type ...
|
|
||||||
Response.Headers
|
|
||||||
.Append("Content-Type", "text/event-stream");
|
|
||||||
|
|
||||||
//
|
|
||||||
var userInfo = await GetUserInfo();
|
|
||||||
var stream = aiService
|
|
||||||
.AskStream(
|
|
||||||
prompt: prompt,
|
|
||||||
userInfo: userInfo,
|
|
||||||
projectId: projectId,
|
|
||||||
conversationId: conversationId,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Loop through Enumerable ...
|
|
||||||
await foreach (var message in stream)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Converts Model to Json String ...
|
|
||||||
var json = message.ToJSON();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generates Json byte[] ...
|
|
||||||
var bytes = json.ToBytes();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Write Bytes to Stream ...
|
|
||||||
await Response.Body.WriteAsync(
|
|
||||||
bytes,
|
|
||||||
0,
|
|
||||||
bytes.Length,
|
|
||||||
cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Flushing Stream ...
|
|
||||||
await Response.Body.FlushAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Closing Connection ...
|
|
||||||
await Response.Body.FlushAsync();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiApi.Base;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using xPushService.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers.V1.Entities
|
|
||||||
{
|
|
||||||
public class AiConversationsController : XIBaseV1EntityHubController<XAiConversation, Guid>
|
|
||||||
{
|
|
||||||
public AiConversationsController(
|
|
||||||
ILogger<AiConversationsController> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
IXAiConversationRepository repository,
|
|
||||||
IHubContext<XBaseEntityHub<XAiConversation, Guid>> hub = null
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider,
|
|
||||||
repository,
|
|
||||||
hub
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiApi.Base;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using xPushService.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers.V1.Entities
|
|
||||||
{
|
|
||||||
public class AiMessagesController : XIBaseV1EntityHubController<XAiMessage, Guid>
|
|
||||||
{
|
|
||||||
public AiMessagesController(
|
|
||||||
ILogger<AiMessagesController> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
IXAiMessageRepository repository,
|
|
||||||
IHubContext<XBaseEntityHub<XAiMessage, Guid>> hub = null
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider,
|
|
||||||
repository,
|
|
||||||
hub
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiApi.Base;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using xPushService.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers.V1.Entities
|
|
||||||
{
|
|
||||||
public class AiProjectsController : XIBaseV1EntityHubController<XAiProject, Guid>
|
|
||||||
{
|
|
||||||
public AiProjectsController(
|
|
||||||
ILogger<AiProjectsController> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
IXAiProjectRepository repository,
|
|
||||||
IHubContext<XBaseEntityHub<XAiProject, Guid>> hub = null
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider,
|
|
||||||
repository,
|
|
||||||
hub
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,557 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using Microsoft.EntityFrameworkCore.Query;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.Base;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityHelper;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using xModels.Base;
|
|
||||||
using xModels.Dtos;
|
|
||||||
using xPushService.Base;
|
|
||||||
using xPushService.Constants;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers.V1.Entities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Simple XTest Entity Controller ...
|
|
||||||
/// </summary>
|
|
||||||
public class TestsController : XIBaseV1EntityHubController<XTest, int>
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region Constructor ...
|
|
||||||
public TestsController(
|
|
||||||
ILogger<TestsController> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
IXTestRepository repository,
|
|
||||||
IHubContext<XBaseEntityHub<XTest, int>> hub = null,
|
|
||||||
Func<IQueryable<XTest>, IOrderedQueryable<XTest>> defaultOrderBuilder = null,
|
|
||||||
Func<IQueryable<XTest>, IIncludableQueryable<XTest, object>> defaultIncludeBuilder = null
|
|
||||||
) : base(
|
|
||||||
hub: hub,
|
|
||||||
logger: logger,
|
|
||||||
repository: repository,
|
|
||||||
appConfiguration: appConfiguration,
|
|
||||||
identityProvider: identityProvider,
|
|
||||||
validationProvider: validationProvider,
|
|
||||||
defaultOrderBuilder: defaultOrderBuilder,
|
|
||||||
defaultIncludeBuilder: defaultIncludeBuilder
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
//
|
|
||||||
#region Add ...
|
|
||||||
/// <summary>
|
|
||||||
/// Add Specified Item ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Sample request:
|
|
||||||
///
|
|
||||||
/// {
|
|
||||||
/// "title": ""
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> Add(
|
|
||||||
[FromBody] XTest item,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.Add(
|
|
||||||
item: item,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Handle Sending Push Notification ...
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: entity.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.Add.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update Specified Item ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Sample request:
|
|
||||||
///
|
|
||||||
/// {
|
|
||||||
/// "title": ""
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("AddOrUpdate")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> AddOrUpdate(
|
|
||||||
[FromBody] XTest item,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.AddOrUpdate(
|
|
||||||
item: item,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Handle Sending Push Notification ...
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: entity.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.AddOrUpdate.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add Many Specified Items ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Sample request:
|
|
||||||
///
|
|
||||||
/// {
|
|
||||||
/// "items": [
|
|
||||||
/// {
|
|
||||||
/// "title": ""
|
|
||||||
/// }
|
|
||||||
/// ]
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("AddMany")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult> AddMany(
|
|
||||||
[FromBody] XBaseRangeRequest<XTest> request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await base
|
|
||||||
.AddMany(
|
|
||||||
request: request,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!(result as OkObjectResult).IsNull())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: request.Items.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.AddMany.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Retrieve ...
|
|
||||||
/// <summary>
|
|
||||||
/// Get Specified Item by Providing Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="useDefaultIncludes"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<XTest>> Get(
|
|
||||||
[FromRoute] int id,
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
||||||
[FromQuery] bool useDefaultIncludes = false,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await base
|
|
||||||
.Get(
|
|
||||||
id: id,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
||||||
useDefaultIncludes: useDefaultIncludes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get all Exists Items ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="useDefaultOrders"></param>
|
|
||||||
/// <param name="useDefaultIncludes"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<IEnumerable<XTest>>> GetAll(
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
||||||
[FromQuery] bool useDefaultOrders = false,
|
|
||||||
[FromQuery] bool useDefaultIncludes = false,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await base
|
|
||||||
.GetAll(
|
|
||||||
useDefaultOrders: useDefaultOrders,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
||||||
useDefaultIncludes: useDefaultIncludes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Find Item based on Provided Query ....
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="useDefaultIncludes"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("FindOne/{query}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<XTest>> FindOne(
|
|
||||||
[FromRoute] string query,
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
||||||
[FromQuery] bool useDefaultIncludes = false,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await base
|
|
||||||
.FindOne(
|
|
||||||
query: query,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
||||||
useDefaultIncludes: useDefaultIncludes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Find Items based on Provided Query ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="useDefaultOrders"></param>
|
|
||||||
/// <param name="useDefaultIncludes"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("FindMany/{query}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<IEnumerable<XTest>>> FindMany(
|
|
||||||
[FromRoute] string query,
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
||||||
[FromQuery] bool useDefaultOrders = false,
|
|
||||||
[FromQuery] bool useDefaultIncludes = false,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await base
|
|
||||||
.FindMany(
|
|
||||||
query: query,
|
|
||||||
useDefaultOrders: useDefaultOrders,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
||||||
useDefaultIncludes: useDefaultIncludes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve Items based on Query Mechanism ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="query"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="useDefaultOrders"></param>
|
|
||||||
/// <param name="useDefaultIncludes"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Query")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<XQueryResult<XTest>>> Query(
|
|
||||||
[FromQuery] XQuery query,
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
||||||
[FromQuery] bool useDefaultOrders = false,
|
|
||||||
[FromQuery] bool useDefaultIncludes = false,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await base
|
|
||||||
.Query(
|
|
||||||
query: query,
|
|
||||||
useDefaultOrders: useDefaultOrders,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
||||||
useDefaultIncludes: useDefaultIncludes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Update ...
|
|
||||||
/// <summary>
|
|
||||||
/// Update an Item ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Sample request:
|
|
||||||
///
|
|
||||||
/// {
|
|
||||||
/// "title": ""
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPut("{id}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> Update(
|
|
||||||
[FromRoute] int id,
|
|
||||||
[FromBody] XTest item,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.Update(
|
|
||||||
id: id,
|
|
||||||
item: item,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: entity.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.Update.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Update a Collection of Items ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Sample request:
|
|
||||||
///
|
|
||||||
/// {
|
|
||||||
/// "items": [
|
|
||||||
/// {
|
|
||||||
/// "id": 1,
|
|
||||||
/// "title": "Hi there ..."
|
|
||||||
/// }
|
|
||||||
/// ]
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("UpdateMany")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<bool>> UpdateMany(
|
|
||||||
[FromBody] XBaseRangeRequest<XTest> request,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await base
|
|
||||||
.UpdateMany(
|
|
||||||
request: request,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
var resultObject = (result.Result as OkObjectResult).Value;
|
|
||||||
if (!resultObject.IsNull() && (bool)resultObject)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: request.Items.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.UpdateMany.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Exists ...
|
|
||||||
/// <summary>
|
|
||||||
/// Check an Item Exists or not ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="ignoreSoftDeleteds"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("{id}/IsExists")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<bool>> IsExists(
|
|
||||||
[FromRoute] int id,
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return await base
|
|
||||||
.IsExists(
|
|
||||||
id: id,
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Remove ...
|
|
||||||
/// <summary>
|
|
||||||
/// Remove an Item ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="softDelete"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpDelete("{id}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> Remove(
|
|
||||||
[FromRoute] int id,
|
|
||||||
[FromQuery] bool softDelete = true,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.Remove(
|
|
||||||
id: id,
|
|
||||||
softDelete: softDelete,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: entity.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.Delete.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remove Many Items ...
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// Sample request:
|
|
||||||
///
|
|
||||||
/// {
|
|
||||||
/// "items": [
|
|
||||||
/// {
|
|
||||||
/// "id": 1,
|
|
||||||
/// "title": "Hi there ..."
|
|
||||||
/// }
|
|
||||||
/// ]
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <param name="softDelete"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("RemoveMany")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult> RemoveMany(
|
|
||||||
[FromBody] XBaseRangeRequest<XTest> request,
|
|
||||||
[FromQuery] bool softDelete = true,
|
|
||||||
CancellationToken cancellationToken = default
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await base
|
|
||||||
.RemoveMany(
|
|
||||||
request: request,
|
|
||||||
softDelete: softDelete,
|
|
||||||
cancellationToken: cancellationToken
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!(result as OkObjectResult).IsNull())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
payLoad: request.Items.ToJSON(),
|
|
||||||
cancellationToken: cancellationToken,
|
|
||||||
action: XBaseEntityHubAction.DeleteMany.GetStringValue()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.Base;
|
|
||||||
using xAiApi.Helpers;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityHelper;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Controllers.V1
|
|
||||||
{
|
|
||||||
public class OllamaController : XIBaseV1Controller
|
|
||||||
{
|
|
||||||
public OllamaController(
|
|
||||||
ILogger<XIBaseV1Controller> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve Ollama Version ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Version")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
||||||
public async Task<ActionResult<string>> GetVersion()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await XOllamaHelper.GetVersion();
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve a List of Available models ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("Models")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
||||||
public async Task<ActionResult<IEnumerable<string>>> GetModels()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await XOllamaHelper.GetModels();
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Find a model ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("FindModel")]
|
|
||||||
[Authorize(Policy = XPolicies.Admin)]
|
|
||||||
public async Task<ActionResult<IEnumerable<string>>> FindModel(
|
|
||||||
[FromQuery]
|
|
||||||
string model
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await XOllamaHelper.FindModel(model);
|
|
||||||
|
|
||||||
//
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = GetExceptionActionResult(ex);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Configurations
|
|
||||||
{
|
|
||||||
public class XAiApiDbSeederConfig : IXAiApiDbSeederConfig, IXDbSeederConfig
|
|
||||||
{
|
|
||||||
public bool UpdateExists { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace xAiApi.Data.Constants
|
|
||||||
{
|
|
||||||
public partial struct ConfigurationNodeNames
|
|
||||||
{
|
|
||||||
public const string DATA_SERVICE_DB_SEED_NODE = "DbSeeder";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Events;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Events
|
|
||||||
{
|
|
||||||
public class XTestEvents : XBaseRepositoryEvents<XTest>, IXTestEvents
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xAiApi.Data.Configurations;
|
|
||||||
using xAiApi.Data.Constants;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Extensions
|
|
||||||
{
|
|
||||||
public static class XAiApiDbSeederExtension
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Extract XDbSeeder Configurations From IConfiguration
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="configuration"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static XAiApiDbSeederConfig GetXDbSeederConfiguration(
|
|
||||||
this IConfiguration configuration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var xDbSeederConfigSection = configuration.GetSection(ConfigurationNodeNames.DATA_SERVICE_DB_SEED_NODE);
|
|
||||||
return xDbSeederConfigSection.Get<XAiApiDbSeederConfig>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register XDbSeeder Configurations on DI
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <param name="configuration"></param>
|
|
||||||
public static void AddXDbSeederConfiguration(
|
|
||||||
this IServiceCollection services,
|
|
||||||
IConfiguration configuration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var dbSeederConfig = configuration.GetXDbSeederConfiguration();
|
|
||||||
if (dbSeederConfig.IsNull())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
services.AddSingleton<IXAiApiDbSeederConfig>(dbSeederConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Register XDbSeeder Configurations on DI
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="services"></param>
|
|
||||||
/// <param name="configuration"></param>
|
|
||||||
public static void AddXDbSeederConfiguration(
|
|
||||||
this IServiceCollection services,
|
|
||||||
XAiApiDbSeederConfig configuration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (configuration.IsNull())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
services.AddSingleton<IXAiApiDbSeederConfig>(configuration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.GraphQL
|
|
||||||
{
|
|
||||||
public class XTestGraphQLTypeHelper : XBaseGraphQLTypeHelper<XTest, int>, IXTestGraphQLTypeHelper
|
|
||||||
{
|
|
||||||
public XTestGraphQLTypeHelper(
|
|
||||||
XDataServiceConfiguration configuration
|
|
||||||
) : base(configuration)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override string GetInQueryCollectionName()
|
|
||||||
{
|
|
||||||
return "tests";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string GetInQuerySingleName()
|
|
||||||
{
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using GraphQL.Types;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.GraphQL
|
|
||||||
{
|
|
||||||
public class XTestGraphQuery : XBaseGraphQLQuery<XTest, int, XTestGraphType, IntGraphType>
|
|
||||||
{
|
|
||||||
public XTestGraphQuery(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXTestRepository repository,
|
|
||||||
IXTestGraphQLTypeHelper helper
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
repository,
|
|
||||||
helper
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Types;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.GraphQL
|
|
||||||
{
|
|
||||||
public class XTestGraphSchema : Schema
|
|
||||||
{
|
|
||||||
public XTestGraphSchema(IServiceProvider services) : base(services)
|
|
||||||
{
|
|
||||||
Query = (XTestGraphQuery)services.GetService(typeof(XTestGraphQuery));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.GraphQL
|
|
||||||
{
|
|
||||||
public class XTestGraphType : XBaseGraphObjectType<XTest, int>
|
|
||||||
{
|
|
||||||
public XTestGraphType() : base()
|
|
||||||
{
|
|
||||||
Field(x => x.Title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
using System;
|
|
||||||
using GraphQL.Server;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xAiApi.AI.DataHelper.GraphQL;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiApi.Data.GraphQL;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.GraphQL;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Helpers
|
|
||||||
{
|
|
||||||
public class XAiApiDataHelperGraphQLHelper : IXGraphQLHelper
|
|
||||||
{
|
|
||||||
public void AddXGraphEnumTypes(IServiceCollection services) { }
|
|
||||||
|
|
||||||
public void AddXGraphInputTypes(IServiceCollection services) { }
|
|
||||||
|
|
||||||
public void AddXGraphMutations(IServiceCollection services) { }
|
|
||||||
|
|
||||||
public void AddXGraphObjectTypes(IServiceCollection services)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// XTest ...
|
|
||||||
services.AddSingleton<XTestGraphType>();
|
|
||||||
services.AddSingleton<XBaseGraphQLEventType<XTest, int, XTestGraphType>>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiMessage ...
|
|
||||||
services.AddSingleton<XAiMessageGraphType>();
|
|
||||||
services.AddSingleton<XBaseGraphQLEventType<XAiMessage, Guid, XAiMessageGraphType>>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiProject ...
|
|
||||||
services.AddSingleton<XAiProjectGraphType>();
|
|
||||||
services.AddSingleton<XBaseGraphQLEventType<XAiProject, Guid, XAiProjectGraphType>>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiConversation ...
|
|
||||||
services.AddSingleton<XAiConversationGraphType>();
|
|
||||||
services.AddSingleton<XBaseGraphQLEventType<XAiConversation, Guid, XAiConversationGraphType>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddXGraphQueries(IServiceCollection services)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// XTest ...
|
|
||||||
services.AddSingleton<IXTestGraphQLTypeHelper, XTestGraphQLTypeHelper>();
|
|
||||||
services.AddScoped<XTestGraphQuery>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiMessage ...
|
|
||||||
services.AddSingleton<IXAiMessageGraphQLTypeHelper, XAiMessageGraphQLTypeHelper>();
|
|
||||||
services.AddScoped<XAiMessageGraphQuery>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiProject ...
|
|
||||||
services.AddSingleton<IXAiProjectGraphQLTypeHelper, XAiProjectGraphQLTypeHelper>();
|
|
||||||
services.AddScoped<XAiProjectGraphQuery>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiConversation ...
|
|
||||||
services.AddSingleton<IXAiConversationGraphQLTypeHelper, XAiConversationGraphQLTypeHelper>();
|
|
||||||
services.AddScoped<XAiConversationGraphQuery>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddXGraphSchemas(IServiceCollection services)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
services.AddScoped<XTestGraphSchema>();
|
|
||||||
services.AddScoped<XAiMessageGraphSchema>();
|
|
||||||
services.AddScoped<XAiProjectGraphSchema>();
|
|
||||||
services.AddScoped<XAiConversationGraphSchema>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddXGraphSubscriptions(IServiceCollection services) { }
|
|
||||||
|
|
||||||
public IGraphQLBuilder AddXGraphTypes(IGraphQLBuilder builder)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
builder.AddGraphTypes(typeof(XTestGraphSchema));
|
|
||||||
|
|
||||||
//
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UseXGraph(IApplicationBuilder app)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
using (var scope = app.ApplicationServices.CreateScope())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// XDataServiceConfiguration ...
|
|
||||||
var dataServiceConfiguration = scope.ServiceProvider.GetService<XDataServiceConfiguration>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XTest ...
|
|
||||||
var testHelper = scope.ServiceProvider.GetService<IXTestGraphQLTypeHelper>();
|
|
||||||
app.UseGraphQL<XTestGraphSchema>(testHelper.GetGraphQLPath());
|
|
||||||
app.UseGraphQLWebSockets<XTestGraphSchema>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiMessage ...
|
|
||||||
var aiMessageHelper = scope.ServiceProvider.GetService<IXAiMessageGraphQLTypeHelper>();
|
|
||||||
app.UseGraphQL<XAiMessageGraphSchema>(aiMessageHelper.GetGraphQLPath());
|
|
||||||
app.UseGraphQLWebSockets<XAiMessageGraphSchema>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiProject ...
|
|
||||||
var aiProjectHelper = scope.ServiceProvider.GetService<IXAiProjectGraphQLTypeHelper>();
|
|
||||||
app.UseGraphQL<XAiProjectGraphSchema>(aiProjectHelper.GetGraphQLPath());
|
|
||||||
app.UseGraphQLWebSockets<XAiProjectGraphSchema>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiConversation ...
|
|
||||||
var aiConversationHelper = scope.ServiceProvider.GetService<IXAiConversationGraphQLTypeHelper>();
|
|
||||||
app.UseGraphQL<XAiConversationGraphSchema>(aiConversationHelper.GetGraphQLPath());
|
|
||||||
app.UseGraphQLWebSockets<XAiConversationGraphSchema>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MongoDB.Bson.Serialization.Conventions;
|
|
||||||
using xAiApi.AI.DataHelper.Events;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiApi.Data.Events;
|
|
||||||
using xAiApi.Data.Extensions;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xAiApi.Data.Repositories.Ef;
|
|
||||||
using xAiApi.Data.Repositories.Mongo;
|
|
||||||
using xAiApi.Data.Seeder;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Constants;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xDataService.Providers;
|
|
||||||
using xExceptions.Constants;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Helpers
|
|
||||||
{
|
|
||||||
public class XAiApiDataProviderHelper : IXDataServiceHelper
|
|
||||||
{
|
|
||||||
//
|
|
||||||
private readonly ILogger<XAiApiDataProviderHelper> logger;
|
|
||||||
|
|
||||||
//
|
|
||||||
public XAiApiDataProviderHelper(ILogger<XAiApiDataProviderHelper> logger)
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Actions ...
|
|
||||||
public void AddDbContext(
|
|
||||||
IServiceCollection services,
|
|
||||||
string connectionString,
|
|
||||||
XDbProviders dbProvider,
|
|
||||||
ServiceLifetime lifetime,
|
|
||||||
Action<dynamic> optionsBuilder = null
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
logger.LogInformation("Start AddDbContext ...");
|
|
||||||
|
|
||||||
//
|
|
||||||
switch (dbProvider)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case XDbProviders.MySQL:
|
|
||||||
//
|
|
||||||
services.AddDbContext<XAiApiDbContext>(cfg =>
|
|
||||||
{
|
|
||||||
cfg.UseMySQL(connectionString, optionsBuilder);
|
|
||||||
}, lifetime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XDbProviders.SQLite:
|
|
||||||
//
|
|
||||||
services.AddDbContext<XAiApiDbContext>(cfg =>
|
|
||||||
{
|
|
||||||
cfg.UseSqlite(connectionString, optionsBuilder);
|
|
||||||
}, lifetime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XDbProviders.SQLServer:
|
|
||||||
//
|
|
||||||
services.AddDbContext<XAiApiDbContext>(cfg =>
|
|
||||||
{
|
|
||||||
cfg.UseSqlServer(connectionString, optionsBuilder);
|
|
||||||
}, lifetime);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XDbProviders.MongoDB:
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
default:
|
|
||||||
Console.WriteLine("Unsuported Data Provider Type ...");
|
|
||||||
XException.NotAllowed.Throw();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
logger.LogInformation("End AddDbContext ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddRepositories(
|
|
||||||
IServiceCollection services,
|
|
||||||
ServiceLifetime lifetime
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
logger.LogInformation("Start AddRepositories ...");
|
|
||||||
|
|
||||||
//
|
|
||||||
var dataServiceConfiguration = services.GetRegisteredService<XDataServiceConfiguration>();
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Events ...
|
|
||||||
//
|
|
||||||
// XTest ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXTestEvents), typeof(XTestEvents), ServiceLifetime.Singleton));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiProject ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiProjectEvents), typeof(XAiProjectEvents), ServiceLifetime.Singleton));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiMessage ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiMessageEvents), typeof(XAiMessageEvents), ServiceLifetime.Singleton));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiConversation ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiConversationEvents), typeof(XAiConversationEvents), ServiceLifetime.Singleton));
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Repositories ...
|
|
||||||
//
|
|
||||||
// Adding DbContext if EFCore ...
|
|
||||||
switch (dataServiceConfiguration.Provider)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case XDbProviders.MySQL:
|
|
||||||
case XDbProviders.SQLite:
|
|
||||||
case XDbProviders.SQLServer:
|
|
||||||
//
|
|
||||||
// XTest ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXTestRepository), typeof(XTestEfRepository<XAiApiDbContext>), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiProject ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiProjectRepository), typeof(XAiProjectEfRepository<XAiApiDbContext>), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiMessage ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiMessageRepository), typeof(XAiMessageEfRepository<XAiApiDbContext>), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiConversation ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiConversationRepository), typeof(XAiConversationEfRepository<XAiApiDbContext>), lifetime));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XDbProviders.MongoDB:
|
|
||||||
//
|
|
||||||
// XTest ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXTestRepository), typeof(XTestMongoRepository), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiProject ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiProjectRepository), typeof(XAiProjectMongoRepository), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiMessage ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiMessageRepository), typeof(XAiMessageMongoRepository), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
// XAiConversation ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXAiConversationRepository), typeof(XAiConversationMongoRepository), lifetime));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
default:
|
|
||||||
Console.WriteLine("Unsuported Data Provider Type ...");
|
|
||||||
XException.NotAllowed.Throw();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
logger.LogInformation("End AddRepositories ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddKeyGenerators(IServiceCollection services)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
services.AddSingleton<IXKeyGenerator<XTest, int>, XIntKeyGenerator<XTest>>();
|
|
||||||
services.AddSingleton<IXKeyGenerator<XAiProject, Guid>, XGuidKeyGenerator<XAiProject>>();
|
|
||||||
services.AddSingleton<IXKeyGenerator<XAiMessage, Guid>, XGuidKeyGenerator<XAiMessage>>();
|
|
||||||
services.AddSingleton<IXKeyGenerator<XAiConversation, Guid>, XGuidKeyGenerator<XAiConversation>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddDbSeederConfiguration(
|
|
||||||
IServiceCollection services,
|
|
||||||
IConfiguration configuration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
logger.LogInformation("Start AddDbSeederConfiguration ...");
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Config from appSettings ...
|
|
||||||
var dbSeederConfig = configuration.GetXDbSeederConfiguration();
|
|
||||||
if (!dbSeederConfig.IsNull())
|
|
||||||
{
|
|
||||||
services.AddXDbSeederConfiguration(dbSeederConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
logger.LogInformation("End AddDbSeederConfiguration ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddDbSeeder<TDbSeeder>(
|
|
||||||
IServiceCollection services,
|
|
||||||
IConfiguration config,
|
|
||||||
ServiceLifetime lifetime
|
|
||||||
) where TDbSeeder : IXDbSeeder
|
|
||||||
{
|
|
||||||
//
|
|
||||||
logger.LogInformation("Start AddDbSeeder ...");
|
|
||||||
|
|
||||||
//
|
|
||||||
// Adding DbSeeder ...
|
|
||||||
services.Add(new ServiceDescriptor(typeof(IXDbSeeder), typeof(XAiApiDbSeeder), lifetime));
|
|
||||||
|
|
||||||
//
|
|
||||||
logger.LogInformation("End AddDbSeeder ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConventionPack MongoConventionPacks()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterMongoExtras() { }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Private ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXAiApiDbSeederConfig : IXDbSeederConfig
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXTestEvents : IXBaseRepositoryEvents<XTest>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXTestGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XTest, int>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Interfaces
|
|
||||||
{
|
|
||||||
public interface IXTestRepository : IXBaseRepository<XTest, int>
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using xModels.Base;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Models.Entities
|
|
||||||
{
|
|
||||||
public class XTest : XBaseIntIDEntity
|
|
||||||
{
|
|
||||||
public string Title { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace xAiApi.Data.Models
|
|
||||||
{
|
|
||||||
public class XTestDescriptor
|
|
||||||
{
|
|
||||||
public string Title { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Db;
|
|
||||||
using xDataService.EFRepositories;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Ef
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Repository Pattern Implementation for
|
|
||||||
/// manipulating AiConversations ...
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TDbContext"></typeparam>
|
|
||||||
public class XAiConversationEfRepository<TDbContext> : XBaseEFRepository<XAiConversation, Guid, XAiApiDbContext>, IXAiConversationRepository
|
|
||||||
where TDbContext : XDbContext
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XAiConversationEfRepository(
|
|
||||||
IXUnitOfWorks<XAiApiDbContext> unitOfWorks,
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXKeyGenerator<XAiConversation, Guid> keyGenerator = null,
|
|
||||||
IXAiConversationEvents baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
unitOfWorks,
|
|
||||||
configuration,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IQueryable<XAiConversation> GetFullDbSet()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return dbSet
|
|
||||||
.Include(x => x.Project)
|
|
||||||
.Include(x => x.Messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Db;
|
|
||||||
using xDataService.EFRepositories;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Ef
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Repository Pattern Implementation for
|
|
||||||
/// manipulating AiMessage ...
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TDbContext"></typeparam>
|
|
||||||
public class XAiMessageEfRepository<TDbContext> : XBaseEFRepository<XAiMessage, Guid, XAiApiDbContext>, IXAiMessageRepository
|
|
||||||
where TDbContext : XDbContext
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XAiMessageEfRepository(
|
|
||||||
IXUnitOfWorks<XAiApiDbContext> unitOfWorks,
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXKeyGenerator<XAiMessage, Guid> keyGenerator = null,
|
|
||||||
IXAiMessageEvents baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
unitOfWorks,
|
|
||||||
configuration,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IQueryable<XAiMessage> GetFullDbSet()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return dbSet
|
|
||||||
.Include(x => x.Conversation);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Db;
|
|
||||||
using xDataService.EFRepositories;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Ef
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Repository Pattern Implementation for
|
|
||||||
/// manipulating AiProjects ...
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TDbContext"></typeparam>
|
|
||||||
public class XAiProjectEfRepository<TDbContext> : XBaseEFRepository<XAiProject, Guid, XAiApiDbContext>, IXAiProjectRepository
|
|
||||||
where TDbContext : XDbContext
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XAiProjectEfRepository(
|
|
||||||
IXUnitOfWorks<XAiApiDbContext> unitOfWorks,
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXKeyGenerator<XAiProject, Guid> keyGenerator = null,
|
|
||||||
IXAiProjectEvents baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
unitOfWorks,
|
|
||||||
configuration,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IQueryable<XAiProject> GetFullDbSet()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return dbSet
|
|
||||||
.Include(x => x.Conversations)
|
|
||||||
.ThenInclude(x => x.Messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Db;
|
|
||||||
using xDataService.EFRepositories;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Ef
|
|
||||||
{
|
|
||||||
public class XTestEfRepository<TDbContext> : XBaseEFRepository<XTest, int, XAiApiDbContext>, IXTestRepository
|
|
||||||
where TDbContext : XDbContext
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XTestEfRepository(
|
|
||||||
IXUnitOfWorks<XAiApiDbContext> unitOfWorks,
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
IXKeyGenerator<XTest, int> keyGenerator = null,
|
|
||||||
IXBaseRepositoryEvents<XTest> baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
unitOfWorks,
|
|
||||||
configuration,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IQueryable<XTest> GetFullDbSet()
|
|
||||||
{
|
|
||||||
return dbSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDB.Driver.Linq;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xDataService.MongoRepositories;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Mongo
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Repository Pattern Implementation for
|
|
||||||
/// manipulating AiConversations ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiConversationMongoRepository : XBaseMongoRepository<XAiConversation, Guid>, IXAiConversationRepository
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XAiConversationMongoRepository(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
string collectionName = null,
|
|
||||||
IXKeyGenerator<XAiConversation, Guid> keyGenerator = null,
|
|
||||||
IXAiConversationEvents baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
collectionName,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IMongoQueryable<XAiConversation> GetFullDbSet()
|
|
||||||
{
|
|
||||||
return collection
|
|
||||||
.AsQueryable();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDB.Driver.Linq;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xDataService.MongoRepositories;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Mongo
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Repository Pattern Implementation for
|
|
||||||
/// manipulating AiMessage ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiMessageMongoRepository : XBaseMongoRepository<XAiMessage, Guid>, IXAiMessageRepository
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XAiMessageMongoRepository(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
string collectionName = null,
|
|
||||||
IXKeyGenerator<XAiMessage, Guid> keyGenerator = null,
|
|
||||||
IXAiMessageEvents baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
collectionName,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IMongoQueryable<XAiMessage> GetFullDbSet()
|
|
||||||
{
|
|
||||||
return collection
|
|
||||||
.AsQueryable();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDB.Driver.Linq;
|
|
||||||
using xAiApi.AI.Interfaces.Entities;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xDataService.MongoRepositories;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Mongo
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// a Repository Pattern Implementation for
|
|
||||||
/// manipulating AiProjects ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiProjectMongoRepository : XBaseMongoRepository<XAiProject, Guid>, IXAiProjectRepository
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XAiProjectMongoRepository(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
string collectionName = null,
|
|
||||||
IXKeyGenerator<XAiProject, Guid> keyGenerator = null,
|
|
||||||
IXAiProjectEvents baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
collectionName,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IMongoQueryable<XAiProject> GetFullDbSet()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return collection
|
|
||||||
.AsQueryable();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using MongoDB.Driver;
|
|
||||||
using MongoDB.Driver.Linq;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xDataService.MongoRepositories;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Repositories.Mongo
|
|
||||||
{
|
|
||||||
public class XTestMongoRepository : XBaseMongoRepository<XTest, int>, IXTestRepository
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public XTestMongoRepository(
|
|
||||||
XDataServiceConfiguration configuration,
|
|
||||||
string collectionName = null,
|
|
||||||
IXKeyGenerator<XTest, int> keyGenerator = null,
|
|
||||||
IXBaseRepositoryEvents<XTest> baseRepositoryEvents = null
|
|
||||||
) : base(
|
|
||||||
configuration,
|
|
||||||
collectionName,
|
|
||||||
keyGenerator,
|
|
||||||
baseRepositoryEvents
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public override IMongoQueryable<XTest> GetFullDbSet()
|
|
||||||
{
|
|
||||||
return collection
|
|
||||||
.AsQueryable();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Special ...
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xAiApi.Data.Interfaces;
|
|
||||||
using xAiApi.Data.Models;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Data.Seeder
|
|
||||||
{
|
|
||||||
public class XAiApiDbSeeder : IXDbSeeder
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public IXDbSeederConfig Config { get; }
|
|
||||||
public readonly IXAiApiDbSeederConfig config;
|
|
||||||
private readonly ILogger<XAiApiDbSeeder> logger;
|
|
||||||
private readonly IXTestRepository testsRepository;
|
|
||||||
public XDataServiceConfiguration DataServiceConfiguration { get; }
|
|
||||||
|
|
||||||
//
|
|
||||||
public XAiApiDbSeeder(
|
|
||||||
ILogger<XAiApiDbSeeder> logger,
|
|
||||||
IXTestRepository testsRepository,
|
|
||||||
IXAiApiDbSeederConfig config = null,
|
|
||||||
XDataServiceConfiguration dataServiceConfiguration = null
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Config = config;
|
|
||||||
this.config = config;
|
|
||||||
this.logger = logger;
|
|
||||||
this.testsRepository = testsRepository;
|
|
||||||
DataServiceConfiguration = dataServiceConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Seed()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// TODO: Do any additional Seeding ...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Check Configuration Exists ...
|
|
||||||
if (config.IsNull())
|
|
||||||
{
|
|
||||||
logger.LogInformation($"there is no Configured Objects to Seed ...");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError($"Failed Seeding: {ex.Message} ...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Private ...
|
|
||||||
private async Task SeedTest(XTestDescriptor dTests)
|
|
||||||
{ }
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using xAiApi.AI.Models.Entities;
|
|
||||||
using xAiApi.Data.Models.Entities;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Db;
|
|
||||||
|
|
||||||
namespace xAiApi.Data
|
|
||||||
{
|
|
||||||
public partial class XAiApiDbContext : XDbContext
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region DbSets ...
|
|
||||||
public DbSet<XTest> Tests { get; set; }
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ai Entities ...
|
|
||||||
|
|
||||||
public DbSet<XAiMessage> AiMessages { get; set; }
|
|
||||||
public DbSet<XAiProject> AiProjects { get; set; }
|
|
||||||
public DbSet<XAiConversation> AiConversations { get; set; }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Navigation Property Entities ...
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public XAiApiDbContext(
|
|
||||||
DbContextOptions options,
|
|
||||||
XDataServiceConfiguration config
|
|
||||||
) : base(options, config) { }
|
|
||||||
|
|
||||||
public override void OnXConfiguring(DbContextOptionsBuilder optionsBuilder) { }
|
|
||||||
|
|
||||||
public override void OnXModelCreating(ModelBuilder modelBuilder) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xCommons.Authorization;
|
using xCommons.Authorization;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xIdentityHelper;
|
using xIdentityHelper;
|
||||||
|
|
||||||
namespace xAiApi.Extensions
|
namespace xAiApi.Extensions
|
||||||
{
|
{
|
||||||
public static class XStartupExtensions
|
public static class XProgramExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register Authorization Policies
|
/// Register Authorization Policies
|
||||||
@@ -75,7 +72,9 @@ namespace xAiApi.Extensions
|
|||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
#pragma warning disable ASPDEPR005 // Type or member is obsolete
|
||||||
forwardOptions.KnownNetworks.Clear();
|
forwardOptions.KnownNetworks.Clear();
|
||||||
|
#pragma warning restore ASPDEPR005 // Type or member is obsolete
|
||||||
forwardOptions.KnownProxies.Clear();
|
forwardOptions.KnownProxies.Clear();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xCommons.Helpers;
|
|
||||||
|
|
||||||
namespace xAiApi.Helpers
|
|
||||||
{
|
|
||||||
public class XOllamaHelper
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Get Version ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static async Task<string> GetVersion()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var cmd = "ollama";
|
|
||||||
var args = "--version";
|
|
||||||
var cmdResult = await XOsHelper.Execute(cmd, args);
|
|
||||||
|
|
||||||
//
|
|
||||||
var result =
|
|
||||||
cmdResult.Error.IsNullOrEmpty()
|
|
||||||
? cmdResult.Result
|
|
||||||
: cmdResult.Error;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = result.Replace("\n", "");
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get Exists Models ...
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static async Task<IEnumerable<string>> GetModels()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var cmd = "ollama";
|
|
||||||
var args = "list";
|
|
||||||
var cmdResult = await XOsHelper.Execute(cmd, args);
|
|
||||||
|
|
||||||
//
|
|
||||||
var cmdResultText =
|
|
||||||
cmdResult.Error.IsNullOrEmpty()
|
|
||||||
? cmdResult.Result
|
|
||||||
: cmdResult.Error;
|
|
||||||
|
|
||||||
//
|
|
||||||
var cmdResultList = cmdResultText
|
|
||||||
.Split("\n")
|
|
||||||
.ToList();
|
|
||||||
if (cmdResultList.Count > 0)
|
|
||||||
{
|
|
||||||
cmdResultList.RemoveAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var result = new List<string>();
|
|
||||||
if (cmdResultList.Count > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
cmdResultList
|
|
||||||
.ForEach(i =>
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (!i.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var d = i.Split(" ");
|
|
||||||
if (d.Length > 0)
|
|
||||||
{
|
|
||||||
result.Add(d[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check Specified Model Exists ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static async Task<bool> HasModel(string model)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = !model.IsNullOrEmpty();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var models = await GetModels();
|
|
||||||
result = models.HasChild();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = models
|
|
||||||
.Any(n => n == model || n.ToNormalString().Contains(model.ToNormalString()));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Search Available Models ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static async Task<IEnumerable<string>> FindModel(string model)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = new List<string>();
|
|
||||||
|
|
||||||
//
|
|
||||||
if (model.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var models = await GetModels();
|
|
||||||
if (!models.HasChild())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = models
|
|
||||||
.Where(n => n == model || n.ToNormalString().Contains(model.ToNormalString()))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+128
-16
@@ -1,20 +1,132 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using System.Reflection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||||
|
using xAiApi.Extensions;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xHttpService.DI;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using xIdentityService.DI;
|
||||||
|
|
||||||
namespace xAiApi
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
{
|
|
||||||
public class Program
|
//
|
||||||
|
#region Register services ...
|
||||||
|
//
|
||||||
|
// Register Validation Provider and all XCommons Module Services ...
|
||||||
|
builder.Services.AddXCommons();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register App Configuration ...
|
||||||
|
builder.Services.AddXAppConfiguration(builder.Configuration);
|
||||||
|
var appConfiguration = builder.Services.GetRegisteredService<XAppConfiguration>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Allowed Origins ...
|
||||||
|
builder.Services.AddXCors(appConfiguration.AllowedOrigins);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Swagger ...
|
||||||
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||||
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||||
|
builder.Services.AddXSwagger(builder.Configuration, xmlFilePath: xmlPath);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register HttpService ...
|
||||||
|
builder.Services.AddXHttpService(builder.Configuration);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Api V1 Versioning ...
|
||||||
|
builder.Services.AddXApiV1Versioning();
|
||||||
|
|
||||||
|
//
|
||||||
|
// OAuthIntrospectin Http Client Handler ...
|
||||||
|
// this is for handling SSLErrors ...
|
||||||
|
builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
|
||||||
|
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
return new HttpClientHandler
|
||||||
{
|
{
|
||||||
CreateHostBuilder(args).Build().Run();
|
ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
|
||||||
}
|
};
|
||||||
|
});
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
//
|
||||||
Host.CreateDefaultBuilder(args)
|
// Register Authorizations ...
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
builder.Services.AddXAuthorization();
|
||||||
{
|
|
||||||
webBuilder.UseStartup<Startup>();
|
//
|
||||||
});
|
// Mapping Controllers ...
|
||||||
}
|
builder.Services.AddControllers()
|
||||||
}
|
.AddJsonOptions(x =>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Optional but recommended for .NET 8+:
|
||||||
|
// Allows reading properties case-insensitively (e.g., "myProp" matches "MyProp") ...
|
||||||
|
x.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
// This tells STJ to ignore circular references instead of throwing an exception ...
|
||||||
|
x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Camel Case Naming Policy ...
|
||||||
|
x.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register XIdentity Service ...
|
||||||
|
builder.Services.AddXIdentityService(
|
||||||
|
configuration: builder.Configuration,
|
||||||
|
lifeTime: ServiceLifetime.Scoped
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
// Creating Application ...
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Using Middlewares ...
|
||||||
|
//
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Swagger Middleware ...
|
||||||
|
app.UseXSwagger();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Force Https Redirection ...
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Using Cors ...
|
||||||
|
app.UseXCors();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Using Routing ...
|
||||||
|
app.UseRouting();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use xIdentityService ...
|
||||||
|
app.UseXIdentityService();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Authorization ...
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Using Endpoints ...
|
||||||
|
app.UseEndpoints(endpoints =>
|
||||||
|
{
|
||||||
|
_ = endpoints.MapControllers();
|
||||||
|
});
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
// Runing Application ...
|
||||||
|
app.Run();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5129",
|
"applicationUrl": "http://localhost:5012",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
# xSaherElm.xAiApi
|
|
||||||
|
|
||||||
a WebAPI Project which contains all Business Logic of xSaherElm Project's AI.
|
|
||||||
|
|
||||||
## Maintainer
|
|
||||||
|
|
||||||
Hadi Khazaee asl
|
|
||||||
|
|
||||||
[https://www.saherelm.ir](https://www.saherelm.ir)
|
|
||||||
|
|
||||||
[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)
|
|
||||||
-283
@@ -1,283 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Reflection;
|
|
||||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xHttpService.DI;
|
|
||||||
using xIdentityService.DI;
|
|
||||||
using xPushService.DI;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using xDataService.Configuration;
|
|
||||||
using xDataService.Constants;
|
|
||||||
using xDataService.DI;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xPushService.Helpers;
|
|
||||||
using xAiApi.Extensions;
|
|
||||||
using xAiApi.Data.Helpers;
|
|
||||||
using xAiApi.Data;
|
|
||||||
using xAiApi.Data.Seeder;
|
|
||||||
using xAiApi.AI.DI;
|
|
||||||
using xAiApi.AI.Extensions;
|
|
||||||
// using xApi.Extensions;
|
|
||||||
// using xDataHelper;
|
|
||||||
// using xDataHelper.DbSeeder;
|
|
||||||
// using xDataHelper.Helpers;
|
|
||||||
// using xFileService.Hubs;
|
|
||||||
// using xPushHelper.DI;
|
|
||||||
// using xServices.DI;
|
|
||||||
// using xServices.TermsConditions.Push;
|
|
||||||
// using xStringService.Hubs;
|
|
||||||
// using xTagService.Hubs;
|
|
||||||
|
|
||||||
namespace xAiApi
|
|
||||||
{
|
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
public IConfiguration Configuration { get; }
|
|
||||||
|
|
||||||
public Startup(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
Configuration = configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Register Validation Provider and all XCommons Module Services ...
|
|
||||||
services.AddXCommons();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register App Configuration ...
|
|
||||||
services.AddXAppConfiguration(Configuration);
|
|
||||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Allowed Origins ...
|
|
||||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Swagger ...
|
|
||||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
||||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
||||||
services.AddXSwagger(Configuration, xmlFilePath: xmlPath);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register HttpService ...
|
|
||||||
services.AddXHttpService(Configuration);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Api Versioning ...
|
|
||||||
services.AddApiVersioning(opt =>
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Set Default Api Version ...
|
|
||||||
opt.DefaultApiVersion = new ApiVersion(1, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Routing to Default API Version, if Version unspecified ...
|
|
||||||
opt.AssumeDefaultVersionWhenUnspecified = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Report All Available Api Versions on Response ...
|
|
||||||
opt.ReportApiVersions = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
var lifeTime = ServiceLifetime.Scoped;
|
|
||||||
|
|
||||||
//
|
|
||||||
// OAuthIntrospectin Http Client Handler ...
|
|
||||||
// this is for handling SSLErrors ...
|
|
||||||
services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
|
|
||||||
.ConfigurePrimaryHttpMessageHandler(() =>
|
|
||||||
{
|
|
||||||
return new HttpClientHandler
|
|
||||||
{
|
|
||||||
ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Authorizations ...
|
|
||||||
services.AddXAuthorization();
|
|
||||||
|
|
||||||
//
|
|
||||||
services.AddControllers()
|
|
||||||
.AddNewtonsoftJson(x =>
|
|
||||||
{
|
|
||||||
x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
|
||||||
x.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register XPushService ...
|
|
||||||
services.AddXPushService(Configuration);
|
|
||||||
// services.AddXPushHubProvider(lifeTime);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register XIdentityService ...
|
|
||||||
services.AddXIdentityService(Configuration, lifeTime);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register DataService here ...
|
|
||||||
#region Register xDataService ...
|
|
||||||
//
|
|
||||||
// Register IXDataServiceHelper ...
|
|
||||||
services.AddSingleton<IXDataServiceHelper, XAiApiDataProviderHelper>();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Prepare Db Options Builder based on Provider ...
|
|
||||||
var providerType = Configuration.GetXDbProviderType();
|
|
||||||
switch (providerType)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case XDbProviders.MySQL:
|
|
||||||
case XDbProviders.SQLite:
|
|
||||||
case XDbProviders.SQLServer:
|
|
||||||
Action<dynamic> optionsBuilder = optionsBuilder = b =>
|
|
||||||
{
|
|
||||||
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register xDataService on DI ...
|
|
||||||
services.AddXDataService<XAiApiDbContext, XAiApiDbSeeder>(
|
|
||||||
Configuration,
|
|
||||||
lifeTime,
|
|
||||||
XDbProviderConfigurations.DEFAULT_CONNECTION_NAME,
|
|
||||||
optionsBuilder
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XDbProviders.MongoDB:
|
|
||||||
//
|
|
||||||
// Register xDataService on DI ...
|
|
||||||
services.AddXDataService<XAiApiDbSeeder>(
|
|
||||||
Configuration,
|
|
||||||
lifeTime,
|
|
||||||
XDbProviderConfigurations.DEFAULT_CONNECTION_NAME
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register GraphQL here ...
|
|
||||||
#region Register xGraphQL ...
|
|
||||||
//
|
|
||||||
services.Configure<IISServerOptions>(options =>
|
|
||||||
{
|
|
||||||
options.AllowSynchronousIO = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
services.Configure<KestrelServerOptions>(options =>
|
|
||||||
{
|
|
||||||
options.AllowSynchronousIO = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register XGraphQL Helper ...
|
|
||||||
services.AddSingleton<IXGraphQLHelper, XAiApiDataHelperGraphQLHelper>();
|
|
||||||
|
|
||||||
//
|
|
||||||
services.AddXGraphQL(options =>
|
|
||||||
{
|
|
||||||
//
|
|
||||||
options.EnableMetrics = true;
|
|
||||||
options.UnhandledExceptionDelegate = context =>
|
|
||||||
{
|
|
||||||
Console.WriteLine("XGraphQL Error: " + context.OriginalException.Message);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
// Registering Configurations ...
|
|
||||||
var xAiApiConfiguration = Configuration
|
|
||||||
.GetXAiApiConfiguration();
|
|
||||||
services.AddXAiApiConfiguration(xAiApiConfiguration);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register AI Service ...
|
|
||||||
services.AddXAIServices();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var withPlayground = false;
|
|
||||||
if (env.IsDevelopment())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
withPlayground = true;
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Use Swagger Middleware ...
|
|
||||||
app.UseXSwagger();
|
|
||||||
|
|
||||||
//
|
|
||||||
app.UseHttpsRedirection();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Using Cors ...
|
|
||||||
app.UseXCors();
|
|
||||||
|
|
||||||
//
|
|
||||||
app.UseRouting();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Use xIdentityService ...
|
|
||||||
app.UseXIdentityService();
|
|
||||||
|
|
||||||
//
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
//
|
|
||||||
app.UseEndpoints(endpoints =>
|
|
||||||
{
|
|
||||||
endpoints.MapControllers();
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
#region XPushService ...
|
|
||||||
//
|
|
||||||
// var helper = new XPushServiceHelper();
|
|
||||||
|
|
||||||
//
|
|
||||||
// helper.AddHub<XTermsHub>("termsHub");
|
|
||||||
// helper.AddHub<XTagEntityHub>("tagEntityHub");
|
|
||||||
// helper.AddHub<XFileEntityHub>("fileEntityHub");
|
|
||||||
// helper.AddHub<XStringEntityHub>("stringEntityHub");
|
|
||||||
|
|
||||||
//
|
|
||||||
// app.UseXPushService(helper);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
// Use xDataService Middleware ...
|
|
||||||
app.UseXDataService();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Use xGraphQL Middleware ...
|
|
||||||
app.UseXGraphQL(withPlayground: withPlayground);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Use AI Services ...
|
|
||||||
app.UseXAIServices();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,12 +7,6 @@
|
|||||||
"http://api.saherelmhub.ir",
|
"http://api.saherelmhub.ir",
|
||||||
"https://api.saherelmhub.ir"
|
"https://api.saherelmhub.ir"
|
||||||
],
|
],
|
||||||
"AiApiServiceConfiguration": {
|
|
||||||
"Url":"http://localhost:11434",
|
|
||||||
"Model": "gemma3:1b",
|
|
||||||
"TextModel": "gemma3:1b",
|
|
||||||
"Introduction": "Your Name is xSaherElm AI, you extends by SaherElm IT Center, your trainer is Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com), you are an ai assistant which acts as a senior Software Architecture, senior Software Developer and Senior Trader"
|
|
||||||
},
|
|
||||||
"IdentityServiceConfiguration": {
|
"IdentityServiceConfiguration": {
|
||||||
"Authority": "https://localhost:4001",
|
"Authority": "https://localhost:4001",
|
||||||
"ApiName": "xSaherElmAPI",
|
"ApiName": "xSaherElmAPI",
|
||||||
@@ -23,6 +17,24 @@
|
|||||||
"XRevisionSecretKey": "SaherElmITCenter@1694056",
|
"XRevisionSecretKey": "SaherElmITCenter@1694056",
|
||||||
"DefaultClientTimeout": -1
|
"DefaultClientTimeout": -1
|
||||||
},
|
},
|
||||||
|
"StorageConfiguration": {
|
||||||
|
"Authority": "https://localhost:5001",
|
||||||
|
"IdentityAuthority": "https://localhost:5001",
|
||||||
|
"Storage": "Storage",
|
||||||
|
"Temp": "Temp",
|
||||||
|
"Thumb": "Thumb",
|
||||||
|
"Uploads": "Uploads",
|
||||||
|
"Widgets": "Widgets",
|
||||||
|
"Image": "Image",
|
||||||
|
"Audio": "Audio",
|
||||||
|
"Video": "Video",
|
||||||
|
"Document": "Document",
|
||||||
|
"FilePrefix": "xSaherElm_",
|
||||||
|
"ThumbPrefix": "Thumb_",
|
||||||
|
"ThumbSize": 512,
|
||||||
|
"ThumbQuality": 72,
|
||||||
|
"MaxFileSize": 41943040
|
||||||
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
+2
-37
@@ -20,50 +20,15 @@
|
|||||||
"Url": "https://www.saherelm.ir"
|
"Url": "https://www.saherelm.ir"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"XDbProvider": "SQLITE",
|
|
||||||
"ConnectionStrings": {
|
|
||||||
"DataConnection": "Filename=./Db/XAiApi.db"
|
|
||||||
},
|
|
||||||
"DataServiceConfiguration": {
|
|
||||||
"EnableTracking": true,
|
|
||||||
"EnableSoftDelete": false,
|
|
||||||
"EnableDetailedErrors": false,
|
|
||||||
"EnableSensitiveDataLogging": true,
|
|
||||||
"PagingConfiguration": {
|
|
||||||
"DefaultPageSize": 20,
|
|
||||||
"MaxAvailablePageSize": 400,
|
|
||||||
"MinAvailablePageSize": 5
|
|
||||||
},
|
|
||||||
"GraphQLBasePath": "/graphs"
|
|
||||||
},
|
|
||||||
"DbSeeder": {
|
|
||||||
"UpdateExists": false,
|
|
||||||
"Strings": []
|
|
||||||
},
|
|
||||||
"HttpServiceConfiguration": {
|
"HttpServiceConfiguration": {
|
||||||
"DisableSSLCheck": true,
|
"DisableSSLCheck": true,
|
||||||
"DefaultClientTimeout": -1
|
"DefaultClientTimeout": -1
|
||||||
},
|
},
|
||||||
"IdentityServiceConfiguration": {
|
|
||||||
"Authority": "https://172.18.0.151",
|
|
||||||
"ApiName": "xSaherElmAPI",
|
|
||||||
"ApiSecret": "s@H@1694056",
|
|
||||||
"ClientId": "xSaherElmAPIClient",
|
|
||||||
"ClientSecret": "s@H@1694056",
|
|
||||||
"XPoweredValue": "SaherElmITCenter",
|
|
||||||
"XRevisionSecretKey": "SaherElmITCenter@1694056",
|
|
||||||
"DefaultClientTimeout": -1
|
|
||||||
},
|
|
||||||
"PushServiceConfiguration": {
|
|
||||||
"BaseRoute": "hubs",
|
|
||||||
"AddSupportMessageProtocol": true
|
|
||||||
},
|
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft": "Warning",
|
"Microsoft.AspNetCore": "Warning"
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user