Compare commits
8
Commits
f6a916fa83
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a228439a5 | ||
|
|
13cd0745c6 | ||
|
|
5bccce3475 | ||
|
|
cddf2650f5 | ||
|
|
fba69b274c | ||
|
|
0077008105 | ||
|
|
3dc54332c2 | ||
|
|
dab384ea37 |
@@ -536,6 +536,8 @@ namespace xAiApi.Controllers
|
|||||||
prompt: request.Prompt,
|
prompt: request.Prompt,
|
||||||
minScore: request.MinScore,
|
minScore: request.MinScore,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
|
extractFileContents: false,
|
||||||
|
addFilesToKnowledge: false,
|
||||||
projectId: request.ProjectId,
|
projectId: request.ProjectId,
|
||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken,
|
||||||
conversationId: request.ConversationId
|
conversationId: request.ConversationId
|
||||||
@@ -634,7 +636,7 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
[HttpGet("Projects/{projectId}/Conversations")]
|
[HttpGet("Projects/{projectId}/Conversations")]
|
||||||
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
||||||
[FromRoute] Guid projectId,
|
[FromRoute] Guid? projectId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -642,12 +644,44 @@ namespace xAiApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
var userInfo = await GetUserInfo();
|
||||||
if (projectId.IsDefaultGuid())
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.LoadConversations(
|
||||||
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
XException.InvalidArgs.Throw();
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Specified AI Project's Conversations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
[HttpGet("Projects/Conversations")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadProjectConversations(
|
||||||
|
[FromQuery] Guid? projectId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var userInfo = await GetUserInfo();
|
var userInfo = await GetUserInfo();
|
||||||
var connectionId = GetConnectionId();
|
var connectionId = GetConnectionId();
|
||||||
@@ -655,6 +689,7 @@ namespace xAiApi.Controllers
|
|||||||
//
|
//
|
||||||
var result = await aiService.LoadConversations(
|
var result = await aiService.LoadConversations(
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -679,7 +714,7 @@ namespace xAiApi.Controllers
|
|||||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
[HttpGet("Conversations/{conversationId}/Messages")]
|
[HttpGet("Conversations/{conversationId}/Messages")]
|
||||||
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
||||||
[FromRoute] Guid conversationId,
|
[FromRoute] Guid? conversationId,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -687,14 +722,52 @@ namespace xAiApi.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
var userInfo = await GetUserInfo();
|
||||||
if (conversationId.IsDefaultGuid())
|
var connectionId = GetConnectionId();
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await aiService.LoadMessages(
|
var result = await aiService.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
conversationId: conversationId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve Specified AI Conversation's Messages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
[HttpGet("Conversations/Messages")]
|
||||||
|
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadConversationMessages(
|
||||||
|
[FromQuery] Guid? conversationId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -949,6 +1022,63 @@ namespace xAiApi.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create an AI Conversation ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
[HttpPost("Projects/Conversations")]
|
||||||
|
public async Task<ActionResult<XAiConversationDto>> CreateProjectConversation(
|
||||||
|
[FromQuery] Guid? projectId,
|
||||||
|
[FromBody] XAiConversationDto item,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (item.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Update Required Params ...
|
||||||
|
item.OwnerId = userInfo.UserId;
|
||||||
|
if (!item.IsValidForAddOrUpdate())
|
||||||
|
{
|
||||||
|
XException.InvalidData.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await aiService.CreateConversation(
|
||||||
|
item: item,
|
||||||
|
projectId: projectId,
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -206,11 +206,13 @@ namespace xAiApi.Interfaces
|
|||||||
/// Load Conversations of Specified AI Project ...
|
/// Load Conversations of Specified AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
|
string ownerId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
@@ -219,10 +221,14 @@ namespace xAiApi.Interfaces
|
|||||||
/// Load Messages of Specified Conversation ...
|
/// Load Messages of Specified Conversation ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||||
Guid conversationId,
|
Guid? conversationId,
|
||||||
|
string ownerId = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
@@ -301,7 +307,7 @@ namespace xAiApi.Interfaces
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XAiConversationDto> CreateConversation(
|
Task<XAiConversationDto> CreateConversation(
|
||||||
string ownerId,
|
string ownerId,
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
XAiConversationDto item,
|
XAiConversationDto item,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
|
|||||||
+21
-17
@@ -27,6 +27,7 @@ using System.Collections.Generic;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using xAiApi.Interfaces.Extractors;
|
using xAiApi.Interfaces.Extractors;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using MongoDB.Driver.Core.Connections;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
@@ -836,24 +837,20 @@ namespace xAiApi.Providers
|
|||||||
/// Load Conversations of Specified AI Project ...
|
/// Load Conversations of Specified AI Project ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="projectId"></param>
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
public virtual async Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
|
string ownerId = null,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (projectId.IsDefaultGuid())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await dataProvider.LoadConversations(
|
var result = await dataProvider.LoadConversations(
|
||||||
|
ownerId: ownerId,
|
||||||
fillMessages: false,
|
fillMessages: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
connectionId: connectionId,
|
connectionId: connectionId,
|
||||||
@@ -868,22 +865,21 @@ namespace xAiApi.Providers
|
|||||||
/// Load Messages of Specified Conversation ...
|
/// Load Messages of Specified Conversation ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conversationId"></param>
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
public virtual async Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||||
Guid conversationId,
|
Guid? conversationId,
|
||||||
|
string ownerId = null,
|
||||||
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (conversationId.IsDefaultGuid())
|
|
||||||
{
|
|
||||||
XException.InvalidArgs.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await dataProvider.LoadMessages(
|
var result = await dataProvider.LoadMessages(
|
||||||
|
ownerId: ownerId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
@@ -1076,7 +1072,7 @@ namespace xAiApi.Providers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<XAiConversationDto> CreateConversation(
|
public virtual async Task<XAiConversationDto> CreateConversation(
|
||||||
string ownerId,
|
string ownerId,
|
||||||
Guid projectId,
|
Guid? projectId,
|
||||||
XAiConversationDto item,
|
XAiConversationDto item,
|
||||||
string connectionId = null,
|
string connectionId = null,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
@@ -1691,6 +1687,12 @@ namespace xAiApi.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
var fileContent = await DataContent.LoadFromAsync(stream, mimeType, cancellationToken);
|
var fileContent = await DataContent.LoadFromAsync(stream, mimeType, cancellationToken);
|
||||||
|
if (additionalContents.IsNull())
|
||||||
|
{
|
||||||
|
additionalContents = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
additionalContents = [.. additionalContents, fileContent];
|
additionalContents = [.. additionalContents, fileContent];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1726,6 +1728,8 @@ namespace xAiApi.Providers
|
|||||||
// Retrieve Conversation Message ...
|
// Retrieve Conversation Message ...
|
||||||
var messages = await dataProvider
|
var messages = await dataProvider
|
||||||
.LoadMessages(
|
.LoadMessages(
|
||||||
|
ownerId: userInfo.UserId,
|
||||||
|
connectionId: connectionId,
|
||||||
conversationId: conversationId.Value,
|
conversationId: conversationId.Value,
|
||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
{
|
{
|
||||||
"AllowedOrigins": [
|
"AllowedOrigins": [
|
||||||
|
"http://127.0.0.1:5500",
|
||||||
"http://localhost:5000",
|
"http://localhost:5000",
|
||||||
"https://localhost:5001",
|
"https://localhost:5001",
|
||||||
"http://api.saherelm.ir",
|
"http://api.saherelm.ir",
|
||||||
"https://api.saherelm.ir",
|
"https://api.saherelm.ir",
|
||||||
"http://api.saherelmhub.ir",
|
"http://api.saherelmhub.ir",
|
||||||
|
"http://192.168.11.29:5173",
|
||||||
|
"http://192.168.11.29:5174",
|
||||||
"https://api.saherelmhub.ir"
|
"https://api.saherelmhub.ir"
|
||||||
],
|
],
|
||||||
"IdentityServiceConfiguration": {
|
"IdentityServiceConfiguration": {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"DefaultLanguage": "fa-IR",
|
"DefaultLanguage": "fa-IR",
|
||||||
"XPoweredValue": "SaherElmITCenter",
|
"XPoweredValue": "SaherElmITCenter",
|
||||||
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
||||||
|
"DefaultCacheTtlMinutes": 10,
|
||||||
"AllowedOrigins": [
|
"AllowedOrigins": [
|
||||||
"http://api.saherelm.ir",
|
"http://api.saherelm.ir",
|
||||||
"https://api.saherelm.ir",
|
"https://api.saherelm.ir",
|
||||||
|
|||||||
Reference in New Issue
Block a user