@@ -31,20 +31,13 @@ struct CodeLlamaFillInTheMiddleRequestStrategy: RequestStrategy {
3131 }
3232
3333 struct Prompt : PromptStrategy {
34- let systemPrompt : String = """
35- You are a senior programer who take the surrounding code and \
36- references from the codebase into account in order to write high-quality code to \
37- complete the code enclosed in the given code. \
38- You only respond with code that works and fits seamlessly with surrounding code. \
39- Don't include anything else beyond the code. \
40- The prefix will follow the PRE tag and the suffix will follow the SUF tag.
41- """
34+ fileprivate( set) var systemPrompt : String = " "
4235 var sourceRequest : SuggestionRequest
4336 var prefix : [ String ]
4437 var suffix : [ String ]
4538 var filePath : String { sourceRequest. relativePath ?? sourceRequest. fileURL. path }
4639 var relevantCodeSnippets : [ RelevantCodeSnippet ] { sourceRequest. relevantCodeSnippets }
47- var stopWords : [ String ] { [ " \n \n " ] }
40+ var stopWords : [ String ] { [ " \n \n " , " <EOT> " ] }
4841 var language : CodeLanguage ? { sourceRequest. language }
4942
5043 var suggestionPrefix : SuggestionPrefix {
@@ -57,6 +50,7 @@ struct CodeLlamaFillInTheMiddleRequestStrategy: RequestStrategy {
5750 truncatedSuffix: [ String ] ,
5851 includedSnippets: [ RelevantCodeSnippet ]
5952 ) -> [ PromptMessage ] {
53+ let suffix = truncatedSuffix. joined ( )
6054 return [
6155 . init(
6256 role: . user,
@@ -67,7 +61,7 @@ struct CodeLlamaFillInTheMiddleRequestStrategy: RequestStrategy {
6761 \( sourceRequest. usesTabsForIndentation ? " tab " : " space " )
6862 \( includedSnippets. map ( \. content) . joined ( separator: " \n \n " ) )
6963 \( truncatedPrefix. joined ( ) ) \
70- \( Tag . suffix) \( truncatedSuffix . joined ( ) ) \
64+ \( Tag . suffix) \( suffix . isEmpty ? " \n // End of file " : suffix ) \
7165 \( Tag . middle)
7266 """ . trimmingCharacters ( in: . whitespacesAndNewlines)
7367 ) ,
@@ -76,3 +70,30 @@ struct CodeLlamaFillInTheMiddleRequestStrategy: RequestStrategy {
7670 }
7771}
7872
73+ struct CodeLlamaFillInTheMiddleWithSystemPromptRequestStrategy : RequestStrategy {
74+ let strategy : CodeLlamaFillInTheMiddleRequestStrategy
75+
76+ init ( sourceRequest: SuggestionRequest , prefix: [ String ] , suffix: [ String ] ) {
77+ strategy = . init( sourceRequest: sourceRequest, prefix: prefix, suffix: suffix)
78+ }
79+
80+ func createPrompt( ) -> some PromptStrategy {
81+ var prompt = strategy. createPrompt ( )
82+ prompt. systemPrompt = """
83+ You are a senior programer who take the surrounding code and \
84+ references from the codebase into account in order to write high-quality code to \
85+ complete the code enclosed in the given code. \
86+ You only respond with code that works and fits seamlessly with surrounding code. \
87+ Don't include anything else beyond the code. \
88+ The prefix will follow the PRE tag and the suffix will follow the SUF tag. \
89+ You should write the code that fits seamlessly after the MID tag.
90+ """ . trimmingCharacters ( in: . whitespacesAndNewlines)
91+
92+ return prompt
93+ }
94+
95+ func createRawSuggestionPostProcessor( ) -> some RawSuggestionPostProcessingStrategy {
96+ strategy. createRawSuggestionPostProcessor ( )
97+ }
98+ }
99+
0 commit comments