mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 14:18:00 +00:00
Multiple Profiles can now be selected
This commit is contained in:
1 parent
d043fbc8f0
commit
cefc5464d5
89 files changed
+1360
-503
No files matched your search
+2
-1
@@ -1,4 +1,5 @@
|
||||
namespace AIStudio.Tools.PluginSystem.Assistants;
|
||||
|
||||
/// <param name="ProfileIds">The exact profiles to use, an empty list for none, or null for chat defaults.</param>
|
||||
/// <param name="ToolIds">The tools preselected for the chat, or null when the launcher names none.</param>
|
||||
public sealed record AssistantChatLaunchConfiguration(string WorkspaceName, Guid? ProviderId, Guid? ProfileId, Guid? ChatTemplateId, IReadOnlyList<Guid>? DataSourceIds, IReadOnlyList<string>? ToolIds);
|
||||
public sealed record AssistantChatLaunchConfiguration(string WorkspaceName, Guid? ProviderId, IReadOnlyList<Guid>? ProfileIds, Guid? ChatTemplateId, IReadOnlyList<Guid>? DataSourceIds, IReadOnlyList<string>? ToolIds);
|
||||
+11
-5
@@ -169,14 +169,20 @@ public static class DirectChatLauncherLuaWriter
|
||||
builder.AppendLine($" [\"WorkspaceName\"] = \"{Escape(definition.Launch.WorkspaceName.Trim())}\",");
|
||||
|
||||
//
|
||||
// Omitted IDs mean "use the chat defaults", while an empty GUID explicitly selects no
|
||||
// profile or no chat template. An empty provider GUID has no such meaning and is invalid:
|
||||
// Omitted IDs mean "use the chat defaults", while an empty profile list or chat-template
|
||||
// GUID explicitly selects none. An empty provider GUID has no such meaning and is invalid:
|
||||
//
|
||||
if (definition.Launch.ProviderId is { } providerId && providerId != Guid.Empty)
|
||||
builder.AppendLine($" [\"ProviderId\"] = \"{providerId}\",");
|
||||
|
||||
if (definition.Launch.ProfileId is { } profileId)
|
||||
builder.AppendLine($" [\"ProfileId\"] = \"{profileId}\",");
|
||||
if (definition.Launch.ProfileIds is { } profileIds)
|
||||
{
|
||||
builder.AppendLine(" [\"ProfileIds\"] = {");
|
||||
foreach (var profileId in profileIds)
|
||||
builder.AppendLine($" \"{profileId}\",");
|
||||
|
||||
builder.AppendLine(" },");
|
||||
}
|
||||
|
||||
if (definition.Launch.ChatTemplateId is { } chatTemplateId)
|
||||
builder.AppendLine($" [\"ChatTemplateId\"] = \"{chatTemplateId}\",");
|
||||
@@ -236,4 +242,4 @@ public static class DirectChatLauncherLuaWriter
|
||||
.Replace("\r", "\\r", StringComparison.Ordinal)
|
||||
.Replace("\n", "\\n", StringComparison.Ordinal)
|
||||
.Replace("\t", "\\t", StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Immutable;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
||||
using AIStudio.Tools.PluginSystem.Assistants.DataModel.Layout;
|
||||
using Lua;
|
||||
@@ -241,13 +242,13 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
}
|
||||
|
||||
if (!TryReadOptionalGuid(assistantTable, "ProviderId", false, out var providerId, out message) ||
|
||||
!TryReadOptionalGuid(assistantTable, "ProfileId", true, out var profileId, out message) ||
|
||||
!TryReadOptionalProfileIds(assistantTable, out var profileIds, out message) ||
|
||||
!TryReadOptionalGuid(assistantTable, "ChatTemplateId", true, out var chatTemplateId, out message) ||
|
||||
!TryReadOptionalDataSourceIds(assistantTable, out var dataSourceIds, out message) ||
|
||||
!TryReadOptionalToolIds(assistantTable, out var toolIds, out message))
|
||||
return false;
|
||||
|
||||
this.ChatLaunchConfiguration = new(workspaceName, providerId, profileId, chatTemplateId, dataSourceIds, toolIds);
|
||||
this.ChatLaunchConfiguration = new(workspaceName, providerId, profileIds, chatTemplateId, dataSourceIds, toolIds);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -309,6 +310,56 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryReadOptionalProfileIds(LuaTable assistantTable, out IReadOnlyList<Guid>? profileIds, out string message)
|
||||
{
|
||||
profileIds = null;
|
||||
message = string.Empty;
|
||||
var hasLegacyId = assistantTable.TryGetValue("ProfileId", out _);
|
||||
var hasIds = assistantTable.TryGetValue("ProfileIds", out var profileIdsValue);
|
||||
if (hasLegacyId && hasIds)
|
||||
{
|
||||
message = TB("The ASSISTANT table contains both ProfileId and ProfileIds. Use only one of them.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasLegacyId)
|
||||
{
|
||||
if (!TryReadOptionalGuid(assistantTable, "ProfileId", true, out var profileId, out message))
|
||||
return false;
|
||||
|
||||
profileIds = profileId == Guid.Empty ? [] : profileId is { } id ? [id] : null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!hasIds)
|
||||
return true;
|
||||
|
||||
if (!profileIdsValue.TryRead<LuaTable>(out var profileIdsTable))
|
||||
{
|
||||
message = TB("The ASSISTANT table contains invalid ProfileIds. Expected a list of unique, non-empty GUIDs.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var parsedIds = new List<Guid>(profileIdsTable.ArrayLength);
|
||||
var uniqueIds = new HashSet<Guid>();
|
||||
for (var index = 1; index <= profileIdsTable.ArrayLength; index++)
|
||||
{
|
||||
if (!profileIdsTable[index].TryRead<string>(out var idText) ||
|
||||
!Guid.TryParse(idText, out var parsedId) ||
|
||||
parsedId == Guid.Empty ||
|
||||
!uniqueIds.Add(parsedId))
|
||||
{
|
||||
message = TB("The ASSISTANT table contains invalid ProfileIds. Expected a list of unique, non-empty GUIDs.");
|
||||
return false;
|
||||
}
|
||||
|
||||
parsedIds.Add(parsedId);
|
||||
}
|
||||
|
||||
profileIds = parsedIds.ToImmutableArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the tools an assistant names: the ones a launcher preselects for its chat, or the ones
|
||||
/// the assistant itself runs with.
|
||||
@@ -383,12 +434,14 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
InitializeState(this.RootComponent.Children, assistantState);
|
||||
|
||||
var input = assistantState.ToLuaTable(this.RootComponent?.Children ?? []);
|
||||
input["profiles"] = new LuaTable();
|
||||
input["profile"] = new LuaTable
|
||||
{
|
||||
["Name"] = string.Empty,
|
||||
["NeedToKnow"] = string.Empty,
|
||||
["Actions"] = string.Empty,
|
||||
["Num"] = 0,
|
||||
["Id"] = Profile.NO_PROFILE.Id,
|
||||
["Name"] = Profile.NO_PROFILE.Name,
|
||||
["NeedToKnow"] = Profile.NO_PROFILE.NeedToKnow,
|
||||
["Actions"] = Profile.NO_PROFILE.Actions,
|
||||
["Num"] = Profile.NO_PROFILE.Num,
|
||||
};
|
||||
|
||||
var prompt = await this.TryBuildPromptAsync(input, cancellationToken);
|
||||
|
||||
Reference in new issue
Block a user