mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-11 20:52:11 +00:00
Fixed chat thread conversion
This commit is contained in:
parent
b4ed1a0f7d
commit
59aee9ecfb
@ -41,6 +41,55 @@ public partial class AssistantCoding : AssistantBaseCore<SettingsDialogCoding>
|
|||||||
|
|
||||||
protected override string SendToChatVisibleUserPromptContent => this.questions;
|
protected override string SendToChatVisibleUserPromptContent => this.questions;
|
||||||
|
|
||||||
|
protected override ChatThread ConvertToChatThread
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var originalChatThread = this.ChatThread ?? new ChatThread();
|
||||||
|
if (string.IsNullOrWhiteSpace(this.SendToChatVisibleUserPromptText))
|
||||||
|
{
|
||||||
|
return originalChatThread with
|
||||||
|
{
|
||||||
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var earliestBlock = originalChatThread.Blocks.MinBy(x => x.Time);
|
||||||
|
var visiblePromptTime = earliestBlock is null
|
||||||
|
? DateTimeOffset.Now
|
||||||
|
: earliestBlock.Time == DateTimeOffset.MinValue
|
||||||
|
? earliestBlock.Time
|
||||||
|
: earliestBlock.Time.AddTicks(-1);
|
||||||
|
|
||||||
|
var transferredBlocks = originalChatThread.Blocks
|
||||||
|
.Select(block => block.Role is ChatRole.USER
|
||||||
|
? this.CloneHiddenUserBlockWithoutAttachments(block)
|
||||||
|
: block.DeepClone())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
transferredBlocks.Insert(0, new ContentBlock
|
||||||
|
{
|
||||||
|
Time = visiblePromptTime,
|
||||||
|
ContentType = ContentType.TEXT,
|
||||||
|
HideFromUser = false,
|
||||||
|
Role = ChatRole.USER,
|
||||||
|
Content = new ContentText
|
||||||
|
{
|
||||||
|
Text = this.BuildVisibleChatPrompt(),
|
||||||
|
FileAttachments = this.loadedDocumentPaths.ToList(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return originalChatThread with
|
||||||
|
{
|
||||||
|
ChatId = Guid.NewGuid(),
|
||||||
|
Name = T("Coding Assistant Session"),
|
||||||
|
SystemPrompt = SystemPrompts.DEFAULT,
|
||||||
|
Blocks = transferredBlocks,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ResetForm()
|
protected override void ResetForm()
|
||||||
{
|
{
|
||||||
this.loadedDocumentPaths.Clear();
|
this.loadedDocumentPaths.Clear();
|
||||||
@ -122,6 +171,32 @@ public partial class AssistantCoding : AssistantBaseCore<SettingsDialogCoding>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ContentBlock CloneHiddenUserBlockWithoutAttachments(ContentBlock block)
|
||||||
|
{
|
||||||
|
var clone = block.DeepClone(changeHideState: true);
|
||||||
|
if (clone.Content is ContentText text)
|
||||||
|
text.FileAttachments = [];
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildVisibleChatPrompt()
|
||||||
|
{
|
||||||
|
if (!this.provideCompilerMessages)
|
||||||
|
return this.SendToChatVisibleUserPromptText ?? string.Empty;
|
||||||
|
|
||||||
|
return $"""
|
||||||
|
I have the following compiler messages:
|
||||||
|
|
||||||
|
```
|
||||||
|
{this.compilerMessages}
|
||||||
|
```
|
||||||
|
|
||||||
|
My questions are:
|
||||||
|
{this.questions}
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
private async Task GetSupport()
|
private async Task GetSupport()
|
||||||
{
|
{
|
||||||
await this.Form!.Validate();
|
await this.Form!.Validate();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user