Skip to content

Commit 3c72675

Browse files
committed
Update prompt
1 parent 9b75b43 commit 3c72675

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

Tool/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/ActiveDocumentChatContextCollector.swift

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,28 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
4545
var functions = [any ChatGPTFunction]()
4646

4747
if !isSensitive {
48+
var functionPrompt = """
49+
ONLY call it when one of the following conditions are satisfied:
50+
- the user ask you about specific line from the latest message, \
51+
which is not included in the focused range.
52+
"""
53+
54+
if let annotations = context.focusedContext?.otherLineAnnotations,
55+
!annotations.isEmpty
56+
{
57+
functionPrompt += """
58+
59+
- the user ask about annotations at line \(
60+
Set(annotations.map(\.line)).map(String.init).joined(separator: ",")
61+
).
62+
"""
63+
}
64+
65+
print(functionPrompt)
66+
4867
functions.append(GetCodeCodeAroundLineFunction(
4968
contextCollector: self,
50-
additionalDescription: "You already have the code in focusing range, don't get it again!"
69+
additionalDescription: functionPrompt
5170
))
5271
}
5372

@@ -91,54 +110,54 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
91110
let relativePath = "Document Relative Path: \(context.relativePath)"
92111
let language = "Language: \(context.language.rawValue)"
93112

94-
let focusingContextExplanation =
113+
let focusedContextExplanation =
95114
"Below is the code inside the active document that the user is looking at right now:"
96115

97-
if let focusingContext = context.focusedContext {
98-
let codeContext = focusingContext.context.isEmpty || isSensitive
116+
if let focusedContext = context.focusedContext {
117+
let codeContext = focusedContext.context.isEmpty || isSensitive
99118
? ""
100119
: """
101-
Focusing Context:
120+
Focused Context:
102121
```
103-
\(focusingContext.context.map(\.signature).joined(separator: "\n"))
122+
\(focusedContext.context.map(\.signature).joined(separator: "\n"))
104123
```
105124
"""
106125

107-
let codeRange = "Focusing Range [line, character]: \(focusingContext.codeRange)"
126+
let codeRange = "Focused Range [line, character]: \(focusedContext.codeRange)"
108127

109128
let code = context.selectionRange.isEmpty && isSensitive
110129
? """
111130
The file is in gitignore, you can't read the file.
112131
Ask the user to select the code in the editor to get help. Also tell them the file is in gitignore.
113132
"""
114133
: """
115-
Focusing Code (from line \(
116-
focusingContext.codeRange.start.line + 1
117-
) to line \(focusingContext.codeRange.end.line + 1)):
134+
Focused Code (from line \(
135+
focusedContext.codeRange.start.line + 1
136+
) to line \(focusedContext.codeRange.end.line + 1)):
118137
```\(context.language.rawValue)
119-
\(focusingContext.code)
138+
\(focusedContext.code)
120139
```
121140
"""
122141

123-
let fileAnnotations = focusingContext.otherLineAnnotations.isEmpty || isSensitive
142+
let fileAnnotations = focusedContext.otherLineAnnotations.isEmpty || isSensitive
124143
? ""
125144
: """
126145
Out-of-scope Annotations:\"""
127-
(They are not inside the focusing code. You can get the code at the line for details)
146+
(The related code are not inside the focused code.)
128147
\(
129-
focusingContext.otherLineAnnotations
148+
focusedContext.otherLineAnnotations
130149
.map(convertAnnotationToText)
131150
.joined(separator: "\n")
132151
)
133152
\"""
134153
"""
135154

136-
let codeAnnotations = focusingContext.lineAnnotations.isEmpty || isSensitive
155+
let codeAnnotations = focusedContext.lineAnnotations.isEmpty || isSensitive
137156
? ""
138157
: """
139-
Annotations Inside Focusing Range:\"""
158+
Annotations Inside Focused Range:\"""
140159
\(
141-
focusingContext.lineAnnotations
160+
focusedContext.lineAnnotations
142161
.map(convertAnnotationToText)
143162
.joined(separator: "\n")
144163
)
@@ -149,7 +168,7 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
149168
start,
150169
relativePath,
151170
language,
152-
focusingContextExplanation,
171+
focusedContextExplanation,
153172
codeContext,
154173
codeRange,
155174
code,

Tool/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/Functions/GetCodeCodeAroundLineFunction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct GetCodeCodeAroundLineFunction: ChatGPTFunction {
3232
}
3333

3434
var description: String {
35-
"Get the code at the given line. You must ONLY call it when the user give you a specific line or the user ask about an out of scope annotation. \n\(additionalDescription)"
35+
"Get the code at the given line. \(additionalDescription)"
3636
}
3737

3838
var argumentSchema: JSONSchemaValue { [

0 commit comments

Comments
 (0)