1
- using System . Text . RegularExpressions ;
1
+ using Microsoft . Extensions . Logging ;
2
+ using System . Text . RegularExpressions ;
2
3
using Wolder . Core . Assistants ;
3
4
using Wolder . Core . Files ;
4
5
using Wolder . CSharp . Compilation ;
5
- using Microsoft . Extensions . Logging ;
6
- using Wolder . CommandLine ;
7
- using Wolder . CommandLine . Actions ;
8
6
using Wolder . Core . Workspace ;
9
- using Wolder . CSharp . Actions ;
10
7
11
8
namespace Wolder . CSharp . OpenAI . Actions ;
12
9
@@ -25,6 +22,10 @@ public class GenerateClass(
25
22
GenerateClassParameters parameters )
26
23
: IAction < GenerateClassParameters , FileMemoryItem >
27
24
{
25
+ public const string CSharpPrompt =
26
+ "You are a helpful assistant that writes C# code to complete any task specified by me. " +
27
+ "Your output will be directly written to a file where it will be compiled as part of a " +
28
+ "larger C# project. Nullable references are enabled." ;
28
29
public async Task < FileMemoryItem > InvokeAsync ( )
29
30
{
30
31
var ( project , classNamespace , className , behaviorPrompt ) = parameters ;
@@ -36,12 +37,13 @@ public async Task<FileMemoryItem> InvokeAsync()
36
37
37
38
var tree = sourceFiles . GetDirectoryTree ( ) ;
38
39
var context = $$ """
40
+
39
41
Directory Tree:
40
42
{{ tree }}
41
43
""" ;
42
44
if ( parameters . ContextMemoryItems . Any ( ) )
43
45
{
44
- context = "\n The items may also provide helpful context:\n " +
46
+ context = "\n These items may also provide helpful context:\n " +
45
47
string . Join ( "\n " , parameters . ContextMemoryItems
46
48
. Select ( i => $ "File: { i . RelativePath } \n { i . Content } " ) ) ;
47
49
}
@@ -50,12 +52,13 @@ public async Task<FileMemoryItem> InvokeAsync()
50
52
? ""
51
53
: $ ".{ classNamespace } ";
52
54
var response = await assistant . CompletePromptAsync ( $ """
53
- You are a C# code generator. Output only C#, your output will be directly written to a `.cs` file.
54
- Write terse but helpful explanatory comments.
55
+ { CSharpPrompt }
55
56
{ context }
56
57
57
58
Create a class named `{ className } ` with namespace `{ project . BaseNamespace } { namespaceEnd } ` with the following behavior:
58
59
{ behaviorPrompt }
60
+
61
+ Begin Output:
59
62
""" ) ;
60
63
61
64
var classMemoryItem = await SanitizeAndWriteClassAsync ( response ) ;
@@ -88,14 +91,18 @@ Write terse but helpful explanatory comments.
88
91
var diagnosticMessages = lastResult . Output . Errors ;
89
92
var messagesText = string . Join ( Environment . NewLine , diagnosticMessages ) ;
90
93
var response = await assistant . CompletePromptAsync ( $ """
91
- You are a helpful assistant that writes C# code to complete any task specified by me. Your output will be directly written to a file where it will be compiled as part of a larger C# project.
94
+ { CSharpPrompt }
92
95
{ context }
93
96
94
- Given the following compilation diagnostic messages transform the following file to resolve the messages :
97
+ Given the following errors :
95
98
{ messagesText }
96
99
97
- File Content:
100
+ Transform the following file to resolve the errors:
101
+ ```
98
102
{ lastFile . Content }
103
+ ```
104
+
105
+ Begin Output:
99
106
""" ) ;
100
107
101
108
classMemoryItem = await SanitizeAndWriteClassAsync ( response ) ;
0 commit comments