Created
March 20, 2023 18:12
-
-
Save greenido/32fe7400a198e69163426da7640ca0c7 to your computer and use it in GitHub Desktop.
An example on how to leverage OpenAI API for image recognition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
const API_KEY = 'your_api_key_here'; | |
const API_URL = 'https://api.openai.com/v1/'; | |
async function recognizeImage(image_url) { | |
// We are passing in a URL of an image as data and making a POST | |
// request to the OpenAI API, and the response will contain information | |
// about what is in the picture. | |
const response = await axios.post(`${API_URL}images/gpt3-davinci-002/predict`, { | |
data: { | |
image: image_url, | |
}, | |
}, { | |
headers: { | |
'Content-Type': 'application/json', | |
'Authorization': `Bearer ${API_KEY}`, | |
}, | |
}); | |
const output = response.data.data[0].output; | |
console.log(output); | |
} | |
recognizeImage('https://example.com/image.jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment