In this tutorial we're going to create a Golang service that communicates with Chat GPT API.
For implementing solution we need to have:
- API Key to Chat GPT API and at the moment Chat GPT doesn't provide free trial, so you'll have to setup your Open API account and pay X per token. But for a pet project it's quite fair price in my opinion.
- Golang installed.
Essentially to get familiar with Chat GPT API we'll try to create a smart dictionary. As an input we'll send a http request with a lexical item and in response we get the meaning, examples of usages. Architecture will consist of 2 components:
- Backend - Golang application with Echo web framework.
- Chat GPT API that Open AI provides.
- Specify env variables
CHAT_GPT_API_URL
andCHAT_GPT_API_KEY
- Start the server
go run ./cmd/main.go
- Test with curl
curl localhost:8080/v1/translations/feasible
Response example:
{
"lexicalItem":"feasible",
"meaning":"possible to do easily or conveniently",
"example":"Given our limited resources, it may not be feasible to launch a new product at this time."
}
- introduction to openai api: https://platform.openai.com/docs/introduction
- quick start with python: https://platform.openai.com/docs/quickstart?context=python
- check token price: https://platform.openai.com/tokenizer
- chat gpt api pricing: https://openai.com/pricing