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
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.