Compare commits
13
Commits
16fb715926
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a228439a5 | ||
|
|
13cd0745c6 | ||
|
|
5bccce3475 | ||
|
|
cddf2650f5 | ||
|
|
fba69b274c | ||
|
|
0077008105 | ||
|
|
3dc54332c2 | ||
|
|
dab384ea37 | ||
|
|
f6a916fa83 | ||
|
|
5656ec07d5 | ||
|
|
c24c14eb74 | ||
|
|
b58f1dd736 | ||
|
|
31add513bc |
@@ -1,6 +1,7 @@
|
||||
#
|
||||
bin/*
|
||||
obj/*
|
||||
Logs
|
||||
|
||||
#
|
||||
Db/*
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace xAiApi.Constants
|
||||
public const string XAiApiContentExtractionPromptName = "ContentExtraction";
|
||||
|
||||
//
|
||||
public const string XAiDefaultModelName = "Gemma";
|
||||
public const string XAiDefaultModelName = "Arion";
|
||||
public const string XAiEmbeddingModelName = "Embed";
|
||||
public const string XAiDefaultVisionModelName = "Qwen";
|
||||
public const string XAiDefaultThinkingModelName = "Qwen";
|
||||
|
||||
@@ -536,6 +536,8 @@ namespace xAiApi.Controllers
|
||||
prompt: request.Prompt,
|
||||
minScore: request.MinScore,
|
||||
connectionId: connectionId,
|
||||
extractFileContents: false,
|
||||
addFilesToKnowledge: false,
|
||||
projectId: request.ProjectId,
|
||||
cancellationToken: cancellationToken,
|
||||
conversationId: request.ConversationId
|
||||
@@ -634,7 +636,7 @@ namespace xAiApi.Controllers
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
[HttpGet("Projects/{projectId}/Conversations")]
|
||||
public async Task<ActionResult<IEnumerable<XAiConversationDto>>> LoadConversations(
|
||||
[FromRoute] Guid projectId,
|
||||
[FromRoute] Guid? projectId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -642,12 +644,44 @@ namespace xAiApi.Controllers
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (projectId.IsDefaultGuid())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await aiService.LoadConversations(
|
||||
projectId: projectId,
|
||||
ownerId: userInfo.UserId,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
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 connectionId = GetConnectionId();
|
||||
@@ -655,6 +689,7 @@ namespace xAiApi.Controllers
|
||||
//
|
||||
var result = await aiService.LoadConversations(
|
||||
projectId: projectId,
|
||||
ownerId: userInfo.UserId,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -679,7 +714,7 @@ namespace xAiApi.Controllers
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
[HttpGet("Conversations/{conversationId}/Messages")]
|
||||
public async Task<ActionResult<IEnumerable<XAiMessageDto>>> LoadMessages(
|
||||
[FromRoute] Guid conversationId,
|
||||
[FromRoute] Guid? conversationId,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
@@ -687,14 +722,52 @@ namespace xAiApi.Controllers
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (conversationId.IsDefaultGuid())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
var userInfo = await GetUserInfo();
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
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,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -949,6 +1022,63 @@ namespace xAiApi.Controllers
|
||||
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
|
||||
|
||||
//
|
||||
|
||||
@@ -132,6 +132,8 @@ namespace xAiApi.Interfaces
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="extractFileContents"></param>
|
||||
/// <param name="addFilesToKnowledge"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
@@ -144,6 +146,8 @@ namespace xAiApi.Interfaces
|
||||
Guid? projectId = null,
|
||||
Guid? conversationId = null,
|
||||
string connectionId = null,
|
||||
bool extractFileContents = false,
|
||||
bool addFilesToKnowledge = true,
|
||||
IFormFileCollection files = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -159,6 +163,8 @@ namespace xAiApi.Interfaces
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="extractFileContents"></param>
|
||||
/// <param name="addFilesToKnowledge"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
@@ -171,6 +177,8 @@ namespace xAiApi.Interfaces
|
||||
Guid? projectId = null,
|
||||
Guid? conversationId = null,
|
||||
string connectionId = null,
|
||||
bool extractFileContents = false,
|
||||
bool addFilesToKnowledge = true,
|
||||
IFormFileCollection files = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -198,11 +206,13 @@ namespace xAiApi.Interfaces
|
||||
/// Load Conversations of Specified AI Project ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string ownerId = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
@@ -211,10 +221,14 @@ namespace xAiApi.Interfaces
|
||||
/// Load Messages of Specified Conversation ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||
Guid conversationId,
|
||||
Guid? conversationId,
|
||||
string ownerId = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
@@ -293,7 +307,7 @@ namespace xAiApi.Interfaces
|
||||
/// <returns></returns>
|
||||
Task<XAiConversationDto> CreateConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
XAiConversationDto item,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
|
||||
+5
-1
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using xLoggingService.DI;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
@@ -19,10 +20,13 @@ namespace xAiApi
|
||||
{
|
||||
//
|
||||
var result = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureLogging(logging =>
|
||||
logging.AddXTelemetryLogger())
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
})
|
||||
.AddXTelemetry();
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"applicationUrl": "https://localhost:6001;http://localhost:6000",
|
||||
"applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
||||
+104
-27
@@ -27,6 +27,7 @@ using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiApi.Interfaces.Extractors;
|
||||
using System.Runtime.CompilerServices;
|
||||
using MongoDB.Driver.Core.Connections;
|
||||
|
||||
namespace xAiApi.Providers
|
||||
{
|
||||
@@ -129,7 +130,7 @@ namespace xAiApi.Providers
|
||||
);
|
||||
|
||||
//
|
||||
Options.Tools = [.. availableTools.Cast<AITool>()];
|
||||
Options.Tools = [.. availableTools];
|
||||
}
|
||||
|
||||
//
|
||||
@@ -389,7 +390,10 @@ namespace xAiApi.Providers
|
||||
connectionId: null,
|
||||
conversationId: null,
|
||||
persistPrompt: false,
|
||||
additionalContents: null,
|
||||
addFilesToKnowledge: false,
|
||||
resolveConversation: false,
|
||||
extractFileContents: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -470,7 +474,10 @@ namespace xAiApi.Providers
|
||||
connectionId: null,
|
||||
conversationId: null,
|
||||
persistPrompt: false,
|
||||
additionalContents: null,
|
||||
resolveConversation: false,
|
||||
addFilesToKnowledge: false,
|
||||
extractFileContents: false,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
@@ -522,6 +529,8 @@ namespace xAiApi.Providers
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="extractFileContents"></param>
|
||||
/// <param name="addFilesToKnowledge"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
@@ -534,6 +543,8 @@ namespace xAiApi.Providers
|
||||
Guid? projectId = null,
|
||||
Guid? conversationId = null,
|
||||
string connectionId = null,
|
||||
bool extractFileContents = false,
|
||||
bool addFilesToKnowledge = true,
|
||||
IFormFileCollection files = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -558,10 +569,13 @@ namespace xAiApi.Providers
|
||||
userInfo: userInfo,
|
||||
persistPrompt: true,
|
||||
projectId: projectId,
|
||||
additionalContents: null,
|
||||
resolveConversation: true,
|
||||
connectionId: connectionId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
extractFileContents: extractFileContents,
|
||||
addFilesToKnowledge: addFilesToKnowledge
|
||||
);
|
||||
|
||||
//
|
||||
@@ -625,6 +639,8 @@ namespace xAiApi.Providers
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="extractFileContents"></param>
|
||||
/// <param name="addFilesToKnowledge"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
@@ -637,6 +653,8 @@ namespace xAiApi.Providers
|
||||
Guid? projectId = null,
|
||||
Guid? conversationId = null,
|
||||
string connectionId = null,
|
||||
bool extractFileContents = false,
|
||||
bool addFilesToKnowledge = true,
|
||||
IFormFileCollection files = null,
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
[EnumeratorCancellation]
|
||||
@@ -662,10 +680,13 @@ namespace xAiApi.Providers
|
||||
userInfo: userInfo,
|
||||
persistPrompt: true,
|
||||
projectId: projectId,
|
||||
additionalContents: null,
|
||||
resolveConversation: true,
|
||||
connectionId: connectionId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
cancellationToken: cancellationToken,
|
||||
extractFileContents: extractFileContents,
|
||||
addFilesToKnowledge: addFilesToKnowledge
|
||||
);
|
||||
|
||||
//
|
||||
@@ -816,24 +837,20 @@ namespace xAiApi.Providers
|
||||
/// Load Conversations of Specified AI Project ...
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> LoadConversations(
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
string ownerId = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (projectId.IsDefaultGuid())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await dataProvider.LoadConversations(
|
||||
ownerId: ownerId,
|
||||
fillMessages: false,
|
||||
projectId: projectId,
|
||||
connectionId: connectionId,
|
||||
@@ -848,22 +865,21 @@ namespace xAiApi.Providers
|
||||
/// Load Messages of Specified Conversation ...
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="ownerId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiMessageDto>> LoadMessages(
|
||||
Guid conversationId,
|
||||
Guid? conversationId,
|
||||
string ownerId = null,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (conversationId.IsDefaultGuid())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await dataProvider.LoadMessages(
|
||||
ownerId: ownerId,
|
||||
connectionId: connectionId,
|
||||
conversationId: conversationId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
@@ -1056,7 +1072,7 @@ namespace xAiApi.Providers
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> CreateConversation(
|
||||
string ownerId,
|
||||
Guid projectId,
|
||||
Guid? projectId,
|
||||
XAiConversationDto item,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
@@ -1339,7 +1355,7 @@ namespace xAiApi.Providers
|
||||
if (!datetimeContext.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
systemText +=
|
||||
systemText +=
|
||||
$"{datetimeContext}{Environment.NewLine}{Environment.NewLine}";
|
||||
}
|
||||
|
||||
@@ -1465,17 +1481,20 @@ namespace xAiApi.Providers
|
||||
/// <summary>
|
||||
/// Retrieve Prepared Chat Context ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="topK"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="minScore"></param>
|
||||
/// <param name="projectId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="persistPrompt"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <param name="resolveConversation"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="resolveConversation"></param>
|
||||
/// <param name="persistPrompt"></param>
|
||||
/// <param name="extractFileContents"></param>
|
||||
/// <param name="addFilesToKnowledge"></param>
|
||||
/// <param name="additionalContents"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<XPreparedChatContext> PrepareChatRequirementsAsync(
|
||||
@@ -1490,6 +1509,8 @@ namespace xAiApi.Providers
|
||||
bool resolveConversation,
|
||||
IFormFileCollection files,
|
||||
XUserClaimsInfoDto userInfo,
|
||||
bool extractFileContents = true,
|
||||
bool addFilesToKnowledge = false,
|
||||
IList<AIContent> additionalContents = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
@@ -1580,7 +1601,8 @@ namespace xAiApi.Providers
|
||||
// Ingest Files if Provided and also Resolve Conversation Flagged ...
|
||||
if (
|
||||
files.HasChild() &&
|
||||
resolveConversation
|
||||
resolveConversation &&
|
||||
addFilesToKnowledge
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1623,6 +1645,59 @@ namespace xAiApi.Providers
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If there isn't Files need to add Files to Knowledge ...
|
||||
if (files.HasChild() &&
|
||||
!addFilesToKnowledge
|
||||
)
|
||||
{
|
||||
//
|
||||
// Extract File Content and add them to Additional Contents ...
|
||||
foreach (var file in files)
|
||||
{
|
||||
//
|
||||
var mimeType = file.ContentType?.ToLowerInvariant() ?? string.Empty;
|
||||
if (mimeType.IsNullOrEmpty() ||
|
||||
!fileContentExtractor.CanExtract(mimeType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
using var stream = file.OpenReadStream();
|
||||
|
||||
//
|
||||
// Extract File Content if necessary ...
|
||||
if (extractFileContents)
|
||||
{
|
||||
//
|
||||
var content = await fileContentExtractor.ExtractAsync(
|
||||
fileStream: stream,
|
||||
mimeType: mimeType,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!content.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
var fileContent = new TextContent($"File:{Environment.NewLine}{file.FileName}{Environment.NewLine}{content}");
|
||||
additionalContents = [.. additionalContents, fileContent];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
var fileContent = await DataContent.LoadFromAsync(stream, mimeType, cancellationToken);
|
||||
if (additionalContents.IsNull())
|
||||
{
|
||||
additionalContents = [];
|
||||
}
|
||||
|
||||
//
|
||||
additionalContents = [.. additionalContents, fileContent];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Request Knowledge ...
|
||||
var knowledgeRequest = new XAiKnowledgeAskRequest
|
||||
@@ -1653,6 +1728,8 @@ namespace xAiApi.Providers
|
||||
// Retrieve Conversation Message ...
|
||||
var messages = await dataProvider
|
||||
.LoadMessages(
|
||||
ownerId: userInfo.UserId,
|
||||
connectionId: connectionId,
|
||||
conversationId: conversationId.Value,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
+25
-3
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using xAiApi.DI;
|
||||
using System.Linq;
|
||||
using xAiModels.DI;
|
||||
using xAiService.DI;
|
||||
using xTagService.DI;
|
||||
using System.Net.Http;
|
||||
using xAiApi.Database;
|
||||
@@ -14,6 +15,7 @@ using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using xAiApi.Extensions;
|
||||
using xStringService.DI;
|
||||
using xLoggingService.DI;
|
||||
using xStorageService.DI;
|
||||
using xIdentityService.DI;
|
||||
using xDataService.Models;
|
||||
@@ -29,7 +31,6 @@ using Newtonsoft.Json.Serialization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
using xAiService.DI;
|
||||
|
||||
namespace xAiApi
|
||||
{
|
||||
@@ -70,6 +71,10 @@ namespace xAiApi
|
||||
services.AddXAppConfiguration(Configuration);
|
||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
//
|
||||
// Register Logging Service ...
|
||||
services.AddXLoggingService(Configuration);
|
||||
|
||||
//
|
||||
// Register Allowed Origins ...
|
||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
||||
@@ -192,7 +197,7 @@ namespace xAiApi
|
||||
//
|
||||
// Register File Content Extractor Services ...
|
||||
services.AddXAiFileContentExtractors();
|
||||
|
||||
|
||||
//
|
||||
// Register Text Chunker Service ...
|
||||
services.AddXAiTextChunker();
|
||||
@@ -214,7 +219,10 @@ namespace xAiApi
|
||||
services.AddXAiServices();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IWebHostEnvironment env
|
||||
)
|
||||
{
|
||||
//
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -231,6 +239,10 @@ namespace xAiApi
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Environment in App Confiuration ...
|
||||
app.AddEnvironmentToXAppConfiguration(env.EnvironmentName);
|
||||
|
||||
//
|
||||
// Force Https Redirection ...
|
||||
app.UseHttpsRedirection();
|
||||
@@ -259,6 +271,13 @@ namespace xAiApi
|
||||
// Using Routing ...
|
||||
app.UseRouting();
|
||||
|
||||
//
|
||||
// Using Request Logging ...
|
||||
if (!isDevelopmentEnvironment)
|
||||
{
|
||||
app.UseXRequestLogger();
|
||||
}
|
||||
|
||||
//
|
||||
// Use xIdentityService (Authentication) ...
|
||||
app.UseXIdentityService();
|
||||
@@ -315,3 +334,6 @@ namespace xAiApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
{
|
||||
"AllowedOrigins": [
|
||||
"http://127.0.0.1:5500",
|
||||
"http://localhost:5000",
|
||||
"https://localhost:5001",
|
||||
"http://api.saherelm.ir",
|
||||
"https://api.saherelm.ir",
|
||||
"http://api.saherelmhub.ir",
|
||||
"http://192.168.11.29:5173",
|
||||
"http://192.168.11.29:5174",
|
||||
"https://api.saherelmhub.ir"
|
||||
],
|
||||
"IdentityServiceConfiguration": {
|
||||
@@ -37,9 +40,16 @@
|
||||
},
|
||||
"AiApiConfiguration": {
|
||||
"Models": [
|
||||
{
|
||||
"Name": "Arion",
|
||||
"Provider": "OpenAI",
|
||||
"LLM": "claude-fable-5-1",
|
||||
"Url": "https://arionhub.pro/v1",
|
||||
"ApiKey": "sk-AKJGD8J9gOCrQgc5oWPGtRGUo25PnnQGnMoipzdliYHa3otZ"
|
||||
},
|
||||
{
|
||||
"ApiKey": "",
|
||||
"Name": "Gemma",
|
||||
"Name": "Gemma_BKP",
|
||||
"LLM": "gemma3:1b",
|
||||
"Provider": "OpenAI",
|
||||
"Url": "http://178.131.88.93:1112/v1"
|
||||
|
||||
+34
-2
@@ -4,6 +4,7 @@
|
||||
"DefaultLanguage": "fa-IR",
|
||||
"XPoweredValue": "SaherElmITCenter",
|
||||
"WelcomeMessage": "Welcome to xSaherElm Project's AI API",
|
||||
"DefaultCacheTtlMinutes": 10,
|
||||
"AllowedOrigins": [
|
||||
"http://api.saherelm.ir",
|
||||
"https://api.saherelm.ir",
|
||||
@@ -22,7 +23,6 @@
|
||||
"DefaultValues": {
|
||||
"version": "1.0"
|
||||
}
|
||||
|
||||
},
|
||||
"HttpServiceConfiguration": {
|
||||
"DisableSSLCheck": true,
|
||||
@@ -52,6 +52,38 @@
|
||||
"BaseRoute": "hubs",
|
||||
"AddSupportMessageProtocol": true
|
||||
},
|
||||
"LoggingServiceConfiguration": {
|
||||
"Enabled": true,
|
||||
"MinimumLevel": "Information",
|
||||
"Queue": {
|
||||
"Enabled": true,
|
||||
"Capacity": 10000,
|
||||
"ShutdownTimeoutSeconds": 10
|
||||
},
|
||||
"File": {
|
||||
"Enabled": true,
|
||||
"Directory": "./Logs",
|
||||
"FileName": "xAiApi-.log",
|
||||
"Format": "Json",
|
||||
"MinimumLevel": "Information",
|
||||
"RetainedFileCountLimit": 30
|
||||
},
|
||||
"Database": {
|
||||
"Enabled": false,
|
||||
"TableName": "XLogs",
|
||||
"AutoCreateTable": true,
|
||||
"MinimumLevel": "Warning",
|
||||
"Provider": "Microsoft.Data.Sqlite",
|
||||
"ConnectionString": "Filename=./Db/XLogs.db"
|
||||
},
|
||||
"Event": {
|
||||
"Enabled": false,
|
||||
"Sender": "xAiApi",
|
||||
"MinimumLevel": "Error",
|
||||
"Topic": "application-logs",
|
||||
"Action": "ApplicationLogCreated"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
@@ -59,4 +91,4 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -17,8 +17,8 @@
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
|
||||
<!-- Fix Duplicate TargetFramework Issue -->
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Icon Handling -->
|
||||
@@ -40,6 +40,7 @@
|
||||
<ProjectReference Include="../Modules/xHttpService/xHttpService.csproj" />
|
||||
<ProjectReference Include="../Modules/xFileService/xFileService.csproj" />
|
||||
<ProjectReference Include="../Modules/xStorageService/xStorageService.csproj" />
|
||||
<ProjectReference Include="..\Modules\xLoggingService\xLoggingService.csproj" />
|
||||
<ProjectReference Include="../Modules/xIdentityHelper/xIdentityHelper.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user