Skip to content

Commit 37f16e6

Browse files
committed
Update FIM strategies to use the default post processing strategy
1 parent 4b26f0f commit 37f16e6

4 files changed

Lines changed: 26 additions & 24 deletions

File tree

Core/Sources/SuggestionService/RawSuggestionPostProcessing/DefaultRawSuggestionPostProcessingStrategy.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ extension RawSuggestionPostProcessingStrategy {
1616
}
1717

1818
struct DefaultRawSuggestionPostProcessingStrategy: RawSuggestionPostProcessingStrategy {
19-
let openingCodeTag: String
20-
let closingCodeTag: String
19+
let codeWrappingTags: (opening: String, closing: String)?
2120

2221
func postProcess(rawSuggestion: String, infillPrefix: String, suffix: [String]) -> String {
2322
var suggestion = extractSuggestion(from: rawSuggestion)
@@ -28,13 +27,16 @@ struct DefaultRawSuggestionPostProcessingStrategy: RawSuggestionPostProcessingSt
2827

2928
func extractSuggestion(from response: String) -> String {
3029
let escapedMarkdownCodeBlock = removeLeadingAndTrailingMarkdownCodeBlockMark(from: response)
31-
let escapedTags = extractEnclosingSuggestion(
32-
from: escapedMarkdownCodeBlock,
33-
openingTag: openingCodeTag,
34-
closingTag: closingCodeTag
35-
)
36-
37-
return escapedTags
30+
if let tags = codeWrappingTags {
31+
let escapedTags = extractEnclosingSuggestion(
32+
from: escapedMarkdownCodeBlock,
33+
openingTag: tags.opening,
34+
closingTag: tags.closing
35+
)
36+
return escapedTags
37+
} else {
38+
return escapedMarkdownCodeBlock
39+
}
3840
}
3941

4042
func removePrefix(from suggestion: inout String, infillPrefix: String) {

Core/Sources/SuggestionService/RequestStrategies/CodeLlamaFillInTheMiddleRequestStrategy.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct CodeLlamaFillInTheMiddleRequestStrategy: RequestStrategy {
2020
)
2121
}
2222

23-
func createRawSuggestionPostProcessor() -> NoOpRawSuggestionPostProcessingStrategy {
24-
NoOpRawSuggestionPostProcessingStrategy()
23+
func createRawSuggestionPostProcessor() -> some RawSuggestionPostProcessingStrategy {
24+
DefaultRawSuggestionPostProcessingStrategy(codeWrappingTags: nil)
2525
}
2626

2727
enum Tag {
@@ -93,7 +93,7 @@ struct CodeLlamaFillInTheMiddleWithSystemPromptRequestStrategy: RequestStrategy
9393
}
9494

9595
func createRawSuggestionPostProcessor() -> some RawSuggestionPostProcessingStrategy {
96-
DefaultRawSuggestionPostProcessingStrategy(openingCodeTag: "", closingCodeTag: "")
96+
DefaultRawSuggestionPostProcessingStrategy(codeWrappingTags: nil)
9797
}
9898
}
9999

Core/Sources/SuggestionService/RequestStrategies/ContinueRequestStrategy.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ struct ContinueRequestStrategy: RequestStrategy {
2323
}
2424

2525
func createRawSuggestionPostProcessor() -> DefaultRawSuggestionPostProcessingStrategy {
26-
DefaultRawSuggestionPostProcessingStrategy(
27-
openingCodeTag: Tag.openingCode,
28-
closingCodeTag: Tag.closingCode
29-
)
26+
DefaultRawSuggestionPostProcessingStrategy(codeWrappingTags: (
27+
Tag.openingCode,
28+
Tag.closingCode
29+
))
3030
}
3131

3232
enum Tag {

Core/Sources/SuggestionService/RequestStrategies/DefaultRequestStrategy.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct DefaultRequestStrategy: RequestStrategy {
1010
var sourceRequest: SuggestionRequest
1111
var prefix: [String]
1212
var suffix: [String]
13-
13+
1414
var shouldSkip: Bool {
1515
prefix.last?.trimmingCharacters(in: .whitespaces) == "}"
1616
}
@@ -22,12 +22,12 @@ struct DefaultRequestStrategy: RequestStrategy {
2222
suffix: suffix
2323
)
2424
}
25-
25+
2626
func createRawSuggestionPostProcessor() -> DefaultRawSuggestionPostProcessingStrategy {
27-
DefaultRawSuggestionPostProcessingStrategy(
28-
openingCodeTag: Tag.openingCode,
29-
closingCodeTag: Tag.closingCode
30-
)
27+
DefaultRawSuggestionPostProcessingStrategy(codeWrappingTags: (
28+
Tag.openingCode,
29+
Tag.closingCode
30+
))
3131
}
3232

3333
enum Tag {
@@ -65,7 +65,7 @@ struct DefaultRequestStrategy: RequestStrategy {
6565
var relevantCodeSnippets: [RelevantCodeSnippet] { sourceRequest.relevantCodeSnippets }
6666
var stopWords: [String] { [Tag.closingCode, "\n\n"] }
6767
var language: CodeLanguage? { sourceRequest.language }
68-
68+
6969
var suggestionPrefix: SuggestionPrefix {
7070
guard let prefix = prefix.last else { return .empty }
7171
return .unchanged(prefix).curlyBracesLineBreak()
@@ -103,7 +103,7 @@ struct DefaultRequestStrategy: RequestStrategy {
103103
File Path: \(filePath)
104104
Indentation: \
105105
\(sourceRequest.indentSize) \(sourceRequest.usesTabsForIndentation ? "tab" : "space")
106-
106+
107107
---
108108
109109
Here is the code:

0 commit comments

Comments
 (0)