Compare commits
1
Commits
383e42a8d2
...
efaf71d962
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efaf71d962 |
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using xModels.Dtos;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using xAiModels.Models;
|
||||
@@ -164,14 +165,16 @@ namespace xAiApi.Controllers
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Data Provided Actions ...
|
||||
#region Loaders ...
|
||||
/// <summary>
|
||||
/// Retrieve AI Projects ...
|
||||
/// </summary>
|
||||
/// <param name="includeDefaults"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Projects")]
|
||||
public async Task<ActionResult<IEnumerable<XAiProjectDto>>> LoadProjects(
|
||||
[FromQuery] bool includeDefaults = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -186,6 +189,7 @@ namespace xAiApi.Controllers
|
||||
var result = await aiService.LoadProjects(
|
||||
ownerId: userInfo.UserId,
|
||||
connectionId: connectionId,
|
||||
includeDefaults: includeDefaults,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -282,7 +286,132 @@ namespace xAiApi.Controllers
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Queries ...
|
||||
/// <summary>
|
||||
/// Query Projects ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Projects/Query")]
|
||||
public async Task<ActionResult<XQueryResult<XAiProjectDto>>> QueryProjects(
|
||||
[FromQuery] XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await aiService.QueryProjects(
|
||||
query: query,
|
||||
ownerId: userInfo.UserId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Conversations ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Projects/{projectId}/Conversations/Query")]
|
||||
public async Task<ActionResult<XQueryResult<XAiConversationDto>>> QueryConversations(
|
||||
[FromRoute] Guid projectId,
|
||||
[FromQuery] XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await aiService.QueryConversations(
|
||||
query: query,
|
||||
projectId: projectId,
|
||||
ownerId: userInfo.UserId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Messages ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Conversations/{conversationId}/Messages/Query")]
|
||||
public async Task<ActionResult<XQueryResult<XAiMessageDto>>> QueryMessages(
|
||||
[FromRoute] Guid conversationId,
|
||||
[FromQuery] XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await aiService.QueryMessages(
|
||||
query: query,
|
||||
ownerId: userInfo.UserId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Creators ...
|
||||
/// <summary>
|
||||
/// Create an AI Project ...
|
||||
/// </summary>
|
||||
@@ -392,7 +521,10 @@ namespace xAiApi.Controllers
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Data Actions ...
|
||||
/// <summary>
|
||||
/// Ask Question and Get Response ...
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using xModels.Dtos;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using xAiModels.Models;
|
||||
@@ -92,11 +93,13 @@ namespace xAiApi.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="includeDefaults"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiProjectDto>> LoadProjects(
|
||||
string ownerId,
|
||||
string connectionId = null,
|
||||
bool includeDefaults = false,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -124,6 +127,49 @@ namespace xAiApi.Interfaces
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Query Projects ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XAiProjectDto>> QueryProjects(
|
||||
string ownerId,
|
||||
XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Query Conversations ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XAiConversationDto>> QueryConversations(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Query Messages ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XQueryResult<XAiMessageDto>> QueryMessages(
|
||||
string ownerId,
|
||||
Guid conversationId,
|
||||
XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Create an AI Project ...
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using xModels.Dtos;
|
||||
using System.Threading;
|
||||
using xAiModels.Models;
|
||||
using xAiModels.Models.Dtos;
|
||||
@@ -38,14 +39,16 @@ namespace xAiApi.Interfaces
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Data Provided Actions ...
|
||||
#region Loaders ...
|
||||
/// <summary>
|
||||
/// Retrieve AI Projects ...
|
||||
/// </summary>
|
||||
/// <param name="includeDefaults"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Projects")]
|
||||
Task<ActionResult<IEnumerable<XAiProjectDto>>> LoadProjects(
|
||||
[FromQuery] bool includeDefaults = false,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
@@ -72,7 +75,55 @@ namespace xAiApi.Interfaces
|
||||
[FromRoute] Guid conversationId,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Queries ...
|
||||
/// <summary>
|
||||
/// Query Projects ...
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Projects/Query")]
|
||||
Task<ActionResult<XQueryResult<XAiProjectDto>>> QueryProjects(
|
||||
[FromQuery] XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Query Conversations ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Projects/{projectId}/Conversations/Query")]
|
||||
Task<ActionResult<XQueryResult<XAiConversationDto>>> QueryConversations(
|
||||
[FromRoute] Guid projectId,
|
||||
[FromQuery] XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Query Messages ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Conversations/{conversationId}/Messages/Query")]
|
||||
Task<ActionResult<XQueryResult<XAiMessageDto>>> QueryMessages(
|
||||
[FromRoute] Guid conversationId,
|
||||
[FromQuery] XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Creators ...
|
||||
/// <summary>
|
||||
/// Create an AI Project ...
|
||||
/// </summary>
|
||||
@@ -98,7 +149,10 @@ namespace xAiApi.Interfaces
|
||||
[FromBody] XAiConversationDto item,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Data Actions ...
|
||||
/// <summary>
|
||||
/// Ask Question and Get Response ...
|
||||
/// </summary>
|
||||
|
||||
+221
-69
@@ -2,6 +2,7 @@ using System;
|
||||
using OpenAI;
|
||||
using OllamaSharp;
|
||||
using System.Linq;
|
||||
using xModels.Dtos;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using xAiApi.Constants;
|
||||
@@ -352,11 +353,13 @@ namespace xAiApi.Providers
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="includeDefaults"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XAiProjectDto>> LoadProjects(
|
||||
string ownerId,
|
||||
string connectionId = null,
|
||||
bool includeDefaults = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -377,42 +380,50 @@ namespace xAiApi.Providers
|
||||
);
|
||||
|
||||
//
|
||||
// Here we have to fill Conversations of Default Project ...
|
||||
var defaultProjectId = result.GetDafualtProject(ownerId);
|
||||
var defaultProject = result.FirstOrDefault(x => x.Id == defaultProjectId);
|
||||
result = result.Where(x => x.Id != defaultProjectId);
|
||||
// Handle Defaults Including ...
|
||||
if (includeDefaults)
|
||||
{
|
||||
//
|
||||
// Here we have to fill Conversations of Default Project ...
|
||||
var defaultProjectId = result.GetDafualtProject(ownerId);
|
||||
var defaultProject = result.FirstOrDefault(x => x.Id == defaultProjectId);
|
||||
result = result.Where(x => x.Id != defaultProjectId);
|
||||
|
||||
//
|
||||
// Reading Conversations of Specified Default Project ...
|
||||
var defaultProjectConversations = await dataProvider.LoadConversations(
|
||||
fillMessages: false,
|
||||
connectionId: connectionId,
|
||||
projectId: defaultProjectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var defaultConversationId = defaultProjectConversations.GetDefaultConversation(
|
||||
ownerId: ownerId,
|
||||
projectId: defaultProjectId
|
||||
);
|
||||
var defaultConversation = defaultProjectConversations.First(x => x.Id == defaultConversationId);
|
||||
defaultProjectConversations = defaultProjectConversations.Where(x => x.Id != defaultConversationId);
|
||||
//
|
||||
// Reading Conversations of Specified Default Project ...
|
||||
var defaultProjectConversations = await dataProvider.LoadConversations(
|
||||
fillMessages: false,
|
||||
connectionId: connectionId,
|
||||
projectId: defaultProjectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
var defaultConversationId = defaultProjectConversations.GetDefaultConversation(
|
||||
ownerId: ownerId,
|
||||
projectId: defaultProjectId
|
||||
);
|
||||
var defaultConversation = defaultProjectConversations.First(x => x.Id == defaultConversationId);
|
||||
defaultProjectConversations = defaultProjectConversations.Where(x => x.Id != defaultConversationId);
|
||||
|
||||
//
|
||||
// Reading Default Conversations Messages ...
|
||||
var defaultConversationMessages = await dataProvider.LoadMessages(
|
||||
cancellationToken: cancellationToken,
|
||||
conversationId: defaultConversationId
|
||||
);
|
||||
//
|
||||
// Reading Default Conversations Messages ...
|
||||
var defaultConversationMessages = await dataProvider.LoadMessages(
|
||||
cancellationToken: cancellationToken,
|
||||
conversationId: defaultConversationId
|
||||
);
|
||||
|
||||
//
|
||||
defaultConversation.Messages = [.. defaultConversationMessages];
|
||||
defaultProjectConversations = [defaultConversation, .. defaultProjectConversations];
|
||||
result = [defaultProject, .. result];
|
||||
//
|
||||
defaultConversation.Messages = [.. defaultConversationMessages.OrderByDescending(m => m.CreatedOn)];
|
||||
defaultProjectConversations = [defaultConversation, .. defaultProjectConversations];
|
||||
defaultProject.Conversations = [.. defaultProjectConversations];
|
||||
result = [defaultProject, .. result];
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Load Conversations of Specified AI Project ...
|
||||
/// </summary>
|
||||
@@ -647,6 +658,7 @@ namespace xAiApi.Providers
|
||||
Role = XAiChatRole.User,
|
||||
CreatedOn = DateTime.UtcNow,
|
||||
ConversationId = conversationId,
|
||||
ConversationTitle = conversation.Title
|
||||
};
|
||||
promptMessage = await dataProvider.AddMessage(
|
||||
item: promptMessage,
|
||||
@@ -678,9 +690,10 @@ namespace xAiApi.Providers
|
||||
{
|
||||
Content = answer,
|
||||
OwnerId = ownerId,
|
||||
Role = XAiChatRole.System,
|
||||
CreatedOn = DateTime.UtcNow,
|
||||
ConversationId = conversationId
|
||||
Role = XAiChatRole.Assistant,
|
||||
ConversationId = conversationId,
|
||||
ConversationTitle = conversation.Title
|
||||
};
|
||||
result = await dataProvider.AddMessage(
|
||||
item: result,
|
||||
@@ -891,6 +904,149 @@ namespace xAiApi.Providers
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Query ...
|
||||
/// <summary>
|
||||
/// Query Projects ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XAiProjectDto>> QueryProjects(
|
||||
string ownerId,
|
||||
XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await dataProvider.QueryProjects(
|
||||
query: query,
|
||||
ownerId: ownerId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Conversations ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XAiConversationDto>> QueryConversations(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty() ||
|
||||
projectId.IsDefaultGuid())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Project ...
|
||||
var project = await dataProvider.GetProject(
|
||||
id: projectId,
|
||||
fillConversations: false,
|
||||
fillConversationMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (project.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Owner ...
|
||||
if (ownerId != project.OwnerId)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await dataProvider.QueryConversations(
|
||||
query: query,
|
||||
ownerId: ownerId,
|
||||
projectId: projectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query Messages ...
|
||||
/// </summary>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XQueryResult<XAiMessageDto>> QueryMessages(
|
||||
string ownerId,
|
||||
Guid conversationId,
|
||||
XQuery query,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (ownerId.IsNullOrEmpty() ||
|
||||
conversationId.IsDefaultGuid())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Conversation ...
|
||||
var conversation = await dataProvider.GetConversation(
|
||||
id: conversationId,
|
||||
fillMessages: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (conversation.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Owner ...
|
||||
if (ownerId != conversation.OwnerId)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await dataProvider.QueryMessages(
|
||||
query: query,
|
||||
ownerId: ownerId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Base Dispose Action ...
|
||||
/// </summary>
|
||||
@@ -916,49 +1072,45 @@ namespace xAiApi.Providers
|
||||
//
|
||||
var result = new List<ChatMessage>();
|
||||
|
||||
//
|
||||
// Retrieve Introduction Prompt ...
|
||||
var introductionPrompt = configuration.GetPrompt(XAiApiConstants.XAiApiIntroductionPromptName);
|
||||
if (introductionPrompt.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidData.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var introductionMessage = new ChatMessage(
|
||||
role: ChatRole.System,
|
||||
content: introductionPrompt
|
||||
);
|
||||
|
||||
//
|
||||
result.Add(introductionMessage);
|
||||
|
||||
//
|
||||
if (!project.IsNullOrDefault() &&
|
||||
!project.Prompt.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
// TODO: Handle Project Files Here ...
|
||||
var projectMessage = new ChatMessage(
|
||||
role: ChatRole.System,
|
||||
contents: [new TextContent(project.Prompt)]
|
||||
);
|
||||
result.Add(projectMessage);
|
||||
}
|
||||
|
||||
//
|
||||
if (messages.HasChild())
|
||||
{
|
||||
//
|
||||
// if Messages Has Child, this means
|
||||
// Default Messages Handled before ...
|
||||
result = [.. messages.Select(m => m.ToChatMessages())];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If Message Has not any Childs, this means
|
||||
// First Asking Questions ...
|
||||
|
||||
//
|
||||
// Retrieve Introduction Prompt ...
|
||||
var introductionPrompt = configuration.GetPrompt(XAiApiConstants.XAiApiIntroductionPromptName);
|
||||
if (introductionPrompt.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidData.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var introductionMessage = new ChatMessage(
|
||||
role: ChatRole.System,
|
||||
content: introductionPrompt
|
||||
);
|
||||
|
||||
//
|
||||
result.Add(introductionMessage);
|
||||
|
||||
//
|
||||
if (!project.IsNullOrDefault() &&
|
||||
!project.Prompt.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
// TODO: Handle Project Files Here ...
|
||||
var projectMessage = new ChatMessage(
|
||||
role: ChatRole.System,
|
||||
contents: [new TextContent(project.Prompt)]
|
||||
);
|
||||
result.Add(projectMessage);
|
||||
}
|
||||
// TODO: Here we can Implement Memory Management based on
|
||||
// Last nth of Messages, or Summarization of Messages, etc ...
|
||||
result = [..result, ..messages
|
||||
.OrderBy(m => m.CreatedOn)
|
||||
.Select(m => m.ToChatMessages())];
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user