AI prompts
base on From anywhere you can type, query and stream the output of an LLM or any other script # Plock
Use an LLM (or anything else that can stream to stdout) directly from literally anywhere you can type. Outputs in real
time.
![demo](https://github.com/jasonjmcghee/plock/assets/1522149/737cb647-69aa-426c-884d-bbe29bac0637)
Write a prompt, select it, and (by default) hit `Cmd+Shift+.`. It will replace your prompt with the output in a
streaming fashion.
Also! You can first put something on your clipboard (as in copy some text) before writing / selecting your prompt, and
it (by default) `Cmd+Shift+/` and it will use the copied text as context to answer your prompt.
For Linux, use `Ctrl` instead of `Cmd`.
**100% Local** by default. (If you want to use an API or something, you can call any shell script you want specified
in `settings.json`)
I show an example `settings.json` in [Settings](#settings)
---
## 🚨 Looking for contributions / help! 🚨
I would love to keep this project alive and growing, but can't do it alone.
If you're at all interested in contributing, please feel free to reach out, start a discussion, open a PR, look at issues, look at roadmap below, etc.
Something not working properly? There's no telemtry or tracking, so I won't know! Please log an issue or take a crack at fixing it yourself and
submitting a PR! Have feature ideas? Log an issue!
---
## Demo showing concept of Triggers, and the new flexible system
<a href="https://www.loom.com/share/d3adddc37c2e4c8daeef11255c0135ea">
<img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/d3adddc37c2e4c8daeef11255c0135ea-with-play.gif">
</a>
## Demo using GPT-3.5 and GPT-4
<a href="https://www.loom.com/share/756220f3f5e249d5b4d5b759e9f9add3">
<img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/756220f3f5e249d5b4d5b759e9f9add3-with-play.gif">
</a>
If you are going to use this with remote APIs, consider environment variables for your API keys... make sure they exist
wherever you launch, or directly embed them (just don't push that code anywhere)
## (Original) Demo using Ollama
<a href="https://www.loom.com/share/fed267e695d145c88e6bff7e631da8e0">
<img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/fed267e695d145c88e6bff7e631da8e0-with-play.gif">
</a>
(in the video I mention [rem](https://github.com/jasonjmcghee/rem), another project I'm working on)
## Getting Started
Install [ollama](https://github.com/jmorganca/ollama) and make sure to run `ollama pull openhermes2.5-mistral` or swap
it out in settings for something else.
Launch "plock"
Shortcuts:
`Ctrl / Cmd + Shift + .`: Replace the selected text with the output of the model.
`Ctrl / Cmd + Shift + /`: Feed whatever is on your clipboard as "context" and the replace the selected text with the
output of the model.
(these two are customizable in `settings.json`)
`Escape`: Stop any streaming output
**Mac** will request access to keyboard accessibility.
**Linux** (untested), may require X11 libs for clipboard stuff and key simulation using
enigo. [Helpful instructions](https://github.com/enigo-rs/enigo/tree/main#runtime-dependencies)
Also [system tray icons require some extras](https://tauri.app/v1/guides/features/system-tray/#linux-setup)
**Windows** (untested), you'll need to swap out Ollama for something else, as it doesn't support windows yet.
## [Settings]
There is a `settings.json` file which you can edit to change shortcuts, the model,
prompts, whether to use shell scripts and what they are, and other settings.
After updating, click the tray icon and select "Load Settings" or restart it.
At any time you can click the tray icon and it will list the settings location. For what it's worth:
On mac, It's at `~/Library/Application Support/today.jason.plock/settings.json`.
On linux, I think it's `~/$XDG_DATA_HOME/today.jason.plock/settings.json`.
Windows, I think it's `~\AppData\Local\today.jason.plock\settings.json`
But clicking the icon is the best way.
Correct me if any of these are wrong.
### Using Settings
Take a look at the shortcut keys. A “trigger” can be started with a shortcut. That points to a process (by an 0-index) and a prompt (by a 0-index) to the lists defined in the processes and prompts fields.
a process is either “ollama” or a command (shell on mac). You can use that to call your script.
prompts can use one of the two built in variables $CLIPBOARD and $SELECTION, or any others you define using set_env_var trigger.
next_steps defines what happens to the output, which can be written to the screen (streaming or all at once ), saved to a variable, and/or kick off another trigger.
In the future i want to make it easy to trigger flexibly (cron, push), output wherever / however, easily chain things together.
very very open to feedback
<details>
<summary>Show Example</summary>
```json
{
"environment": {
"PERPLEXITY_API": "",
"OLLAMA_MODEL": "openhermes2.5-mistral",
"OPENAI_API": ""
},
"processes": [
{
"name": "Use GPT",
"command": [
"bash",
"/Users/jason/workspace/plock/scripts/gpt.sh"
]
},
{
"name": "Execute text directly as script",
"command": []
},
{
"name": "Use perplexity",
"command": [
"bash",
"/Users/jason/workspace/plock/scripts/p.sh"
]
},
{
"name": "Use Dall-E",
"command": [
"bash",
"/Users/jason/workspace/plock/scripts/dalle.sh"
]
},
"ollama"
],
"prompts": [
{
"name": "default basic",
"prompt": "$SELECTION"
},
{
"name": "default with context",
"prompt": "I will ask you to do something. Below is some extra context to help do what I ask. --------- $CLIPBOARD --------- Given the above context, please, $SELECTION. DO NOT OUTPUT ANYTHING ELSE."
},
{
"name": "step",
"prompt": "$STEP"
},
{
"name": "say gpt",
"prompt": "say \"$GPT\""
}
],
"triggers": [
{
"trigger_with_shortcut": "Command+Shift+,",
"process": 1,
"prompt": 0,
"next_steps": [
{
"store_as_env_var": "STEP"
},
{
"trigger": 4
}
],
"selection_action": null
},
{
"trigger_with_shortcut": "Command+Shift+.",
"process": 0,
"prompt": 0,
"next_steps": [
"stream_text_to_screen"
],
"selection_action": "newline"
},
{
"trigger_with_shortcut": "Command+Shift+/",
"process": 1,
"prompt": 0,
"next_steps": [
"write_final_text_to_screen"
],
"selection_action": "newline"
},
{
"trigger_with_shortcut": "Command+Shift+'",
"process": 3,
"prompt": 0,
"next_steps": [
"write_image_to_screen"
],
"selection_action": null
},
{
"trigger_with_shortcut": null,
"process": 0,
"prompt": 2,
"next_steps": [
"stream_text_to_screen",
{
"store_as_env_var": "GPT"
},
{
"trigger": 5
}
],
"selection_action": null
},
{
"trigger_with_shortcut": null,
"process": 0,
"prompt": 3,
"next_steps": [],
"selection_action": null
}
]
}
```
</details>
## Building Plock
If you don't want to blindly trust binaries (you shouldn't), here's how you can build it
yourself!
## Prerequisites
- Node.js (v14 or later)
- Rust (v1.41 or later)
- NPM (latest version)
## Installation Steps
### Node.js
Download from: https://nodejs.org/
### Rust
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
```
### ~~Bun~~ NPM
_Whattt?? Why?_ - well, windows doesn't support `bun` in github actions afaict. So, I'm using npm instead.
[How to Install Node](https://nodejs.org/en/download/package-manager)
## Project Setup
```bash
git clone <repo_url>
cd path/to/project
npm install
npm run tauri dev
```
## Build
```bash
npm run tauri build
```
## Inspiration / Another Great Project
- [LLM-automator](https://github.com/radames/LLM-automator)
## Another demo
Another demo where I use the perplexity shell script to generate an answer super fast.
Not affiliated, was just replying to a thread lol
https://github.com/jasonjmcghee/plock/assets/1522149/6166af73-545f-4a8e-ad46-ea8aacd84969
## Secrets
Curious folks might be wondering what `ocr` feature is. I took a crack at taking a screenshot,
running OCR, and using that for context, instead of copying text manually. Long story short,
rusty-tesseract _really_ dissapointed me, which is awkward b/c it's core
to [xrem](https://github.com/jasonjmcghee/xrem).
If someone wants to figure this out... this could be really cool, especially with multi-modal models.
", Assign "at most 3 tags" to the expected json: {"id":"7198","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"