This commit is contained in:
2026-04-24 13:42:14 +03:30
parent 5efd41754a
commit e49c273171
9 changed files with 643 additions and 171 deletions
+85 -6
View File
@@ -1,21 +1,100 @@
using xCommons.Extensions;
using System.Collections.Generic;
using Microsoft.Extensions.AI;
using System.Linq;
using xAiApi.AI.Models.Entities;
using xAiModels.Models;
namespace xAiApi.AI.Extensions
{
/// <summary>
/// Extensions which used for AiModels ...
/// </summary>
public static class AiModelsExtensions
{
public static AIContent GetLast(IList<AIContent> source)
/// <summary>
/// Converts Entity to Dto regardsless of Owner and NavigationProperties ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XAiMessageDto ToDto(this XAiMessage source)
{
//
AIContent result = null;
XAiMessageDto result = null;
//
if (source.HasChild())
if (!source.IsNullOrDefault())
{
result = source.ElementAt(source.Count - 1);
//
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),
}
);
}
//
-162
View File
@@ -1,162 +0,0 @@
using Microsoft.Extensions.AI;
using xAiApi.AI.Constants;
using xCommons.Extensions;
namespace xAiApi.AI.Extensions
{
/// <summary>
/// Extensions for ChatRole ...
/// </summary>
public static class ChatRoleExtensions
{
/// <summary>
/// Normalize an String to Propper Chat Role Value ...
/// <see cref="XAiChatRoles"/>>
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string GetChatRoleTitle(this string source)
{
//
var result = XAiChatRoles.None;
//
if (source.ToNormalString() == XAiChatRoles.None.ToNormalString())
{
result = XAiChatRoles.None;
}
else if (source.ToNormalString() == XAiChatRoles.User.ToNormalString())
{
result = XAiChatRoles.User;
}
else if (source.ToNormalString() == XAiChatRoles.Tool.ToNormalString())
{
result = XAiChatRoles.Tool;
}
else if (source.ToNormalString() == XAiChatRoles.System.ToNormalString())
{
result = XAiChatRoles.System;
}
else if (source.ToNormalString() == XAiChatRoles.Assistant.ToNormalString())
{
result = XAiChatRoles.Assistant;
}
//
return result;
}
/// <summary>
/// Get Chat Role Title from Chat Role Class ...
/// <see cref="XAiChatRoles"/>
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string GetRole(this ChatRole source)
{
//
var result = source.Value
.GetChatRoleTitle();
//
return result;
}
/// <summary>
/// Generate Chat Role Class Based on role Title ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static ChatRole ToChatRole(this string source)
{
//
var role = source.GetChatRoleTitle();
ChatRole result = new ChatRole(role);
//
return result;
}
/// <summary>
/// Extract Chat Role Enum from Chat Role ...
/// <see cref="ChatRole"/>
/// <see cref="XAiChatRole"/>
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XAiChatRole ToChatRole(this ChatRole source)
{
//
var role = source
.GetRole()
.GetChatRoleTitle();
//
XAiChatRole result = XAiChatRole.User;
//
if (role == XAiChatRoles.User)
{
result = XAiChatRole.User;
}
else if (role == XAiChatRoles.Tool)
{
result = XAiChatRole.Tool;
}
else if (role == XAiChatRoles.System)
{
result = XAiChatRole.System;
}
else if (role == XAiChatRoles.Assistant)
{
result = XAiChatRole.Assistant;
}
//
return result;
}
/// <summary>
/// Validate an String as Chat Role ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this string source)
{
//
var result =
source != XAiChatRoles.None &&
source.ToNormalString() != XAiChatRoles.None.ToNormalString();
//
return result;
}
/// <summary>
/// Validate Role ...
/// <see cref="XAiChatRole"/>>
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XAiChatRole source)
{
//
var result = source != XAiChatRole.None;
return result;
}
/// <summary>
/// Validate Role ...
/// <see cref="ChatRole"/>>
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this ChatRole source)
{
//
var role = source.ToChatRole();
var result = role.IsValid();
return result;
}
}
}