@@ -33,35 +33,88 @@ final class OpenAIPromptToCodeAPI: PromptToCodeAPI {
3333 }
3434 return userPreferredLanguage. isEmpty ? " " : " in \( userPreferredLanguage) "
3535 } ( )
36+
37+ let rule : String = {
38+ func generateDescription( index: Int ) -> String {
39+ return UserDefaults . shared. value ( for: \. promptToCodeGenerateDescription)
40+ ? """
41+ \( index) . After the code block, write a clear and concise description \
42+ in 1-3 sentences about what you did in step 1 \( textLanguage) .
43+ \( index + 1 ) . Reply with the result.
44+ """
45+ : " \( index) . Reply with the result. "
46+ }
47+ switch language {
48+ case . builtIn( . markdown) , . plaintext:
49+ if code. isEmpty {
50+ return """
51+ 1. Write the content that meets my requirements.
52+ 2. Embed the new content in a markdown code block.
53+ \( generateDescription ( index: 3 ) )
54+ """
55+ } else {
56+ return """
57+ 1. Do what I required.
58+ 2. Format the updated content to use the original indentation. Especially the first line.
59+ 3. Embed the updated content in a markdown code block.
60+ 4. You MUST never translate the content in the code block if it's not requested in the requirements.
61+ \( generateDescription ( index: 5 ) )
62+ """
63+ }
64+ default :
65+ if code. isEmpty {
66+ return """
67+ 1. Write the code that meets my requirements.
68+ 2. Embed the code in a markdown code block.
69+ \( generateDescription ( index: 3 ) )
70+ """
71+ } else {
72+ return """
73+ 1. Do what I required.
74+ 2. Format the updated code to use the original indentation. Especially the first line.
75+ 3. Embed the updated code in a markdown code block.
76+ \( generateDescription ( index: 4 ) )
77+ """
78+ }
79+ }
80+ } ( )
3681
3782 let systemPrompt = {
3883 switch language {
3984 case . builtIn( . markdown) , . plaintext:
4085 if code. isEmpty {
4186 return """
4287 You are good at writing in \( language. rawValue) .
43- You are editing file: \( fileURL. lastPathComponent) .
88+ The active file is : \( fileURL. lastPathComponent) .
4489 \( extraSystemPrompt ?? " " )
90+
91+ \( rule)
4592 """
4693 } else {
4794 return """
4895 You are good at writing in \( language. rawValue) .
49- You are editing file: \( fileURL. lastPathComponent) .
96+ The active file is : \( fileURL. lastPathComponent) .
5097 \( extraSystemPrompt ?? " " )
98+
99+ \( rule)
51100 """
52101 }
53102 default :
54103 if code. isEmpty {
55104 return """
56105 You are a senior programer in writing in \( language. rawValue) .
57- You are editing file: \( fileURL. lastPathComponent) .
106+ The active file is : \( fileURL. lastPathComponent) .
58107 \( extraSystemPrompt ?? " " )
108+
109+ \( rule)
59110 """
60111 } else {
61112 return """
62113 You are a senior programer in writing in \( language. rawValue) .
63- You are editing file: \( fileURL. lastPathComponent) .
114+ The active file is : \( fileURL. lastPathComponent) .
64115 \( extraSystemPrompt ?? " " )
116+
117+ \( rule)
65118 """
66119 }
67120 }
@@ -72,81 +125,24 @@ final class OpenAIPromptToCodeAPI: PromptToCodeAPI {
72125 switch language {
73126 case . builtIn( . markdown) , . plaintext:
74127 return """
75- Content: \" " "
128+ ```
76129 \( code)
77- \" " "
130+ ```
78131 """
79132 default :
80133 return """
81- Code: ```
134+ ```
82135 \( code)
83136 ```
84137 """
85138 }
86139 } ( )
87140
88- let formattedRequirement = requirement. split ( separator: " \n " )
89- . map { " \( $0) " }
90- . joined ( separator: " \n " )
91-
92- let secondMessage : String = {
93- func generateDescription( index: Int ) -> String {
94- return UserDefaults . shared. value ( for: \. promptToCodeGenerateDescription)
95- ? """
96- \( index) . After the code block, write a clear and concise description \
97- in 1-3 sentences about what you did in step 1 \( textLanguage) .
98- \( index + 1 ) . Reply with the result.
99- """
100- : " \( index) . Reply with the result. "
101- }
102- switch language {
103- case . builtIn( . markdown) , . plaintext:
104- if code. isEmpty {
105- return """
106- 1. Write the content that meets my requirements.
107- Requirements: \" " "
108- Write the content;
109- \( formattedRequirement)
110- \" " "
111- 2. Embed the new content in a markdown code block.
112- \( generateDescription ( index: 3 ) )
113- """
114- } else {
115- return """
116- 1. Update the content to meet my requirements.
117- Requirements: \" " "
118- \( formattedRequirement)
119- \" " "
120- 2. Format the updated content to use the original indentation. Especially the first line.
121- 3. Embed the updated content in a markdown code block.
122- \( generateDescription ( index: 4 ) )
123- """
124- }
125- default :
126- if code. isEmpty {
127- return """
128- 1. Write the code that meets my requirements.
129- Requirements: \" " "
130- Write the code in \( language. rawValue) ;
131- \( formattedRequirement)
132- \" " "
133- 2. Embed the code in a markdown code block.
134- \( generateDescription ( index: 3 ) )
135- """
136- } else {
137- return """
138- 1. Update the code to meet my requirements.
139- Requirements: \" " "
140- Update the code;
141- \( formattedRequirement)
142- \" " "
143- 2. Format the updated code to use the original indentation. Especially the first line.
144- 3. Embed the updated code in a markdown code block.
145- \( generateDescription ( index: 4 ) )
146- """
147- }
148- }
149- } ( )
141+ let secondMessage : String = """
142+ Requirements:###
143+ \( requirement)
144+ ###
145+ """
150146
151147 let chatGPTService = ChatGPTService ( systemPrompt: systemPrompt, temperature: 0.3 )
152148 service = chatGPTService
0 commit comments