File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Core/Sources/PromptToCodeService Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -163,13 +163,16 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
163163 }
164164 } ( )
165165
166+ let indentation = getCommonLeadingSpaceCount ( code)
167+
166168 let secondMessage = """
167- Requirements:###
168- \( requirement)
169- ###
169+ I will update the code you just provided.
170+ It looks like every line has an indentation of \( indentation) spaces, I will keep that.
171+
172+ What is your requirement?
170173 """
171174
172- let configuration = UserPreferenceChatGPTConfiguration ( )
175+ let configuration = UserPreferenceChatGPTConfiguration ( )
173176 . overriding ( . init( temperature: 0 ) )
174177 let memory = AutoManagedChatGPTMemory (
175178 systemPrompt: systemPrompt,
@@ -255,6 +258,19 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
255258
256259 return ( code, description)
257260 }
261+
262+ func getCommonLeadingSpaceCount( _ code: String ) -> Int {
263+ let lines = code. split ( separator: " \n " )
264+ guard !lines. isEmpty else { return 0 }
265+ var commonCount = Int . max
266+ for line in lines {
267+ let count = line. prefix ( while: { $0 == " " } ) . count
268+ commonCount = min ( commonCount, count)
269+ if commonCount == 0 { break }
270+ }
271+ return commonCount
272+ }
273+
258274 func extractAnnotations(
259275 editorInformation: EditorInformation ,
260276 source: PromptToCodeSource
You can’t perform that action at this time.
0 commit comments