jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.64k stars 312 forks source link

api_key_cmd with pipes (|) ? #280

Closed sedlund closed 8 months ago

sedlund commented 12 months ago

https://github.com/jackMort/ChatGPT.nvim/blob/8191b4a1faea28483aa3a495d01ade3eb86409fe/lua/chatgpt/api.lua#L174

Is there a way this can be changed so I can use a pipe in my command?

I'd like to use:

api_cmd_key = "rbw get -f OPENAI_API_KEY chat.openai.com | awk '{print $2}'"

Using only rbw get -f OPENAI_API_KEY chat.openai.com gets a custom field from the entry but its output format is:

OPENAI_API_KEY: sk-fda94jf88gfdssblah

so I need to pipe to awk, sed, cut, jq or something. I wrote a wrapper script which works, but this is not ideal for having my config files be portable.

Thanks

kentchiu commented 11 months ago

same here +1

Solution:

Put your command in a script file and call the script file instead.

ex:

get_api_key.sh

#!/bin/bash
rbw get -f OPENAI_API_KEY chat.openai.com | awk '{print $2}

in config file

   api_key_cmd = "get_api_key.sh"

It works for me.