This article will guide you through creating your first application that uses AI, to see just how simple yet powerful it is.
We will create an application that takes user input and generates a short poem using that input. Without AI, this would be a very complex task.
For this article we’ll create the application in Go and use one of OpenAI’s GPT models but you can use a similar approach in any language.
Step 1
Create a basic app to get user input.
Create a new Go application and add the following code to the main() function to get user input.
// Read user input
var input string
println("Enter a word to create a poem: ")
_, err := fmt.Scanln(&input)
if err != nil {
fmt.Println(err)
}
Step 2
Add an OpenAI library.
Instead of writing all the code to interact with OpenAI’s APIs ourselves, we will use a Go module called go-openai. This module saves us from rewriting a lot of communication code with OpenAI’s API and allows us to reuse it in multiple projects.
Add the library using the following terminal command
go get github.com/sashabaranov/go-openai
Step 3
Now, let’s get to the interesting part! We will add the code that generates the poem for us.