Compare commits
10
Commits
2b5e09912f
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
632dd04d98 | ||
|
|
9caf46a266 | ||
|
|
7dd333f013 | ||
|
|
f115b2bc85 | ||
|
|
d07a273ea3 | ||
|
|
db2d80160e | ||
|
|
a3b3e69e53 | ||
|
|
203ba30056 | ||
|
|
6b869e82d8 | ||
|
|
f7184c7b79 |
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
bin
|
bin/*
|
||||||
obj
|
obj/*
|
||||||
|
|
||||||
#
|
#
|
||||||
Db/*
|
Db/*
|
||||||
|
|||||||
@@ -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,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,33 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xCommons.Attributes;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xIdentityService.Controllers;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
|
|
||||||
namespace xAiApi.Base
|
|
||||||
{
|
|
||||||
[ApiController]
|
|
||||||
[ApiVersion("1.0")]
|
|
||||||
[RequireXPowered(true)]
|
|
||||||
[Route("api/v{version:apiVersion}/[controller]")]
|
|
||||||
public abstract class XIBaseV1Controller : XIBaseController
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region Constructor ...
|
|
||||||
protected XIBaseV1Controller(
|
|
||||||
ILogger<XIBaseV1Controller> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using xCommons.Attributes;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xCommons.Providers;
|
|
||||||
using xDataService.Interfaces;
|
|
||||||
using xIdentityService.Controllers;
|
|
||||||
using xIdentityService.Interfaces;
|
|
||||||
using xModels.Base;
|
|
||||||
using xPushService.Base;
|
|
||||||
using xPushService.Constants;
|
|
||||||
|
|
||||||
namespace xAiApi.Base
|
|
||||||
{
|
|
||||||
[ApiController]
|
|
||||||
[ApiVersion("1.0")]
|
|
||||||
[RequireXPowered(true)]
|
|
||||||
[Route("api/v{version:apiVersion}/entities/[controller]")]
|
|
||||||
public abstract class XIBaseV1EntityController<TEntity, TKey> : XIBaseEntityController<TEntity, TKey>
|
|
||||||
where TEntity : XBaseEntity<TKey>
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region Constructor ...
|
|
||||||
protected XIBaseV1EntityController(
|
|
||||||
ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
IXBaseRepository<TEntity, TKey> repository
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider,
|
|
||||||
repository
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
|
|
||||||
where TEntity : XBaseEntity<TKey>
|
|
||||||
{
|
|
||||||
//
|
|
||||||
#region Props ...
|
|
||||||
public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Constructor ...
|
|
||||||
protected XIBaseV1EntityHubController(
|
|
||||||
ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
|
|
||||||
XAppConfiguration appConfiguration,
|
|
||||||
IXIdentityProvider identityProvider,
|
|
||||||
XValidationProvider validationProvider,
|
|
||||||
IXBaseRepository<TEntity, TKey> repository,
|
|
||||||
IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider,
|
|
||||||
repository
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Hub = hub;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Hub ...
|
|
||||||
[NonAction]
|
|
||||||
public async Task SendPush(
|
|
||||||
string action,
|
|
||||||
string payLoad
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var actions = new List<string>
|
|
||||||
{
|
|
||||||
XBaseEntityHubAction.Add.GetStringValue(),
|
|
||||||
XBaseEntityHubAction.Update.GetStringValue(),
|
|
||||||
XBaseEntityHubAction.Delete.GetStringValue(),
|
|
||||||
XBaseEntityHubAction.AddMany.GetStringValue(),
|
|
||||||
XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
|
||||||
XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
|
||||||
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
var isValid =
|
|
||||||
!Hub.IsNull() &&
|
|
||||||
!action.IsNullOrEmpty() &&
|
|
||||||
!payLoad.IsNullOrEmpty() &&
|
|
||||||
actions.Contains(action);
|
|
||||||
if (!isValid)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Connection Id ...
|
|
||||||
var connectionId = GetConnectionId();
|
|
||||||
var clients = Hub.Clients.All;
|
|
||||||
if (!connectionId.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
clients = Hub.Clients.AllExcept(connectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
await clients.SendAsync(action, payLoad, connectionId);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace xAiApi.Constants
|
||||||
|
{
|
||||||
|
public struct XAiApiConstants
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Database Descriptor ...
|
||||||
|
public const string XAiApiDbIdentifier = "xAiApiDb";
|
||||||
|
public const string XAiApiMigrationsAssemblyIdentifier = "xAiApi";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,160 +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.Base;
|
|
||||||
using xAiModels.Models;
|
|
||||||
using xCommons.Configurations;
|
|
||||||
using xCommons.Extensions;
|
|
||||||
using xCommons.Providers;
|
|
||||||
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="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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[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
|
|
||||||
);
|
|
||||||
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,326 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
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
|
|
||||||
) : base(
|
|
||||||
logger,
|
|
||||||
appConfiguration,
|
|
||||||
identityProvider,
|
|
||||||
validationProvider,
|
|
||||||
repository,
|
|
||||||
hub
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Interface Implementations ...
|
|
||||||
//
|
|
||||||
#region Retrieve ...
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<XTest>> Get(
|
|
||||||
[FromRoute] int id, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return await base
|
|
||||||
.Get(
|
|
||||||
id: id,
|
|
||||||
containsDetail: containsDetail,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<IEnumerable<XTest>>> GetAll(
|
|
||||||
[FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return await base
|
|
||||||
.GetAll(
|
|
||||||
containsDetail: containsDetail,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("FindOne/{query}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<XTest>> FindOne(
|
|
||||||
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return await base
|
|
||||||
.FindOne(
|
|
||||||
query: query,
|
|
||||||
containsDetail: containsDetail,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("FindMany/{query}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<IEnumerable<XTest>>> FindMany(
|
|
||||||
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return await base
|
|
||||||
.FindMany(
|
|
||||||
query: query,
|
|
||||||
containsDetail: containsDetail,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("Query")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<XQueryResult<XTest>>> Query(
|
|
||||||
[FromQuery] XQuery query, [FromQuery] bool ignoreSoftDeleteds = true
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return await base
|
|
||||||
.Query(
|
|
||||||
query: query,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Add ...
|
|
||||||
[HttpPost]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> Add(
|
|
||||||
[FromBody] XTest item
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.Add(item);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Handle Sending Push Notification ...
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.Add.GetStringValue(),
|
|
||||||
payLoad: entity.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("AddOrUpdate")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> AddOrUpdate(
|
|
||||||
[FromBody] XTest item
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.AddOrUpdate(item);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Handle Sending Push Notification ...
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
|
||||||
payLoad: entity.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("AddMany")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult> AddMany(
|
|
||||||
[FromBody] XBaseRangeRequest<XTest> request
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await base
|
|
||||||
.AddMany(request);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!(result as OkObjectResult).IsNull())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.AddMany.GetStringValue(),
|
|
||||||
payLoad: request.Items.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Update ...
|
|
||||||
[HttpPut("{id}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> Update(
|
|
||||||
[FromRoute] int id, [FromBody] XTest item
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.Update(
|
|
||||||
id,
|
|
||||||
item
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.Update.GetStringValue(),
|
|
||||||
payLoad: entity.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("UpdateMany")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<bool>> UpdateMany(
|
|
||||||
[FromBody] XBaseRangeRequest<XTest> request
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await base
|
|
||||||
.UpdateMany(request);
|
|
||||||
|
|
||||||
//
|
|
||||||
var resultObject = (result.Result as OkObjectResult).Value;
|
|
||||||
if (!resultObject.IsNull() && (bool)resultObject)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
|
||||||
payLoad: request.Items.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Exists ...
|
|
||||||
[HttpGet("{id}/IsExists")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
||||||
public override async Task<ActionResult<bool>> IsExists(
|
|
||||||
[FromRoute] int id, [FromQuery] bool ignoreSoftDeleteds = true
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return await base
|
|
||||||
.IsExists(
|
|
||||||
id: id,
|
|
||||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
|
||||||
#region Remove ...
|
|
||||||
[HttpDelete("{id}")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult<XTest>> Remove(
|
|
||||||
[FromRoute] int id, bool softDelete = true
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var entity = await base
|
|
||||||
.Remove(
|
|
||||||
id: id,
|
|
||||||
softDelete: softDelete
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!entity.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
|
||||||
payLoad: entity.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("RemoveMany")]
|
|
||||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
||||||
public override async Task<ActionResult> RemoveMany(
|
|
||||||
[FromBody] XBaseRangeRequest<XTest> request, bool softDelete = true
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result = await base
|
|
||||||
.RemoveMany(
|
|
||||||
request: request,
|
|
||||||
softDelete: softDelete
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!(result as OkObjectResult).IsNull())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
await SendPush(
|
|
||||||
action: XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
|
||||||
payLoad: request.Items.ToJSON()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
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) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using xAiApi.Constants;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xDataService.Models;
|
||||||
|
|
||||||
|
namespace xAiApi.Database
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ai Api Database Descriptor ...
|
||||||
|
/// </summary>
|
||||||
|
public class XAiApiDatabaseDescriptor : XDatabaseDescriptor<XAiApiDbContext>, IXDatabaseDescriptor<XAiApiDbContext>
|
||||||
|
{
|
||||||
|
public XAiApiDatabaseDescriptor() : base(
|
||||||
|
name: XAiApiConstants.XAiApiDbIdentifier,
|
||||||
|
repositories: []
|
||||||
|
)
|
||||||
|
{
|
||||||
|
OptionsBuilder = b => b.MigrationsAssembly(XAiApiConstants.XAiApiMigrationsAssemblyIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using xAiApi.Constants;
|
||||||
|
using xAiModels.Providers;
|
||||||
|
using xDataService.Configuration;
|
||||||
|
using xDataService.Db;
|
||||||
|
using xDataService.Providers;
|
||||||
|
using xFileService.Providers;
|
||||||
|
using xStringService.Providers;
|
||||||
|
using xTagService.Providers;
|
||||||
|
|
||||||
|
namespace xAiApi.Database
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Db Context of AiApi ...
|
||||||
|
/// </summary>
|
||||||
|
public class XAiApiDbContext : XDbContext
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region DbSets ...
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Navigation Property Entities ...
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Constructor ...
|
||||||
|
public XAiApiDbContext(
|
||||||
|
DbContextOptions options,
|
||||||
|
XDataServiceConfiguration config,
|
||||||
|
XEntityRegisterarHandlerService dynamicEntityHandlers
|
||||||
|
) : base(
|
||||||
|
config: config,
|
||||||
|
options: options,
|
||||||
|
database: XAiApiConstants.XAiApiDbIdentifier,
|
||||||
|
dynamicEntityHandlers: dynamicEntityHandlers,
|
||||||
|
dynamicEntityRegisterarsNames: [
|
||||||
|
nameof(XTagEntityRegisterar),
|
||||||
|
nameof(XFileEntityRegisterar),
|
||||||
|
nameof(XStringEntityRegisterar),
|
||||||
|
nameof(XAiMessageEntityRegisterar),
|
||||||
|
nameof(XAiProjectEntityRegisterar),
|
||||||
|
nameof(XAiConversationEntityRegisterar),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Overrides ...
|
||||||
|
//
|
||||||
|
public override void OnXModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
public override void OnXConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{ }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ using xIdentityHelper;
|
|||||||
|
|
||||||
namespace xAiApi.Extensions
|
namespace xAiApi.Extensions
|
||||||
{
|
{
|
||||||
public static class XStartupExtensions
|
public static class XProgramExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register Authorization Policies
|
/// Register Authorization Policies
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.AI;
|
||||||
|
|
||||||
|
namespace xAiApi.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Describe a Base Service Actions of any Ai Based Services ...
|
||||||
|
/// </summary>
|
||||||
|
public interface IAIServiceBase : IDisposable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base Method for Communicate with LLM ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> AskAsync(
|
||||||
|
string prompt,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base Method for Communicate with LLM ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IAsyncEnumerable<string> AskAsEnumerable(
|
||||||
|
string prompt,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get LLM Client instance for Communicating with LLM ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="llm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IChatClient GetClient(string llm = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create Custom HttpClient for Communicating with LLM API ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
HttpClient GetHttpClient(string url = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prepare a Message History List for LLM Communication based on Prompt ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt"></param>
|
||||||
|
/// <param name="forcePrompt"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IList<ChatMessage> GetHistory(
|
||||||
|
string prompt = null,
|
||||||
|
bool forcePrompt = true
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prepare a Message History List for LLM Communication based on Prompt ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <param name="forceMessage"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IList<ChatMessage> GetHistory(
|
||||||
|
ChatMessage message = null,
|
||||||
|
bool forceMessage = true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi
|
namespace xAiApi
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,20 +1,27 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:6636",
|
||||||
|
"sslPort": 44322
|
||||||
|
}
|
||||||
|
},
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"http": {
|
"IIS Express": {
|
||||||
"commandName": "Project",
|
"commandName": "IISExpress",
|
||||||
"dotnetRunMessages": true,
|
"launchBrowser": true,
|
||||||
"launchBrowser": false,
|
"launchUrl": "weatherforecast",
|
||||||
"applicationUrl": "http://localhost:5129",
|
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"https": {
|
"xAiApi": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"launchBrowser": true,
|
||||||
"launchBrowser": false,
|
"launchUrl": "weatherforecast",
|
||||||
"applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;",
|
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||||
"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)
|
|
||||||
+118
-141
@@ -1,54 +1,59 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using xTagService.DI;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using xAiApi.Database;
|
||||||
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 xHttpService.DI;
|
||||||
using xIdentityService.DI;
|
|
||||||
using xPushService.DI;
|
using xPushService.DI;
|
||||||
|
using xFileService.DI;
|
||||||
|
using xDataService.DI;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Reflection;
|
||||||
|
using xAiApi.Extensions;
|
||||||
|
using xStringService.DI;
|
||||||
|
using xStorageService.DI;
|
||||||
|
using xIdentityService.DI;
|
||||||
|
using xDataService.Models;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using xDataService.Configuration;
|
using Newtonsoft.Json.Serialization;
|
||||||
using xDataService.Constants;
|
using Microsoft.Extensions.Configuration;
|
||||||
using xDataService.DI;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using xDataService.Interfaces;
|
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||||
using xPushService.Helpers;
|
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
|
namespace xAiApi
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
#region Props ...
|
||||||
public IConfiguration Configuration { get; }
|
public IConfiguration Configuration { get; }
|
||||||
|
private readonly List<XDatabaseDescriptor> databases;
|
||||||
|
private readonly XAiApiDatabaseDescriptor apiDatabaseDescriptor;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Constructor(s) ...
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create an Api Descriptor Class Instance ...
|
||||||
|
apiDatabaseDescriptor = new XAiApiDatabaseDescriptor();
|
||||||
|
databases = new List<XDatabaseDescriptor>
|
||||||
|
{
|
||||||
|
apiDatabaseDescriptor
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
@@ -76,24 +81,8 @@ namespace xAiApi
|
|||||||
services.AddXHttpService(Configuration);
|
services.AddXHttpService(Configuration);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register Api Versioning ...
|
// Add Api V1 Versioning ...
|
||||||
services.AddApiVersioning(opt =>
|
services.AddXApiV1Versioning();
|
||||||
{
|
|
||||||
//
|
|
||||||
// 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 ...
|
// OAuthIntrospectin Http Client Handler ...
|
||||||
@@ -120,108 +109,76 @@ namespace xAiApi
|
|||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register XPushService ...
|
var lifeTime = ServiceLifetime.Scoped;
|
||||||
services.AddXPushService(Configuration);
|
var repositoryType = xDataService.Constants.XRepositoryType.EF;
|
||||||
// services.AddXPushHubProvider(lifeTime);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register XIdentityService ...
|
// Register XIdentity Service ...
|
||||||
services.AddXIdentityService(Configuration, lifeTime);
|
services.AddXIdentityService(
|
||||||
|
lifeTime: lifeTime,
|
||||||
|
configuration: Configuration
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register DataService here ...
|
// Storage Service ...
|
||||||
#region Register xDataService ...
|
services.AddXStorageService(Configuration);
|
||||||
//
|
|
||||||
// Register IXDataServiceHelper ...
|
|
||||||
services.AddSingleton<IXDataServiceHelper, XAiApiDataProviderHelper>();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prepare Db Options Builder based on Provider ...
|
// Push Service ...
|
||||||
var providerType = Configuration.GetXDbProviderType();
|
services.AddXPushService(
|
||||||
switch (providerType)
|
lifeTime: lifeTime,
|
||||||
|
config: Configuration
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Preparing DataBases ...
|
||||||
|
if (databases.HasChild())
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
case XDbProviders.MySQL:
|
databases
|
||||||
case XDbProviders.SQLite:
|
.ToList()
|
||||||
case XDbProviders.SQLServer:
|
.ForEach(database =>
|
||||||
Action<dynamic> optionsBuilder = optionsBuilder = b =>
|
|
||||||
{
|
{
|
||||||
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register xDataService on DI ...
|
// Register DataBase ...
|
||||||
services.AddXDataService<XAiApiDbContext, XAiApiDbSeeder>(
|
services.AddXDatabase(
|
||||||
Configuration,
|
lifeTime: lifeTime,
|
||||||
lifeTime,
|
descriptor: database,
|
||||||
XDbProviderConfigurations.DEFAULT_CONNECTION_NAME,
|
configuration: Configuration
|
||||||
optionsBuilder
|
|
||||||
);
|
);
|
||||||
break;
|
});
|
||||||
|
|
||||||
//
|
|
||||||
case XDbProviders.MongoDB:
|
|
||||||
//
|
|
||||||
// Register xDataService on DI ...
|
|
||||||
services.AddXDataService<XAiApiDbSeeder>(
|
|
||||||
Configuration,
|
|
||||||
lifeTime,
|
|
||||||
XDbProviderConfigurations.DEFAULT_CONNECTION_NAME
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register GraphQL here ...
|
// Register String Service ...
|
||||||
#region Register xGraphQL ...
|
services.AddXStringService<XAiApiDbContext>(
|
||||||
//
|
lifeTime: lifeTime,
|
||||||
services.Configure<IISServerOptions>(options =>
|
repositoryType: repositoryType
|
||||||
{
|
);
|
||||||
options.AllowSynchronousIO = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
//
|
||||||
services.Configure<KestrelServerOptions>(options =>
|
// Register Tag Service ...
|
||||||
{
|
services.AddXTagService<XAiApiDbContext>(
|
||||||
options.AllowSynchronousIO = true;
|
lifeTime: lifeTime,
|
||||||
});
|
repositoryType: repositoryType
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register XGraphQL Helper ...
|
// Register File Service ...
|
||||||
services.AddSingleton<IXGraphQLHelper, XAiApiDataHelperGraphQLHelper>();
|
services.AddXFileService<XAiApiDbContext>(
|
||||||
|
lifeTime: lifeTime,
|
||||||
//
|
repositoryType: repositoryType
|
||||||
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)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
var withPlayground = false;
|
// Configure the HTTP request pipeline.
|
||||||
|
var isDevelopmentEnvironment = false;
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
//
|
isDevelopmentEnvironment = true;
|
||||||
withPlayground = true;
|
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,6 +187,7 @@ namespace xAiApi
|
|||||||
app.UseXSwagger();
|
app.UseXSwagger();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Force Https Redirection ...
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -237,6 +195,7 @@ namespace xAiApi
|
|||||||
app.UseXCors();
|
app.UseXCors();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Using Routing ...
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -244,6 +203,7 @@ namespace xAiApi
|
|||||||
app.UseXIdentityService();
|
app.UseXIdentityService();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Use Authorization ...
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -253,31 +213,48 @@ namespace xAiApi
|
|||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
#region XPushService ...
|
// Use Storage Service ...
|
||||||
//
|
app.UseXStorageService();
|
||||||
// var helper = new XPushServiceHelper();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// helper.AddHub<XTermsHub>("termsHub");
|
// Use PushService ...
|
||||||
// helper.AddHub<XTagEntityHub>("tagEntityHub");
|
var pushHelper = new XPushServiceHelper();
|
||||||
// helper.AddHub<XFileEntityHub>("fileEntityHub");
|
app.UseXPushService(pushHelper);
|
||||||
// helper.AddHub<XStringEntityHub>("stringEntityHub");
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// app.UseXPushService(helper);
|
// Using DataBase ...
|
||||||
#endregion
|
if (databases.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
databases
|
||||||
|
.ToList()
|
||||||
|
.ForEach(database =>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
app.UseXDatabase(
|
||||||
|
descriptor: database,
|
||||||
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use xDataService Middleware ...
|
// Using String Service ...
|
||||||
app.UseXDataService();
|
app.UseXStringService(
|
||||||
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use xGraphQL Middleware ...
|
// Using XTag Service ...
|
||||||
app.UseXGraphQL(withPlayground: withPlayground);
|
app.UseXTagService(
|
||||||
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use AI Services ...
|
// Using File Service ...
|
||||||
app.UseXAIServices();
|
app.UseXFileService(
|
||||||
|
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user