Skip to content

Instantly share code, notes, and snippets.

@greenido
Created March 20, 2023 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenido/32fe7400a198e69163426da7640ca0c7 to your computer and use it in GitHub Desktop.
Save greenido/32fe7400a198e69163426da7640ca0c7 to your computer and use it in GitHub Desktop.
An example on how to leverage OpenAI API for image recognition
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