优化LLM提示词

This commit is contained in:
2026-02-28 22:34:51 +08:00
parent 6beb8b5be9
commit 53f1c4902c
9 changed files with 292 additions and 30 deletions

View File

@@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
@@ -21,15 +15,8 @@ using CommunityToolkit.Mvvm.Messaging;
using LangChain.Providers;
using LangChain.Providers.DeepSeek;
using LangChain.Providers.DeepSeek.Predefined;
using LangChain.Providers.OpenAI.Predefined;
using Markdig;
using Markdig.Syntax;
using Markdig.Wpf.ColorCode;
using tryAGI.OpenAI;
//using LangChain.Schema;
//using static LangChain.Chains.Chain;
@@ -142,13 +129,13 @@ public partial class ChatDialogueViewModel : ObservableObject
{
if (ChatHistory.Count == 0)
{
CurrentRequest += Message.Human($"你是专业的Revit二次开发工程师不随意捏造事实能客观地回答用户的问题对于不确定或难以理解的问题需要用户补充说明的需要主动提出。你需要在{GlobalVariables.UIApplication.Application.VersionName}二次开发中使用已定义的uidoc、doc两个变量构造一个可以正确执行的C#代码块保证使用的RevitAPI的所有方法都能在{GlobalVariables.UIApplication.Application.VersionName}版本的API文档中找到在代码中添加关键的注释不需要Excute方法签名和using命名空间使用类声明对象时需要完整的命名空间。需求是{UserInput}");
ChatHistory.Add(CurrentRequest);
var systemPrompt = new PromptManager(Path.Combine(GlobalVariables.DirAssembly, "Templates/SystemPrompt.txt")).GetSystemPrompt();
CurrentRequest += Message.Ai($"{systemPrompt}\n\r注意当前的Revit版本是{GlobalVariables.UIApplication.Application.VersionName}");
ChatHistory.Add(Message.Human($"{UserInput}"));
}
else
{
ChatHistory.Add(Message.Human(UserInput));
CurrentRequest += Message.Human(UserInput);
}

View File

@@ -4,14 +4,13 @@ using System.Windows.Documents;
using ColorCode;
using ColorCode.Styling;
using ColorCode.Wpf;
using Markdig.Parsers;
using Markdig.Renderers;
using Markdig.Renderers.Wpf;
using Markdig.Syntax;
#nullable enable
namespace Markdig.Wpf.ColorCode;
using Markdig.Wpf;
namespace Szmedi.RvKits.RvScript;
public class ColorCodeBlockRenderer : WpfObjectRenderer<CodeBlock>
{
@@ -54,7 +53,7 @@ public class ColorCodeBlockRenderer : WpfObjectRenderer<CodeBlock>
}
var code = ExtractCode(codeBlock);
var formatter = new RichTextBoxFormatter(_styleDictionary);
var formatter = new RvScript.RichTextBoxFormatter(_styleDictionary);
var paragraph = new Paragraph();
paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.CodeBlockStyleKey);
formatter.FormatInlines(code, language, paragraph.Inlines);
@@ -62,7 +61,7 @@ public class ColorCodeBlockRenderer : WpfObjectRenderer<CodeBlock>
renderer.WriteBlock(paragraph);
}
private static ILanguage? ExtractLanguage(IFencedBlock fencedCodeBlock, FencedCodeBlockParser parser)
private static ILanguage ExtractLanguage(IFencedBlock fencedCodeBlock, FencedCodeBlockParser parser)
{
var languageId = fencedCodeBlock.Info!.Replace(parser.InfoPrefix!, string.Empty);

View File

@@ -1,8 +1,10 @@
using ColorCode.Styling;
using Markdig;
using Markdig.Renderers;
using Markdig.Renderers.Wpf;
namespace Markdig.Wpf.ColorCode;
namespace Szmedi.RvKits.RvScript;
public class ColorCodeWpfExtension : IMarkdownExtension
{

View File

@@ -1,6 +1,6 @@
using System.Windows.Media;
namespace ColorCode.Wpf.Common
namespace Szmedi.RvKits.RvScript
{
public static class ExtensionMethods
{

View File

@@ -1,6 +1,8 @@
using ColorCode.Styling;
using Markdig;
#nullable enable
namespace Markdig.Wpf.ColorCode;
namespace Szmedi.RvKits.RvScript;
/// <summary>
/// Extensions for adding ColorCode to the Markdig pipeline.
@@ -17,7 +19,7 @@ public static class MarkdownPipelineBuilderExtension
this MarkdownPipelineBuilder pipeline,
StyleDictionary? styleDictionary = null)
{
pipeline.Extensions.Add(new ColorCodeWpfExtension(styleDictionary ?? StyleDictionary.DefaultLight));
pipeline.Extensions.Add(new RvScript.ColorCodeWpfExtension(styleDictionary ?? StyleDictionary.DefaultLight));
return pipeline;
}

View File

@@ -0,0 +1,22 @@
namespace Szmedi.RvKits.RvScript
{
public class PromptManager
{
private readonly string _systemPrompt;
public PromptManager(string promptPath)
{
_systemPrompt = File.ReadAllText(promptPath);
}
public string GetSystemPrompt()
{
return _systemPrompt;
}
public string BuildUserPrompt(string task)
{
return task.Trim();
}
}
}

View File

@@ -2,12 +2,12 @@
using System.Windows.Controls;
using System.Windows.Documents;
using ColorCode;
using ColorCode.Common;
using ColorCode.Parsing;
using ColorCode.Styling;
using ColorCode.Wpf.Common;
#nullable enable
namespace ColorCode.Wpf
namespace Szmedi.RvKits.RvScript
{
/// <summary>
/// Creates a <see cref="RichTextBoxFormatter"/>, for rendering Syntax Highlighted code to a RichTextBlock.
@@ -108,7 +108,7 @@ namespace ColorCode.Wpf
if (Styles.Contains(scope.Name))
{
Styling.Style style = Styles[scope.Name];
ColorCode.Styling.Style style = Styles[scope.Name];
foreground = style.Foreground;
background = style.Background;