My howto script
2023-8-7 08:12:51 Author: gynvael.coldwind.pl(查看原文) 阅读量:11 收藏

Since I started my coding livestreams again there is one common question, which I wanted to address in this blogpost: what is this weird howto command I'm using?

$ howto convert a set of jpegs into a pdf, assume 90 dpi A4 page convert -quality 100 -density 90x90 -page A4 *.jpg output.pdf $ howto block any access to tcp port 1234 using iptables sudo iptables -A INPUT -p tcp --dport 1234 -j DROP $ howto zoom in my webcam v4l2-ctl --set-ctrl=zoom_absolute=300 $ howto encrypt a file using openssl with aes in authenticated mode openssl enc -aes-256-gcm -salt -in inputfile -out outputfile

And yes, that is just ChatGPT over API. It's actually a super simple Python script based on their examples. See for yourself:

#!/usr/bin/env python import openai import sys import os dir_path = os.path.dirname(os.path.realpath(__file__)) # !!!You need an API key!!! # https://platform.openai.com/account/api-keys with open(f"{dir_path}/api_key.txt") as f: openai.api_key = f.read().strip() arg = ' '.join(sys.argv[1:]) r = openai.ChatCompletion.create( model="gpt-3.5-turbo", #model="gpt-4", messages=[ {"role": "system", "content": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible."}, {"role": "user", "content": f"Answer with only the actual command without any intro or explanation. What is the ubuntu command line command to {arg}"} ] ) text = r["choices"][0]["message"]["content"] if text.startswith('`') and text.endswith('`'): text = text[1:-1] print(text)

Note that you both need to install the openai Python package (pip install openai) and an API key. The API is paid, but the cost is ridiculously low for using such a simple script – using it daily from the beginning of the year I haven't yet exceeded the $1 mark needed to unlock the gpt-4 model ;f. My usage for July is apparently even below 1 cent.

Now, if there is actually a better version of such a script out there – and I'm sure that's the case – feel free to let me know in the comments below.


文章来源: https://gynvael.coldwind.pl/?id=771
如有侵权请联系:admin#unsafe.sh