Let an AI chatbot do the work
Translation at Your Command
Because users communicate with the AI back end via questions as text blocks instead of differently named API calls, you can now easily build more specialized tools that follow the pattern of Listing 2. How about a translation chatbot that translates texts from different languages into French? Listing 4 reads texts and sends them to the API with the instruction to "Translate to French" in the prompt.
Listing 4
french.go
package main import ( "bufio" "os" ) func main() { ai := NewAI() ai.init() scanner := bufio.NewScanner(os.Stdin) text := "" for scanner.Scan() { text += scanner.Text() } ai.printResp("Translate to French:\n" + text) }
Because the server can parse requests in many different languages, the API request does not even need to specify the source language of the provided text to be translated. The AI discovers this automatically on reading the question. Figure 7 shows that the electronic brain translates questions from German and English tourists concerning the route to the Eiffel Tower into very usable French. You can compile the french
binary by typing
go build french.go openai.go
This links the new program to the library from Listing 1.
In the examples so far, we've used the el cheapo mode of chatbot with MaxTokens
set to 1000
, giving us relatively brief answers. For longer texts, however, Listing 1 needs to set MaxTokens
to a higher value. At some point, though, this will lead to OpenAI wanting to be compensated for the work. You will then need to add a means of payment to the account in the form of a credit card.
Hard Limits
In summary, for the Davinci003
model that Listing 1 set as the electronic brain to use in line 30, the AI is surprisingly knowledgeable about real-world facts. However, this knowledge stops abruptly in the year 2021, because more recent events have not yet been fed in. For example, the server has to pass on questions about the Soccer World Cup 2022 in Qatar, and when asked about the Secretary of Defense, the server will respond with the appointee from the Trump administration. The next update to the model will hopefully get it up to speed with current events.
Disturbing Worlds
The AI behind ChatGPT can understand texts, analyze problems, answer questions, and produce output. But it is also capable of image processing. For example, using the API, it can analyze uploaded images, assign them to a category, or subject them to amazing transformations.
For example, Listing 5 runs a curl
command to contact the OpenAI API endpoint images/variations
. The back end then goes ahead and disturbingly modifies the original photo of a Wiener schnitzel that I cooked myself [7]. It is important to note that this particular end point only accepts square photos that are in PNG format and are no larger than 4MB.
Listing 5
var.sh
curl https://api.openai.com/v1/images/variations \ -H "Authorization: Bearer sk-XXXXXXXXXXXXX" \ -F image='@test.png' -F n=3 -F size="1024x1024"
To use it, I spun up the trusted convert
tool from the ImageMagick collection to reformat my schnitzel photo to create a PNG image measuring 1000x1000 pixels, using the -crop
and -resize
options. When called with a valid API token, the curl
command – which parses and uploads the test.png
file – returns three different URLs in the JSON response. Each of them results in a photo variation generated from the original, which curl
can subsequently retrieve from the server and store on the local drive.
Figure 8 shows the uploaded original, and Figure 9 shows one of the three variants OpenAI offered for download. You can see that the schnitzel is now on a different plate and surrounded by a light brown sauce. Next to the plate there is a beer glass full of salad. And instead of good old American India Pale Ale, you get what looks like a sake rice wine bottle top left.
On closer inspection, even the schnitzel is no longer the original. Instead, the algorithm used by the AI seems to have combined my photo with one from its archive, probably from a Japanese tonkatsu restaurant. We live in amazing times.
Infos
- ChatGPT: https://openai.com/blog/chatgpt/
- ELIZA: https://en.wikipedia.org/wiki/ELIZA
- "Collaborative Creative Writing with OpenAI's ChatGPT": https://andrewmayneblog.wordpress.com/2022/11/30/collaborative-creative-writing-with-openais-chatgpt/
- "How Kindle novelists are using ChatGPT": https://www.theverge.com/23520625/chatgpt-openai-amazon-kindle-novel
- Retrieving an API key for ChatGPT: https://beta.openai.com/account/api-keys
- OpenAI price list: https://openai.com/api/pricing/
- The author making Wiener schnitzel: https://www.youtube.com/watch?v=88HkqLmx07o
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.