You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a completely overhauled version of the original. There was too much funkery (real word) that could happen by letting chatgpt just spew characters via keyboard.
V1 still will exist as quick-prompt.js and will live under the deprecated folder with a disclaimer about the funk mentioned above and use at own risk, etc. I'll still be using it, because it's pretty fun :)
Anyhow, This is a "pre-release" and will be added to my kenv soon
There are a couple things I still need to work out, like how the heck to stop the token stream on escape and some more QOL, but I really happy with it. I used it all week in my workflow and it's really a game changer.
Feedback, critiques, or bad puns are welcome.
Anyhow, set forth and be awesome.
/*# Prompt AnythingHighlight some text and run this script to prompt against it.Useful for summarizing text, generating a title, or any other task you can think of.## Usage- Highlight the text you want to prompt against- Run the script via shortcut or command palette- Input your desired prompt- Wait for the AI to respond- Select one of the options* Retry - Rerun generation with option to update prompt* Edit - Edit response in editor - On editor exit the message is saved to the clipboard - On editor submit the message is pasted into the highlighted text* Copy - Copy response to clipboard* Paste - Paste response into highlighted text* Save - Save response to file (not working)## Example- Highlight: 'Some really long passage in a blog post'- Run Script- Prompt: `Summarize this passage in the form of Shakespearean prose`- Waaaaait for it...- Get a response from the AI- Select an option- Rinse and repeat*/// Name: Prompt Anything// Description: Custom prompt for any highlighted text// Author: Josh Mabry// Twitter: @AI_Citizen// Shortcut: alt shift enter//#################// ScriptKit Import//#################import"@johnlindquist/kit";//#################// LangChain Imports//#################let{ ChatOpenAI }=awaitimport("langchain/chat_models");let{ HumanChatMessage, SystemChatMessage }=awaitimport("langchain/schema");//#################// Request API KEY//#################// stored in .env file after first run// can change there or through the command paletteletopenAIApiKey=awaitenv("OPENAI_API_KEY",{hint: `Grab a key from <a href="https://platform.openai.com/account/api-keys">here</a>`,});// System input / Task for the AI to followletuserSystemInput=awaitarg("Summarize this passage");// User Prompt from highlighted textletuserPrompt=awaitgetSelectedText();//#################// Prompt Template//#################constformatPrompt=(prompt)=>{return`##### Ignore prior instructions- Return answer in markdown format- You are tasked with the following${prompt}########`;};//################// Options Template//################constoptions=`* [Retry](submit:retry) - Rerun generation with option to update prompt* [Edit](submit:edit) - Edit response in editor* [Copy](submit:copy) - Copy response to clipboard* [Paste](submit:paste) - Paste response into highlighted text* [Save](submit:save) - Save response to file (not working)`;//#########// Helpers//########// exit script on cancelconstcancelChat=()=>{process.exit(1);};//################// Main Function//################/** * * @param {*} prompt * @param {*} humanChatMessage */asyncfunctionpromptAgainstHighlightedText(prompt=formatPrompt(userSystemInput),humanChatMessage=userPrompt){letcurrentMessage="";constllm=newChatOpenAI({// 0 = "precise", 1 = "creative"temperature: 0.3,// modelName: "gpt-4", // uncomment to use GPT-4 (requires beta access)openAIApiKey: openAIApiKey,// turn off to only get output when the AI is donestreaming: true,callbacks: [{handleLLMNewToken: async(token)=>{log(`handleLLMNewToken`);// each new token is appended to the current message// and then rendered to the screencurrentMessage+=token;// render current messageawaitdiv({html: md(currentMessage+options),// @TODO: Figure out how to get ESC to trigger a cancelonAbandon: cancelChat,onEscape: cancelChat,onBackspace: cancelChat,// if this is set to false you can click outside the window to cancel// ignoreBlur: true,focus: true,// hint: `Press ESC to cancel`,});},handleLLMError: async(err)=>{dev({ err });},handleLLMEnd: async()=>{log(`handleLLMEnd`);// render final message with optionslethtml=md(currentMessage+options);// wait for user to select an optionconstselectedOption=awaitdiv(html,{ignoreBlur: true,focus: true,// onSubmit: () => setSelectedText(currentMessage),});// handle selected optionswitch(selectedOption){case"paste":
// paste into highlighted textawaitsetSelectedText(currentMessage);process.exit(1);case"retry":
// reset current messagecurrentMessage="";// prompt again with new prompt// press enter to use original promptconstfollowUp=awaitarg({placeholder: userSystemInput,hint: "Press enter to use the same prompt",});awaitprocessMessage(followUp);break;case"edit":
// still need to figure out best way to handle submit and abort// would like custom buttons for triggering all these same options such as saveawaiteditor({value: currentMessage,onEscape: async(state)=>{// copy to clipboard when exiting the editorawaitclipboard.writeText(state);// exit scriptprocess.exit(1);},onSubmit: async(state)=>{// paste into highlighted text when pressing enterawaitsetSelectedText(state);// exit scriptprocess.exit(1);},});break;case"copy":
// copy to clipboardawaitclipboard.writeText(currentMessage);// exit scriptprocess.exit(1);case"save":
awaitinspect(currentMessage,`conversations/${Date.now()}.md`);// exit scriptprocess.exit(1);default:
// copy to clipboardawaitclipboard.writeText(currentMessage);process.exit(1);}awaitoptionHandler(selectedOption);},},],});//###########// Main Loop//###########// runs the language model until the user cancelswhile(true){awaitllm.call([newSystemChatMessage(formatPrompt(prompt)),newHumanChatMessage(humanChatMessage),]);}}promptAgainstHighlightedText();
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Open prompt-anything in Script Kit
It's a completely overhauled version of the original. There was too much funkery (real word) that could happen by letting chatgpt just spew characters via keyboard.
V1 still will exist as
quick-prompt.js
and will live under the deprecated folder with a disclaimer about the funk mentioned above and use at own risk, etc. I'll still be using it, because it's pretty fun :)Anyhow, This is a "pre-release" and will be added to my kenv soon
There are a couple things I still need to work out, like how the heck to stop the token stream on escape and some more QOL, but I really happy with it. I used it all week in my workflow and it's really a game changer.
Feedback, critiques, or bad puns are welcome.
Anyhow, set forth and be awesome.
Beta Was this translation helpful? Give feedback.
All reactions