ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / prompts / node / inline / inlineChatNotebookGeneratePrompt.tsx 319 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import { BasePromptElementProps , PromptElement , PromptSizing , SystemMessage , UserMessage } from '@vscode/prompt-tsx' ;
import type * as vscode from 'vscode' ;
import { ConfigKey , IConfigurationService } from '../../../../platform/configuration/common/configurationService' ;
import { IIgnoreService } from '../../../../platform/ignore/common/ignoreService' ;
import { INotebookService } from
props
@ ignoreService
@ parserService
@ experimentationService
props
override sizing
documentContext context
isIgnored context
wholeRange context context
summarizedDocument
context
context
wholeRange
sizing
isTagBasedDocumentSummary
summarizedDocument
isIgnored
priorities promptPriorities
tagBasedDocumentSummary isTagBasedDocumentSummary
state sizing
query history chatVariables
language lang
extractCodeBlock lang
jupyterNotebook
splitDoc state
codeAbove hasContent codeBelow splitDoc
code
replyInterpreter splitDoc
extractCodeBlock
splitDoc
extractCodeBlock
line line
priorities state
tagBasedDocumentSummary state
lang extractCodeBlock hasContent extractCodeBlock
hasContent
code
tagBasedDocumentSummary
props
@ configurationService
@ notebookService
@ tabsAndEditorsService
@ experimentationService
@ workspaceService
props
override
wholeRange
inSummaryExperiment
executedCells vscode
inSummaryExperiment notebook notebook
executedCells
wholeRange wholeRange
executedCells
state sizing
wholeRange state
contextInfo
sizing
wholeRange
doc
jupyterNotebook
hasContent code
aboveCells belowCells contextInfo
aboveCellsInfo aboveCells
belowCellsInfo belowCells
lang
isMarkdown lang
executedCells state
tagBasedDocumentSummary
jupyterNotebook
executedCells
executedCells aboveCellsInfo belowCellsInfo tagBasedDocumentSummary
executedCells aboveCellsInfo belowCellsInfo tagBasedDocumentSummary
isMarkdown
hasContent aboveCellsInfo hasContent aboveCellsInfo hasContent doc lang code
hasContent aboveCellsInfo hasContent aboveCellsInfo hasContent doc lang code
isMarkdown
hasContent aboveCellsInfo hasContent aboveCellsInfo hasContent doc lang code
hasContent aboveCellsInfo hasContent aboveCellsInfo hasContent doc lang code
documentContext
executedCells vscode
state sizing
lang
executedCells
'../../../../platform/notebook/common/notebookService'
;
import
{ IParserService }
from
'../../../../platform/parser/node/parserService'
;
import
{ ITabsAndEditorsService }
from
'../../../../platform/tabs/common/tabsAndEditorsService'
;
import
{ IExperimentationService }
from
'../../../../platform/telemetry/common/nullExperimentationService'
;
import
{ IWorkspaceService }
from
'../../../../platform/workspace/common/workspaceService'
;
import
{ isJupyterNotebookUri, isNotebookCellOrNotebookChatInput }
from
'../../../../util/common/notebooks'
;
import
{ illegalArgument }
from
'../../../../util/vs/base/common/errors'
;
import
{ Schemas }
from
'../../../../util/vs/base/common/network'
;
import
{ IDocumentContext }
from
'../../../prompt/node/documentContext'
;
import
{ EarlyStopping , LeadingMarkdownStreaming , ReplyInterpreterMetaData }
from
'../../../prompt/node/intents'
;
import
{ TextPieceClassifiers }
from
'../../../prompt/node/streamingEdits'
;
import
{ InstructionMessage }
from
'../base/instructionMessage'
;
import
{ LegacySafetyRules }
from
'../base/safetyRules'
;
import
{ JupyterNotebookRules }
from
'../notebook/commonPrompts'
;
import
{ ChatToolReferences , ChatVariables , UserQuery }
from
'../panel/chatVariables'
;
import
{ HistoryWithInstructions }
from
'../panel/conversationHistory'
;
import
{ CustomInstructions }
from
'../panel/customInstructions'
;
import
{ CodeBlock }
from
'../panel/safeElements'
;
import
{ InlineChatEditCodePromptProps }
from
'./inlineChatEditCodePrompt'
;
import
{ promptPriorities }
from
'./inlineChatNotebookCommon'
;
import
{ generateSelectionContextInNotebook, InlineChatCustomNotebookCellsContextRenderer , InlineChatCustomNotebookInfoRenderer , InlineChatJupyterNotebookCellsContextRenderer , InlineChatJupyterNotebookCellsContextTagBasedRenderer , InlineChatNotebookBasePromptState , InlineChatNotebookSelectionCommonProps , InlineChatNotebookSelectionState , InlineChatNotebookVariables }
from
'./inlineChatNotebookCommonPromptElements'
;
import
{ createPromptingSummarizedDocument }
from
'./promptingSummarizedDocument'
;
export
class
InlineChatNotebookGeneratePrompt
extends
PromptElement< InlineChatEditCodePromptProps, InlineChatNotebookBasePromptState>
{
constructor
(
:
InlineChatEditCodePromptProps
,
IIgnoreService
private
readonly
:
IIgnoreService
,
IParserService
private
readonly
:
IParserService
,
IExperimentationService
private
readonly
:
IExperimentationService
)
{
super
(
)
;
}
async
prepare
(
:
PromptSizing
)
:
Promise
<
InlineChatNotebookBasePromptState
>
{
const
{
:
}
=
this
.
props
;
const
=
await
this
.
ignoreService
.
isCopilotIgnored
(
.
document
.
uri
)
;
const
=
.
document
.
validateRange
(
.
wholeRange
)
;
const
=
await
createPromptingSummarizedDocument
(
this
.
parserService
,
.
document
,
.
fileIndentInfo
,
,
.
endpoint
.
modelMaxPromptTokens
/
3
)
;
const
=
this
.
experimentationService
.
getTreatmentVariable
<
boolean
>
(
'copilotchat.tagBasedDocumentSummary'
)
??
false
;
return
{
,
,
:
,
:
}
;
}
render
(
:
InlineChatNotebookBasePromptState
,
:
PromptSizing
)
{
if
(
this
.
props
.
documentContext
.
document
.
uri
.
scheme
!==
Schemas
.
vscodeNotebookCell
)
{
throw
illegalArgument
(
'InlineChatNotebookBasePrompt should be used only with a notebook!'
)
;
}
const
{
,
,
}
=
this
.
props
.
promptContext
;
const
{
:
}
=
this
.
props
.
documentContext
;
const
=
.
languageId
!==
'markdown'
;
const
=
isJupyterNotebookUri
(
this
.
props
.
documentContext
.
document
.
uri
)
;
const
=
.
summarizedDocument
.
splitAroundOriginalSelectionEnd
(
)
;
const
{
,
,
}
=
;
const
=
` ${ codeAbove} $PLACEHOLDER$ ${ codeBelow} `
;
const
=
.
createReplyInterpreter
(
LeadingMarkdownStreaming
.
Mute
,
?
EarlyStopping
.
StopAfterFirstCodeBlock
:
EarlyStopping
.
None
,
.
insertOrReplaceStreaming
,
?
TextPieceClassifiers
.
createCodeBlockClassifier
(
)
:
TextPieceClassifiers
.
createAlwaysInsideCodeBlockClassifier
(
)
,
=>
.
value
.
trim
(
)
!==
'$PLACEHOLDER$'
,
)
;
const
=
.
priorities
;
const
=
.
tagBasedDocumentSummary
;
return
(
< >
< meta value = { new ReplyInterpreterMetaData ( replyInterpreter) } />
< SystemMessage priority = { priorities. core } >
You are an AI programming assistant.
< br />
When asked for your name, you must respond with "GitHub Copilot".
< br />
You are a world class expert in programming, and especially good at
{
.
languageId
}
.
< br />
Source code is always contained in ``` blocks.<br />
The user needs help to write some new code.<br />
<LegacySafetyRules />
</SystemMessage>
<HistoryWithInstructions inline={true} historyPriority={priorities.history ?? 700} passPriority history={history}>
<InstructionMessage priority={priorities.core}>
{jupyterNotebook &&
<>
<JupyterNotebookRules />
{!tagBasedDocumentSummary && <>When dealing with Jupyter Notebook, do not generate CELL INDEX in the code blocks in your answer, it is only used to help you understand the context.<br /></>}
</>
}
{hasContent && <>The user includes existing code and marks with $PLACEHOLDER$ where the new code should go.<br /></>}
{hasContent && <>DO NOT include the text "$PLACEHOLDER$" in your reply.<br /></>}
{hasContent && <>DO NOT repeat any code from the user in your reply.<br /></>}
{(!hasContent && extractCodeBlock) && <>Your must generate a code block surrounded with ``` that will be used in a new file<br />
</ >
}
{
!
&&
< >
When generating content for markdown cell, provide the answer directly without any additional introductory text. Ensure that the response is structured in Markdown format to seamlessly integrate into the markdown file.
</ >
}
</ InstructionMessage >
</ HistoryWithInstructions >
< UserMessage priority = { priorities. context } >
< CustomInstructions languageId = { lang. languageId } chatVariables = { chatVariables} />
</ UserMessage >
< ChatToolReferences priority = { priorities. context } promptContext = { this . props . promptContext } flexGrow = { 1 } embeddedInsideUserMessage = { false } />
< ChatVariables priority = { priorities. context } chatVariables = { chatVariables} embeddedInsideUserMessage = { false } />
< InlineChatNotebookGenerateSelection documentContext = { this . props . documentContext } hasContent = { hasContent} code = { code} priority = { priorities. core } tagBasedDocumentSummary = { tagBasedDocumentSummary} />
< InlineChatNotebookVariables notebookURI = { this . props . documentContext . document . uri } priorities = { priorities} query = { query} />
< UserMessage priority = { priorities. core } >
< UserQuery chatVariables = { chatVariables} query = { query} />
<br />
{
(
&&
)
&&
< >
The code that would fit at $PLACEHOLDER$ with ``` is:</>}
{(hasContent && !extractCodeBlock) && <>The code that would fit at $PLACEHOLDER$ without ``` is:
</ >
}
</ UserMessage >
</ >
);
}
}
interface InlineChatNotebookGenerateSelectionProps extends InlineChatNotebookSelectionCommonProps
{
:
boolean
;
:
string
;
:
boolean
;
}
class InlineChatNotebookGenerateSelection extends PromptElement<InlineChatNotebookGenerateSelectionProps, InlineChatNotebookSelectionState>
{
constructor
(
:
InlineChatNotebookGenerateSelectionProps
,
IConfigurationService
private
readonly
:
IConfigurationService
,
INotebookService
private
readonly
:
INotebookService
,
ITabsAndEditorsService
private
readonly
:
ITabsAndEditorsService
,
IExperimentationService
private
readonly
:
IExperimentationService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
)
{
super
(
)
;
}
async
prepare
(
)
:
Promise
<
InlineChatNotebookSelectionState
>
{
const
{
document
,
}
=
this
.
props
.
documentContext
;
const
=
this
.
experimentationService
.
getTreatmentVariable
(
'copilotchat.notebookSummary'
)
||
this
.
configurationService
.
getConfig
(
ConfigKey
.
Advanced
.
NotebookSummaryExperimentEnabled
)
;
let
:
.
NotebookCell
[
]
|
undefined
=
undefined
;
if
(
&&
this
.
tabsAndEditorsService
.
activeNotebookEditor
?.
&&
this
.
tabsAndEditorsService
.
activeNotebookEditor
?.
.
uri
.
path
===
document
.
uri
.
path
)
{
=
this
.
notebookService
.
getCellExecutions
(
this
.
tabsAndEditorsService
.
activeNotebookEditor
.
notebook
.
uri
)
;
}
return
{
:
document
.
validateRange
(
)
,
}
;
}
render
(
:
InlineChatNotebookSelectionState
,
:
PromptSizing
)
{
if
(
this
.
props
.
documentContext
.
document
.
uri
.
scheme
!==
Schemas
.
vscodeNotebookCell
)
{
throw
illegalArgument
(
'InlineChatNotebookSelection should be used only with a notebook!'
)
;
}
const
{
}
=
;
const
=
generateSelectionContextInNotebook
(
.
endpoint
.
modelMaxPromptTokens
/
3
,
this
.
props
.
documentContext
,
,
this
.
tabsAndEditorsService
,
this
.
workspaceService
)
;
const
=
this
.
props
.
documentContext
.
document
;
const
=
isJupyterNotebookUri
(
this
.
props
.
documentContext
.
document
.
uri
)
;
const
{
,
}
=
this
.
props
;
const
{
,
}
=
;
const
=
||
[
]
;
const
=
||
[
]
;
const
=
this
.
props
.
documentContext
.
language
;
const
=
.
languageId
===
'markdown'
;
const
=
.
executedCells
||
[
]
;
const
=
this
.
props
.
tagBasedDocumentSummary
;
return
< >
{
?
< >
{
(
.
length
>
0
&&
< InlineChatJupyterNotebookCellSummaryContextRenderer documentContext = { this . props . documentContext } executedCells = { executedCells} />
)
}
{
(
.
length
===
0
&&
(
.
length
>
0
||
.
length
>
0
)
&&
!
)
&&
< InlineChatJupyterNotebookCellsContextRenderer documentContext = { this . props . documentContext } aboveCells = { aboveCellsInfo} belowCells = { belowCellsInfo} />
}
{
(
.
length
===
0
&&
(
.
length
>
0
||
.
length
>
0
)
&&
)
&&
< InlineChatJupyterNotebookCellsContextTagBasedRenderer documentContext = { this . props . documentContext } aboveCells = { aboveCellsInfo} belowCells = { belowCellsInfo} />
}
< UserMessage >
{
?
< >
{
&&
< >
Now I edit a markdown cell in this Jupyter Notebook document at index
{
.
length
}
.
< br />
</ >
}
{
!
&&
< >
Now I create a new markdown cell in this Jupyter Notebook document at index
{
.
length
}
.
< br />
</ >
}
This is a markdown cell. Markdown cell is used to describe and document your workflow.
< br />
{
&&
< >
<CodeBlock uri=
{
.
uri
}
languageId=
{
.
languageId
}
code=
{
}
shouldTrim=
{
false
}
/>
< br />
</ >
}
</ >
:
< >
{
&&
< >
Now I edit a cell in this Jupyter Notebook document at index
{
.
length
}
.
< br />
</ >
}
{
!
&&
< >
Now I create a new cell in this Jupyter Notebook document at index
{
.
length
}
.
< br />
</ >
}
{
&&
< >
<CodeBlock uri=
{
.
uri
}
languageId=
{
.
languageId
}
code=
{
}
shouldTrim=
{
false
}
/>
< br />
</ >
}
</ >
}
</ UserMessage >
</ >
:
< >
< InlineChatCustomNotebookInfoRenderer documentContext = { this . props . documentContext } />
< InlineChatCustomNotebookCellsContextRenderer documentContext = { this . props . documentContext } aboveCells = { aboveCellsInfo} belowCells = { belowCellsInfo} />
< UserMessage >
{
?
< >
{
&&
< >
Now I edit a markdown cell in this custom Notebook document at index
{
.
length
}
.
< br />
</ >
}
{
!
&&
< >
Now I create a new markdown cell in this custom Notebook document at index
{
.
length
}
.
< br />
</ >
}
This is a markdown cell. Markdown cell is used to describe and document your workflow.
< br />
{
&&
< >
<CodeBlock uri=
{
.
uri
}
languageId=
{
.
languageId
}
code=
{
}
shouldTrim=
{
false
}
/>
< br />
</ >
}
</ >
:
< >
{
&&
< >
Now I edit a cell in this custom Notebook document at index
{
.
length
}
.
< br />
</ >
}
{
!
&&
< >
Now I create a new cell in this custom Notebook document at index
{
.
length
}
.
< br />
</ >
}
{
&&
< >
<CodeBlock uri=
{
.
uri
}
languageId=
{
.
languageId
}
code=
{
}
shouldTrim=
{
false
}
/>
< br />
</ >
}
</ >
}
</ UserMessage >
</ >
}
</ >
;
}
}
interface InlineChatJupyterNotebookCellSummaryContextRendererProps extends BasePromptElementProps
{
:
IDocumentContext
;
:
.
NotebookCell
[
]
|
undefined
;
}
class InlineChatJupyterNotebookCellSummaryContextRenderer extends PromptElement<InlineChatJupyterNotebookCellSummaryContextRendererProps>
{
render
(
:
void
,
:
PromptSizing
)
{
if
(
!
isNotebookCellOrNotebookChatInput
(
this
.
props
.
documentContext
.
document
.
uri
)
)
{
throw
illegalArgument
(
'InlineChatJupyterNotebookCellSummaryContextRenderer should be used only with a notebook!'
)
;
}
const
=
this
.
props
.
documentContext
.
language
;
const
=
this
.
props
.
executedCells
||
[
]
;
return
(
< >
{
< UserMessage >
I am working on a Jupyter notebook.
< br />
Users have executed the following cells in this notebook<br />
Each cell contains a code block started with ```{lang.languageId}<br />
Since it is Jupyter Notebook, if a module is already imported in a cell, it can be used in other cells as well.<br />
For the same reason, if a variable is defined in a cell, it can be used in other cells as well.<br />
We should not repeat the same import or variable definition in multiple cells, unless we want to overwrite the previous definition.<br />
Do not generate CELL INDEX in your answer, it is only used to help you understand the context.<br />
<br />
Below you will find a set of examples of what you should respond with. Please follow the exmaples on how to avoid repeating code.<br />
## Examples starts here<br />
Here are the executed cells in this Jupyter Notebook:<br />
```python<br />
import pandas as pd<br />
< br />
df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'Gender': ['F', 'M', 'M']})
< br />
print(df)
< br />
```<br />
---------------------------------<br />
USER:<br />
Now I create a new cell in this Jupyter Notebook document at index 1.<br />
USER:<br />
plot the data frame<br />
<br />
---------------------------------<br />
ChatGPT Answer<br />
---------------------------------<br />
To plot the dataframe, we can use the `plot()` method of pandas dataframe. Here's the code:<br />
<br />
```python<br />
df.plot(x='Name', y='Age', kind='bar')
< br />
```<br />
## Example ends here<br />
{executedCells.map((cell) => (<NotebookCellContent cell={cell} />))}
</UserMessage>
}
</>
);
}
}
class NotebookCellContent extends PromptElement<{ cell: vscode.NotebookCell } & BasePromptElementProps> {
override render() {
return <>
```
{
this
.
props
.
cell
.
document
.
languageId
}
< br />
{
this
.
props
.
cell
.
document
.
getText
(
)
}
< br />
```
</ >
;
}
}