Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Chatblade – A CLI Swiss Army Knife for ChatGPT (github.com/npiv)
315 points by ramblerman on March 19, 2023 | hide | past | favorite | 65 comments
integrate chatGPT into your scripts or terminal work. Supports piping text, saving prompts, estimating costs, and some basic json/yaml extraction.

I've added some elaborate examples on the readme of how to use it with pictures, that may provide a better overview.




Ha, I was about to release something similar to this as my first ever open-source project. Beaten by a day. And, frankly, this is better than mine.

Congrats to npiv.


Even if your tool is just written in a different language you'll probably have an audience. Some people will want to hack on your code, maybe they don't know python. Maybe they just don't like python for whatever reason.

Get it shipped lol. Highest rated comment and you're practically the only person not linking your own!


Same thing happened to me two weeks ago... Released clevercli[0] only to find out aichat[1] had more features and written in Rust.

[0] https://github.com/clevercli/clevercli

[1] https://github.com/sigoden/aichat/


> written in Rust

Thank you, I'm glad to have a more casually hackable implementation in TypeScript. It definitely helps that you project is not written in Rust!


Amazing! Thank you. The AI Chat is super interesting.

Having that on even just a super old computer would be revolutionary for the old computer. Completely new life.

Something old that was obsolete, if it can have a terminal connected to an LLM, and hopefully internet access too, then it becomes a super powerful interface that doesn’t even require images.


If I was going to have a pet AI who’s brain was largely in the cloud, Id put the ghost in an old machine =]


Does aichat also connect to GPT-4?


At this point a good fraction of every half decent engineer is trying to do something around LLMs. Not sure if that’s the best use of the effort when the entire field is in a state of such unstable equilibrium.


Learning by doing is second only to learning by teaching, so my best guess is that it's probably extremely valuable.


Where’s the harm in releasing it anyway? You’ve done the work, put it out there!


Multiple implementations are always appreciated, different languages etc. :)


I think it's still worth releasing even if it's not as good as someone else's. Worst-case scenario, you're growing and learning and putting something out there that demonstrates you're developing interesting software. And who knows, maybe you'll find some other contributors, or maybe this will spark some novel ideas in someone else. You never know the power of your contributions.

Don't gatekeep yourself!


It’s not always about being the first, but being the best and having enough steam to stick around. Lots of abandonware too.

Launch your take anyways


Release it anyhow!


Yup, release it anyhow. There’s plenty of storage space on the internet.


Haha yeah, I made something similar for my own use. I bet thousands of people saw the ChatGPT interface and instinctively wanted to pipe stuff / save it easily without fussing with manual copy and paste. It's still a fun project and quite rewarding to see the text stream appear in real time in your shell.


Yeah still release it for sure. I don’t line python and that’s enough for me to check out a different language.


And 1k github stars. Is the creator famous?


Do it anyway.


I'm building something similar[1] but for the web. Imagine creating your own command palette/context menu for any web page. ChatGPT really opened up a lot of mind blowing possibilities and the speed of innovation in this space makes me both excited and anxious.

Now if the Chrome store stops taking 3-4 days to approve an update, that'd be great!

[1] https://sublimegpt.com


How about the inverse? Having ChatGPT be able to open a browser and perform actions (like visit a website, summarizing it, giving you the best answer, triggering actions, setting up an ads campaign, replying to comments on a social media platform, etc). Then you don’t even need to open a browser window, the agent can do it for you headless. You only need to tell it to do it via chat. Kind of like on-demand, chat-triggered selenium tests.


> How about the inverse?

Having GPT fill in (or 'out', if you prefer) the myriad of web-forms I'm currently wrestling with as a job-seeker would be amazing. There's only so many times each day I can copy and paste from my CV (résumé) without turning to drink.


Sure, wire a language model to the internet and allow it to run arbitrary code. What could possibly go wrong!


I think https://uilicious.com is trying to do something like that. Haven’t tried it yet but they market themselves as “GPT writes selenium tests for you”


Cool. I wonder if there’s going to be a marketplace for ChatGPT/LLM tools.

Then you download/subscribe/connect your LLM interface, to your tools. I guess that’s kind of like Slack.


I think that's what Langchain is trying to do. You can use Zapier's natural language actions with Langchain to connect with thousands of services.


Is the webpage content passed to ChatGPT, or is this more intended to be a way to easily use chatgpt?

On the first part: I've been trying to build a tool that parses webpages using ChatGPT, but I'm struggling to figure out the best way to pass the website content over. Some options I have tried:

* Raw HTML - expensive, and in a lot of cases doesn't fit in prompt input

* OCR - works better than I would have expected, but can struggle with certain fonts, and a lot of the webpage structure is lost



Let me know if you got it working. I'm looking for such a thing too!

Maybe stripping the styling and Javascript from webpages would work? Did you do the OCR as part of the complete model or did you make it a separate step? Machine learning is usually much better in one step.


I did OCR as a separate step (essentially 1. load webpage, 2. screenshot, 3. ocr, 4. ocr output + question into chatgpt). What does it mean to do it all as one step / how would I got about doing that with ChatGPT?

For more context: I have this setup as an api that I feed url + typescript definitions to, and have chatgpt output information from the website in the specified typescript definition.

For example, I can use {product_price: float, product_name: str} + a url as the input, and fairly accurately get product price info across ALL product websites. It's kind of amazing that it's able to do this much just based upon the typescript variable names + raw OCR output.


> What does it mean to do it all as one step / how would I got about doing that with ChatGPT?

Wait till they make the image input available via the API, I guess


That makes sense, and was my plan, but the costs for chat-gpt-4 are a bit higher than is economically viable for most of my use cases.


have you already tried this: https://github.com/mozilla/readability ?


https://github.com/Nemoden/gogpt

https://github.com/NotBrianZach/bza (my concept, wip, read along repl as opposed to io focused cli tool)


Fascinating stuff, thank you for sharing.

You could create a graph of the intersections/references of meaning across different books. Those could represent an external memory for the agent/LLM, that it can retrieve/navigate via prompts.


my brother thought something like that might be useful for playing dnd with it.

he says it tends to lose character cohesion as conversation goes on

and of course obviously could be useful if a character shows up in a scene it just looks up their wiki entry essentially

sounds complicated lol

i just wanna read math book with it

i could imagine it would be fun to create a wiki with friends and then like randomly roll characters into your session from your shared universe or something

a lot of possibilities


This looks great. However, after generting an API key and providing it to chatblade, I get the following error:

openai.error.AuthenticationError: Incorrect API key provided: user@dom***.tld. You can find your API key at https://platform.openai.com/account/api-keys.

That is kind of weird, because the email given in that message looks valid, but does not match my OpenAI account name. Is that email encoded in the key? If so, apparently decoding worked, so why should the key be invalid?

Am I doing something wrong here, or is something round the API key stuff broken right now?


It looks like user@dom**.tld is actually what you set as your key.

I can generate the same error by setting

OPENAI_API_KEY="this is wrong"; chatblade test

openai.error.AuthenticationError: Incorrect API key provided: this is *rong. You can find your API key at https://platform.openai.com/account/api-keys.

if you run

echo $OPENAI_API_KEY

you should see your key which starts with sk-......... If not thats where your issue is


That is what is strange about it, OPENAI_API_KEY is set correctly, and start with sk-

So I wonder where it is getting this email from.


can you try:

curl https://api.openai.com/v1/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{ "model": "text-davinci-003", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0 }'


Yes, this works.

So my api key is valid. But something in chatblade or the python packages it depends on trashes the input I provide, and replaces it with an email address of mine. Sounds weird, but is apparently true.


Its not doing anything special that could "trash" the input. In fact no other env variables are read at all. So the fact that you are seeing your email, is a pretty strong indication that it is being set by you somewhere. Where else could it even get it from?

An other option is that you passed your email as a parameter mistakingly (which takes precedence over the env variable)

But the code is really pretty simple. https://github.com/npiv/chatblade/blob/4ce28739ca7ada1611029...


Found it! I need to set NETRC=/dev/null. It appears the request library is trying to grab auth info from .netrc, and in my case, picks the default entry. Why it is doing that despite an api key being provided is unclear.


The openapi library seems to use requests incorrectly.

> If no authentication method is given with the auth argument, Requests will attempt to get the authentication credentials for the URL’s hostname from the user’s netrc file. The netrc file overrides raw HTTP authentication headers set with headers.

Source: https://docs.python-requests.org/en/latest/user/authenticati...


I know, I took a look at the code.

I even replaced get_openai_key(params) with a hardcoded

  return "sk-redacted"
and still no luck. I guess the bug must be in the openai python package, but I cant find it either. However, rest assured I am not providing this email anywhere manually...


Has anyone created a REPL style command line interface for ChatGPT? So that it runs in the terminal instead of the browser?

Edit: just saw on another post aichat - https://github.com/sigoden/aichat/



$ cat ~/.config/openai/completions.json ~/.local/bin/completions { "model": "text-davinci-003", "max_tokens": 1024 } #!/bin/sh jq --rawfile prompt /dev/stdin '.prompt = $prompt' \ ${XDG_CONFIG_HOME:-$HOME/.config}/openai/completions.json | curl --silent https://api.openai.com/v1/completions \ --header "Authorization: Bearer $OPENAI_API_KEY" \ --header "Content-Type: application/json" --data-binary @- | jq -r '.choices[].text'


Well why use jq? you could decompose that into standard unix commands as well :)

The main itch I wanted to scratch for my own exploration with chatgpt was that I found myself doing a lot of curl requests, and then after a few iterations I would come up with one that worked well. The next step was to reproduce that last result (without ideally hitting the openai servers again) and I wanted to pipe it to the next part of my chain.

This project kind of grew out of that. Every time I had more than 2 pipes I created a new "ease of life" parameter.

Although it is possible (and likely) that your working memory is far greater than mine to come up with a command like that.


Sorry, I was not trying to belittle your effort, not at all. In fact, its sort of the other way around. You inspired me enough today (basically because I had to deep-dive and try to debug a problem which turned out to be an openai python bug) to realize how simple it actually is to use the completions API. Also, recently upgraded to Debian Bookworm, I was greeted by the new future that pip install refuses to do what it used to do, forcing you to create a venv. So I learnt about pipx, and realized this is getting a bit out of hand, esp. because the bug I was tracing ended up being somewhere deep in the dependencies of the tool you wrote. Remembering KISS, I went back to shell.

I am sure I could encode stuff with plain other tools as well, but jq is actually handy for escaping json strings. And since it can read variable content from stdin, I was a happy man. Even with decently working emacs integration now.

But again, thanks for writing this. I have both now, and will happily steal ideas from chatblade!


No offense taken at all :) these are some interesting times we live in with the power chatgpt gives us.

The dream is ultimately to leverage chatgpt as a fuzzy text assistant to 10x productivity and I think combining the unix CLI which is optimized for text is the best way to do so.

It is also one of the great powers of the unix CLI that there are many roads that lead to rome.


In Emacs: C-u M-| completions RET


Hacking on something similar, but specifically for operating on source files https://github.com/icholy/codegpt (it's in a very rough state)


I'm also developing something similar, but with a REPL style approach: https://github.com/marcolardera/chatgpt-cli


Shell Genie is my favorite. It actually runs the commands if you want.

https://github.com/dylanjcastillo/shell-genie


Nice!, piping from and to chatgpt is really powerful.

If you use tmux, you can pipe in `tmux capture-pane -p -S -` to ask questions about commands and outputs you have just run in your shell.

I use a small script that does that, but will probably replace it with chatblade

script: https://gist.github.com/kinfolk0117/7177964818f46407d4c45792...


Nice, will try this out. The ascii formatting looks good on this one

I made something quite similar, this can also run commands and has syntax highlighting

https://github.com/lennardv2/hey-chatgpt-cli


If I used this in interactive mode, and generate a code snippet, then try to copy it, it will have | the bounding box and the beginning and end of lines |


Is there a similar tool that works for a chatgpt plus account?


The $20/mo plus only gets you features that you can access in the web interface. It is independent from the API usage that bills by the query. Anything you can get from the API, you can get without paying for plus.


There have been addons that were able to use the web interface to get authorization (ex: ChatGPT4Google). I was hoping some similar session authentication and cache and make them available in terminal


Can't access the GPT-4 model through the API yet


Maybe you already did that, just reminder for those who don't know - you need to apply for API access for gpt-4. I did that and was granted it after about 2 days.


Best cli gpt tool, I've seen, so far. Thank you very much for this.


Piping prompt is an great use case, that makes a lot of sense actually. Love it.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: