Skip to content

Instantly share code, notes, and snippets.

@simonw
Created March 4, 2024 17:28
Show Gist options
  • Save simonw/d3c07969a522226067b8fe099007fe4a to your computer and use it in GitHub Desktop.
Save simonw/d3c07969a522226067b8fe099007fe4a to your computer and use it in GitHub Desktop.
@maschinenzeitmaschine
Copy link

maschinenzeitmaschine commented Mar 4, 2024

p.s. i'm well aware this is out of scope and needs quite some more than a shell script, but wouldn't it be insanely cool if this would not only open a text window with an answer, but an interactive shell? like a chat interface, so i could do follow-up questions? i really love the idea to have an llm available anywhere in the finder and not have to open an app or browser or terminal and copy/paste every time…

@eliyastein
Copy link

@maschinenzeitmaschine - the script can be modified to pop open a terminal that starts a chat with the highlighted text as the system prompt. Something like this:

escaped_args=""
for arg in "$@"; do
  escaped_arg=$(printf '%s\n' "$arg" | sed "s/'/'\\\\''/g")
  escaped_args="$escaped_args '$escaped_arg'"
done

osascript -e "tell application \"Terminal\" to do script \"/usr/local/bin/llm chat -m gpt-4 -s ${escaped_args}\""

@devtanna
Copy link

While this is great I wish I could use this in any app. Currently I cannot access this automator workflow from within slack :/

@eliyastein
Copy link

@devtanna - It works from Slack for me. If you highlight some text in slack, you can access the workflow from the menu Slack -> Services -> LLM, or you can invoke it with a hotkey if you've set one under keyboard shortcuts.

@devtanna
Copy link

oh cool, thanks @eliyastein ! works now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment