FlexiGPT
Interact with GPT AI models (GPT3, ChatGPT, etc) as a power user.
FlexiGPT offers pre-defined prompts enriched with custom or predefined functions that can be engineered and fine-tuned to meet specific user needs. Prompts can be saved and used directly within VSCode, and the extension supports request parameter modifications for GPT APIs and post-processing response via responseHandlers in prompts.
Users can use a chat activity bar interface for request/response interaction, load/save conversations from history, export conversations to a file, and copy/insert/create new files out of GPT response.
FlexiGPT also offers a variety of UI and access features, including keyboard shortcuts, editor/command context, and command palette controls, making it easy to use and customizable.
Download from: VSCode Marketplace
Table of contents
Features
Ask GPT AI models (GPT3, ChatGPT, etc) anything you want
- Currently supported:
- OpenAI chat completion APIs, with GPT3.5 models
- OpenAI completion APIs, with GPT2/3 models
Use pre-defined prompts in configuration files
Engineer and fine tune prompts, save them and use them directly within VSCode.
Prompts can be enriched using predefined functions or custom functions. Multiple inbuilt predefined functions available.
Supports request parameter modifications for GPT APIs
Supports post-processing response via responseHandlers in prompts.
Available inbuilt prompts:
FlexiGPT basic prompts
- Refactor selection
- Generate unit test
- Complete
- Explain code
- Generate Documentation
- Find problems
- Optimize selection
Go basic prompts
- Write godoc string
- Generate unit test
UI and access
- Chat activity bar interface for request/response interaction
- Load/Save conversations from history
- Export conversations to a file
- Copy, Insert, Create new file out of GPT response.
- Detailed request and response to/from to GPT APIs available in activity bar itself for better prompt engineering and debugging
- Keyboard shortcuts, editor/command context (right click in editor), command palette controls for quick access
Immediate term TODO:
- Additional features:
- Prompt files:
- Add support for Pre processing the prompt before sending the API.
- Provide enriched data handling functions. E.g:
- Collect definitions, strip them and pass on, etc.
- Diff collection from a git branch for review
Installation
- Requirements
- Visual Studio Code v1.74.0 or later
- Steps:
- Install Visual Studio Code 1.74.0 or later
- Launch Visual Studio Code
- From the command palette
Ctrl
-Shift
-P
(Windows, Linux) or Cmd
-Shift
-P
(macOS), run > Extensions: Install Extension
.
- Choose the extension
FlexiGPT
by ppipada
.
- Restart Visual Studio Code after the installation
Configuration
FlexiGPT requires an OpenAI API key to function. You can obtain one from your openAI account settings here.
To configure FlexiGPT, open Visual Studio Code's settings (File > Preferences > Settings or by using the Ctrl
/Cmd
+ ,
keyboard shortcut) and search for flexigpt
.
FlexiGPT uses defaultChatCompletionModel: gpt-3.5-turbo
, unless the prompt overrides it.
Options:
flexigpt.openai.apiKey: Your OpenAI API key, which can be obtained from the OpenAI website.
flexigpt.openai.timeout: The timeout for OpenAI requests, in seconds. Default: 60.
flexigpt.openai.defaultChatCompletionModel: Default model to use for chat completion requests.
- You can always override the default model per prompt via the prompt file command declaration.
- FlexiGPT basic prompts will use the default models set.
- Default:
gpt-3.5-turbo
. Note that gpt-3.5-turbo
usage is accounted in OpenAIs billing. Only free model that is in beta as of Feb 2023 is codex (code-davinci-002
).
flexigpt.openai.defaultCompletionModel: Default model to use for completion requests.
flexigpt.openai.defaultEditModel: Default model to use for edit requests. (currently unsupported)
- You can always override the default model per prompt via the prompt file command declaration.
- FlexiGPT basic prompts will use the default models set.
- Default:
code-davinci-edit-001
.
flexigpt.promptFiles: A semicolon-separated list of paths to user-defined prompt configuration files. Prompt file configuration is detailed below.
flexigpt.inBuiltPrompts: A semicolon-separated list of inbuilt prompt filenames to enable. For multiple names separate with ';'. 'flexigptbasic.js' will always be enabled. Inbuilt prompts can be found at this path. Current values are: "flexigptbasic.js" and "gobasic.js".
Sample Full configuration
"flexigpt.openai.apiKey": "sk-mkey",
"flexigpt.openai.timeout": "120",
"flexigpt.openai.defaultCompletionModel": "gpt-3.5-turbo",
"flexigpt.openai.defaultChatCompletionModel": "gpt-3.5-turbo",
"flexigpt.openai.defaultEditModel": "code-davinci-edit-001",
"flexigpt.promptFiles": "/home/me/my_prompt_files/myprompts.js",
"flexigpt.inBuiltPrompts": "gobasic.js"
Usage
Samples
Here is a sample javascript (.js) prompt file
module.exports = {
commands: [
{
name: "Refactor",
template: `Refactor following function.
function:
{system.selection}`,
},
],
};
Here is a more complex javascript (.js) prompt file
module.exports = {
commands: [
{
name: "Create unit test.",
template: `Create unit test in {user.unitTestFramework} framework for following function.
code:
{system.selection}`,
responseHandler: {
func: "writeFile",
args: {
filePath: "user.testFileName",
},
},
requestparams: {
model: "gpt-3.5-turbo",
stop: ["##", "func Test", "package main", "func main"],
},
},
{
name: "Write godoc",
template: `Write godoc for following functions.
code:
{system.selection}`,
responseHandler: {
func: "append",
args: {
position: "start",
},
},
requestparams: {
model: "code-davinci-002",
stop: ["##", "func Test", "package main", "func main"],
},
},
],
functions: [
// you could also write your own responseHandler
function myHandler({ system, user }) {
console.table({ system });
console.table({ user });
},
],
variables: [
{
name: "unitTestFramework",
value: "testing",
},
{
name: "testFileName",
value: ({ baseFolder, fileName, fileExtension }) =>
`${baseFolder}\\${fileName}_test.${fileExtension}`,
},
],
};
Creating Command
Predefined System Variables
Variable Name |
Description |
system.selection |
Selected text in editor |
system.question |
OpenAI question |
system.answer |
OpenAI answer |
system.language |
Programming language of active file |
system.baseFolder |
Project base path |
system.fileName |
Name of active file |
system.filePath |
Full path of active file |
system.fileExtension |
Extension of active file |
system.commitAndTagList |
Last 25 commits and associated tags |
Note that the system.
prefix for a system variable is optional. Therefore, you can even use only {selection}
to use the selected text, or {language}
instead of {system.language}
for language of your file.
Predefined System Function
Function Name |
Description |
params(default) |
append |
Append Text |
textToAppend(system.answer),postion('end') |
replace |
Replace selected text |
textToReplace(system.answer) |
showWebView |
Show Webview |
question(system.question),question(system.answer) |
writeConsole |
Write text to console |
content(system.answer) |
writeFile |
Write text to file |
filePath(),content(system.answer) |
Replace
Replace text with selection. Take optional parameter textToReplace
In default value equals to API answer.
Default Usage
...
commands: [
{
name: "Refactor",
template: `Refactor following function.
function:
{system.selection}`
responseHandler:'replace'
},
],
Usage with params
...
commands: [
{
name: "Refactor",
template: `Refactor following function.
function:
{system.selection}`
responseHandler:{
func: 'replace',
args: {
textToReplace: 'user.answerModified'
}
}
},
],
variables: [
{
name: "answerModified",
value: ({answer})=>`/*\n${anwer}\n*/`
},
],
Append
Append text with selection. Take optional parameter textToAppend
and postion
. postion
can be start
or end
In default textToAppend
equals to OpenAI postion
is end of selection
Sample usage
...
commands: [
{
name: "Append",
template: `Write jsdoc for following function.
function:
{system.selection}`
responseHandler:{
func: 'append',
args: {
position: 'start'
}
}
},
],
Creating Variables
Any of the variables
items can be used in a command template. User-defined values must have the "user" prefix. For example, if "testFileName" is defined in variables, it can be used as "user.TestFileName" in the template file or passed to a function.
Variable values can be static or dynamic. For dynamic values, you should create a getter method. When calling the variable getter, system variables(see Predefined System Variables) and functions are passed as arguments, the first argument is a system variable and the second one is a function.
module.exports = {
variables: [
{
//static
name: "testingFramework",
value: "xUnit"
},
{
//dynamic
name: "typeNameInResponse",
value: ({ answer/*system variable*/ }, { extractTypeName/*user defined function*/ }) => extractTypeName({ code: answer })
},
]
functions: [function extractTypeName({ code, system }) {/**/}],
commands: [
{
name: "Create DTO",
template: `Create unit test with {user.testingFramework} for following class.
class:
{system.selection}`,
responseHandler: {
func: 'writeFile',
args: {
filePath: 'user.typeNameInResponse'/*usage for function arg*/
}
}
}
]
}
Creating Functions
TODO
License
FlexiGPT is open source software licensed under the MIT license.
Contributions
Contributions are welcome! Feel free to submit a pull request on GitHub.
Support
If you have any questions or problems, please open an issue on GitHub at the issues page.