mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 19:11:38 +00:00
added a file content reader as a component for the assistant builder
This commit is contained in:
parent
6841a357cc
commit
4f6bdec82b
@ -25,6 +25,12 @@
|
||||
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent" />
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.FILE_CONTENT_READER:
|
||||
if (component is AssistantFileContentReader fileContent && this.fileContentFields.TryGetValue(fileContent.Name, out var fileState))
|
||||
{
|
||||
<ReadFileContent @bind-FileContent="@fileState.Content" />
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantUiCompontentType.DROPDOWN:
|
||||
if (component is AssistantDropdown assistantDropdown)
|
||||
|
||||
@ -35,6 +35,7 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
private Dictionary<string, string> dropdownFields = new();
|
||||
private Dictionary<string, bool> switchFields = new();
|
||||
private Dictionary<string, WebContentState> webContentFields = new();
|
||||
private Dictionary<string, FileContentState> fileContentFields = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@ -83,6 +84,12 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
});
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.FILE_CONTENT_READER:
|
||||
if (component is AssistantFileContentReader fileContent)
|
||||
{
|
||||
this.fileContentFields.Add(fileContent.Name, new FileContentState());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
base.OnInitialized();
|
||||
@ -99,6 +106,10 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
entry.Value.Content = string.Empty;
|
||||
entry.Value.AgentIsRunning = false;
|
||||
}
|
||||
foreach (var entry in this.fileContentFields)
|
||||
{
|
||||
entry.Value.Content = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
@ -164,6 +175,21 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.FILE_CONTENT_READER:
|
||||
if (component is AssistantFileContentReader fileContent &&
|
||||
this.fileContentFields.TryGetValue(fileContent.Name, out var fileState))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(fileContent.UserPrompt))
|
||||
{
|
||||
prompt += $"{Environment.NewLine}context:{Environment.NewLine}{fileContent.UserPrompt}{Environment.NewLine}---{Environment.NewLine}";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(fileState.Content))
|
||||
{
|
||||
prompt += $"user prompt:{Environment.NewLine}{fileState.Content}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
prompt += $"{userInput}{Environment.NewLine}";
|
||||
break;
|
||||
@ -192,4 +218,5 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
var time = this.AddUserRequest(this.CollectUserPrompt());
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
namespace AIStudio.Assistants.Dynamic;
|
||||
|
||||
internal sealed class FileContentState
|
||||
{
|
||||
public string Content { get; set; } = string.Empty;
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
namespace AIStudio.Assistants.Dynamic;
|
||||
namespace AIStudio.Assistants.Dynamic;
|
||||
|
||||
public sealed class WebContentState
|
||||
internal sealed class WebContentState
|
||||
{
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public bool Preselect { get; set; }
|
||||
|
||||
@ -151,6 +151,13 @@ ASSISTANT = {
|
||||
["PreselectContentCleanerAgent"] = true -- run the content cleaner by default
|
||||
}
|
||||
},
|
||||
{
|
||||
["Type"] = "FILE_CONTENT_READER", -- allows the user to load local files
|
||||
["Props"] = {
|
||||
["Name"] = "<unique identifier of this component>", -- required
|
||||
["UserPrompt"] = "<help text reminding the user what kind of file they should load>"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@ public class AssistantComponentFactory
|
||||
return new AssistantList { Props = props, Children = children };
|
||||
case AssistantUiCompontentType.WEB_CONTENT_READER:
|
||||
return new AssistantWebContentReader { Props = props, Children = children };
|
||||
case AssistantUiCompontentType.FILE_CONTENT_READER:
|
||||
return new AssistantFileContentReader { Props = props, Children = children };
|
||||
default:
|
||||
LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type");
|
||||
throw new Exception($"Unknown assistant component type: {type}");
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
||||
|
||||
public class AssistantFileContentReader : AssistantComponentBase
|
||||
{
|
||||
public override AssistantUiCompontentType Type => AssistantUiCompontentType.FILE_CONTENT_READER;
|
||||
public Dictionary<string, object> Props { get; set; } = new();
|
||||
public List<IAssistantComponent> Children { get; set; } = new();
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.Name), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.Name)] = value;
|
||||
}
|
||||
|
||||
public string UserPrompt
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.UserPrompt), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.UserPrompt)] = value;
|
||||
}
|
||||
}
|
||||
@ -13,4 +13,5 @@ public enum AssistantUiCompontentType
|
||||
TEXT,
|
||||
LIST,
|
||||
WEB_CONTENT_READER,
|
||||
FILE_CONTENT_READER,
|
||||
}
|
||||
|
||||
@ -49,5 +49,9 @@ public static class ComponentPropSpecs
|
||||
required: ["Name"],
|
||||
optional: ["UserPrompt", "Preselect", "PreselectContentCleanerAgent"]
|
||||
),
|
||||
[AssistantUiCompontentType.FILE_CONTENT_READER] = new(
|
||||
required: ["Name"],
|
||||
optional: ["UserPrompt"]
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user