Site icon Antonio Lamorgese

ChatGPT in action with CURL from command prompt

ChatGPT in action with CURL from command prompt

You can use ChatGPT from the command line by sending http requests to the OpenAI API using a utility like curl.
di Antonio Lamorgese

ChatGPT, developed by OpenAI, is a model based on artificial intelligence which returns, in the form of conversational language, a descriptive content that is coherent and compliant with what is requested by the user with a short descriptive sentence on the subject. Using ChatGPT, users can create bots that can answer questions, handle requests, and even hold more complex conversations. With ChatGPT, users can also use the command line to put their bots into action. To see ChatGPT in action you do n’t need to install any software on your computer, just click on this link and then on the “Try Chat GPT”. Once logged in, in this regard you can also use a Google or Microsoft account, if you have one, you can type your first request to send to ChatGPT and press the ENTER key. After a few seconds the bot will return the content you requested as if you had asked a real person. In this article, we’ll look at how to use CURL, from a command prompt, to put ChatGPT into action.

ChatGPT's response to receiving the message: "Hi, how are you?"
ChatGPT’s response to receiving the message: “Hi, how are you?”

What is CURL?

CURL is an open source tool, usable on any type of operating system and directly from the terminal or command prompt, which allows users to send HTTP requests to a server. It is a very powerful tool that can be used to automate various network tasks, such as sending POST requests, sending files, downloading files, and so much more. It is also a very useful tool for putting ChatGPT into action right from the command prompt.

Logically CURL is not implemented by default on any kind of operating system. Therefore you need to download and install it on your computer. In this regard, you can click on this link which will take you to the CURL home page and where you will find all the information necessary to install it on your computer. After the download and installation phase, CURL will be immediately available to send commands to any server capable of receiving http requests. Now let’s see how to send requests to ChatGPT and how to process the result returned by the OpenAI bot.

How to put ChatGPT into action with CURL

To put ChatGPT into action with CURL, you must first obtain a Secret Key. ChatGPT like all http servers to process requests made by the user needs to know who is using its artificial intelligence algorithms. Therefore you must first log into the OpenAI portal and then request your Secret Key to access its APIs.

So, as a first step, click on this link and then on the “Create New Secret Key” button. The Secret Key returned by OpenAI is one of the keys you will use to send requests to ChatGPT. Yes, you read right, one of the keys. You should know that with this procedure you can create several Secret Keys and use them all, as you like, to have the bot process your requests. After OpenAI has generated your secret key, you should copy it to your clipboard and type it into the CURL command when prompted.

secret Key generated by OpenAI
secret Key generated by OpenAI

Once you have your secret key, you can use CURL to send a POST request to ChatGPT invoking “text-davinci-003”, as the conversational text generation model, one of 4 models available. To do this, you need to run the following command from a command prompt replacing the string “YOUR_API_KEY” with your secret key that OpenAI created for you.

curl -X POST -H "Content-Type: application/json " -H "Authorization: Bearer YOUR_API_KEY" -d '{"prompt": "Hi, how are you ?"}' http://api.openai.com/v1/engines/chatbot/jobs

This command will send a POST request to the bot with the query “Hi, how are you?”. The bot will then respond, processing your request, with the most appropriate response generated in real time by ChatGPT. The content, processed as a response to your request, will be displayed in the same command prompt or terminal window.


Read more: “How to invoke OpenAI and ChatGPT with PHP


Conclusion

ChatGPT is a very powerful chatbot platform that allows users to easily build intelligent and conversational chat bots. As you could see, using CURL and the command prompt, users can also use the command line to put ChatGPT into action. In this article, we have examined how to use CURL from a command prompt and get all the information we want from ChatGPT without entering the client made available to users on the OpenAI portal . So, to sum up, using CURL, from a command prompt, you can put ChatGPT into action easily and effectively.

Antonio Lamorgese
Latest posts by Antonio Lamorgese (see all)
Exit mobile version