Skip to content

Commit 49d40f2

Browse files
authored
Add a source range prompt containing the current file content range (#8129)
* Add a source range prompt containing the current file content range To help @greg-kcio with not needing to stuff everything into the LLM context window. * Fix lints
1 parent 2f4b687 commit 49d40f2

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/components/ModelingSidebar/ModelingPanes/MlEphantConversationPane.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ export const MlEphantConversationPane = (props: {
7676
type: MlEphantManagerTransitions.PromptEditModel,
7777
prompt: requestedPrompt,
7878
projectForPromptOutput: props.theProject,
79-
fileSelectedDuringPrompting: props.loaderFile,
79+
fileSelectedDuringPrompting: {
80+
entry: props.loaderFile,
81+
content: props.codeManager.code,
82+
},
8083
projectFiles,
8184
selections: props.contextModeling.selectionRanges,
8285
artifactGraph: props.kclManager.artifactGraph,

src/lib/promptToEdit.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ export function constructMultiFileIterationRequestWithPromptHelpers({
7979
projectFiles,
8080
artifactGraph,
8181
projectName,
82+
currentFile,
8283
kclVersion,
8384
}: ConstructRequestArgs): PromptToEditRequest {
8485
const kclFilesMap: KclFileMetaMap = {}
8586
const files: KittyCadLibFile[] = []
87+
const currentFileMeta = projectFiles.find(
88+
(f) => f.type !== 'other' && f.absPath === currentFile.entry?.path
89+
)
8690
projectFiles.forEach((file) => {
8791
let data: Blob
8892
if (file.type === 'other') {
@@ -98,12 +102,23 @@ export function constructMultiFileIterationRequestWithPromptHelpers({
98102
})
99103
})
100104

105+
// Way to patch in supplying the currently-opened file without updating the API.
106+
// TODO: update the API to support currently-opened files as other parts of the payload
107+
const currentFilePrompt: Models['SourceRangePrompt_type'] = {
108+
prompt: 'This is the active file',
109+
range: convertAppRangeToApiRange(
110+
[0, currentFile.content.length, 0],
111+
currentFile.content
112+
),
113+
file: currentFileMeta?.relPath,
114+
}
115+
101116
// If no selection, use whole file
102117
if (selections === null) {
103118
return {
104119
body: {
105120
prompt,
106-
source_ranges: [],
121+
source_ranges: [currentFilePrompt],
107122
project_name:
108123
projectName !== '' && projectName !== 'browser'
109124
? projectName
@@ -245,6 +260,8 @@ See later source ranges for more context. about the sweep`,
245260
}
246261
return prompts
247262
})
263+
// Push the current file prompt alongside the selection-based prompts
264+
ranges.push(currentFilePrompt)
248265
let payload = {
249266
body: {
250267
prompt,

src/lib/promptToEditTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ArtifactGraph } from '@src/lang/wasm'
33
import type { Selections } from '@src/lib/selections'
44
import type { FileMeta } from '@src/lib/types'
55
import type { File as KittyCadLibFile } from '@kittycad/lib/dist/types/src/models'
6+
import type { FileEntry } from '@src/lib/project'
67

78
export type KclFileMetaMap = {
89
[execStateFileNamesIndex: number]: Extract<FileMeta, { type: 'kcl' }>
@@ -29,6 +30,7 @@ export interface ConstructRequestArgs {
2930
selections: Selections | null
3031
projectFiles: FileMeta[]
3132
projectName: string
33+
currentFile: { entry?: FileEntry; content: string }
3234
artifactGraph: ArtifactGraph
3335
kclVersion: string
3436
}

src/machines/mlEphantManagerMachine.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export type MlEphantManagerEvents =
8181
type: MlEphantManagerTransitions.PromptEditModel
8282
projectForPromptOutput: Project
8383
prompt: string
84-
fileSelectedDuringPrompting?: FileEntry
84+
fileSelectedDuringPrompting: { entry?: FileEntry; content: string }
8585
projectFiles: FileMeta[]
8686
selections: Selections
8787
artifactGraph: ArtifactGraph
@@ -380,6 +380,7 @@ export const mlEphantManagerMachine = setup({
380380
projectFiles: event.projectFiles,
381381
artifactGraph: event.artifactGraph,
382382
projectName: event.projectForPromptOutput.name,
383+
currentFile: event.fileSelectedDuringPrompting,
383384
kclVersion: getKclVersion(),
384385
}
385386
)
@@ -406,7 +407,7 @@ export const mlEphantManagerMachine = setup({
406407
promptsBelongingToConversation.push(result.id)
407408
promptsMeta.set(result.id, {
408409
type: PromptType.Edit,
409-
targetFile: args.input.event.fileSelectedDuringPrompting,
410+
targetFile: args.input.event.fileSelectedDuringPrompting.entry,
410411
project: args.input.event.projectForPromptOutput,
411412
})
412413

0 commit comments

Comments
 (0)