Skip to content

Commit

Permalink
Add multiple files to prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiecraane committed Jun 13, 2023
1 parent 5c87656 commit 55cc47c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
- Add model, temperature and max tokens to settings
- Fixed toolwindow state

## [0.0.8] - TBD
## [0.0.8] - 2023-06-13

- Add gpt-3.5-turbo-16k model
- Add gpt-4-32k model
- Create prompt with the contents of multiple selected files using the New Prompt or Append to Prompt actions (right-click in Project view)

### Added
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ import dev.jamiecraane.gptmentorplugin.messagebus.CHAT_GPT_ACTION_TOPIC
class AppendPromptFromFileAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT)
val psiFile = e.getData(CommonDataKeys.PSI_FILE)
val files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)

if (project == null || psiFile == null) {
if (project == null || files.isNullOrEmpty()) {
return
}

val virtualFile = psiFile.virtualFile
val contents = String(virtualFile.contentsToByteArray())
if (contents.isNotEmpty()) {
project.messageBus.syncPublisher(CHAT_GPT_ACTION_TOPIC).appendToPrompt(contents)
val allFilesContent = buildString {
files.forEach { file ->
val contents = String(file.contentsToByteArray())
append(contents)
repeat(2) {
appendLine()
}
}
}


if (allFilesContent.isNotEmpty()) {
project.messageBus.syncPublisher(CHAT_GPT_ACTION_TOPIC).appendToPrompt(allFilesContent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ import dev.jamiecraane.gptmentorplugin.messagebus.CHAT_GPT_ACTION_TOPIC
class NewPromptFromFileAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT)
val psiFile = e.getData(CommonDataKeys.PSI_FILE)
val files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)

if (project == null || psiFile == null) {
if (project == null || files.isNullOrEmpty()) {
return
}

val virtualFile = psiFile.virtualFile
val contents = String(virtualFile.contentsToByteArray())
val allFilesContent = buildString {
files.forEach { file ->
val contents = String(file.contentsToByteArray())
append(contents)
repeat(2) {
appendLine()
}
}
}

val promptFactory = PromptFactory(project.getService(GptMentorSettingsState::class.java))
promptFactory.promptFromSelection(contents).let { prompt ->
promptFactory.promptFromSelection(allFilesContent).let { prompt ->
project.messageBus.syncPublisher(CHAT_GPT_ACTION_TOPIC).onNewPrompt(prompt)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
</add-to-group>

<action id="promptFromFile" class="dev.jamiecraane.gptmentorplugin.actions.file.NewPromptFromFileAction"
text="New Prompt From File"/>
text="New Prompt From File(s)"/>

<action id="appendPromptFromFile" class="dev.jamiecraane.gptmentorplugin.actions.file.AppendPromptFromFileAction"
text="Append Prompt With File"/>
text="Append Prompt With File(s)"/>
</group>

<action id="addGitCommitsToPrompt" class="dev.jamiecraane.gptmentorplugin.actions.git.AddGitCommitsToPromptAction"
Expand Down

0 comments on commit 55cc47c

Please sign in to comment.