![chatgpt-api-logo](https://private-user-images.githubusercontent.com/36672021/280516482-56d00bfd-6bd1-44b2-ac92-c1c2eca56bac.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk1MzA3MTYsIm5iZiI6MTcxOTUzMDQxNiwicGF0aCI6Ii8zNjY3MjAyMS8yODA1MTY0ODItNTZkMDBiZmQtNmJkMS00NGIyLWFjOTItYzFjMmVjYTU2YmFjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI3VDIzMjAxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFjNzVkOTg1OWE4Njk5ODNmYWExYjIxNjQ4N2E4ZTcwZTgxNGVkNzQ1NDg5OTRhYjJhZWU1YTM4NzcxODM0NzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.che3x5aDkvnt7nyuWPEva_w73WrbQBXQB8K9rX1s3FQ)
You already know what ChatGPT is. This API is a simple implementation of the OpenAI API for GPT. In short...you can ask it questions!
Before you begin, create a new API key here. Then, just set an environment variable called CHATGPT_API_KEY
to the API key that was just generated. Then run go run main.go
.
To test the API, run the following cURL command (replace APIKey with your base64 encoded API key):
curl --request POST \
--url http://localhost:8080/askGPT \
--header 'APIKey: YOUR_BASE64_ENCODED_API_KEY_HERE' \
--header 'Content-Type: multipart/form-data' \
--form 'question=what is 2+2?'
If you don't know how to base64 encode a string, don't fear! It's really easy. Just run this:
echo $CHATGPT_API_KEY | base64