Small example for generating responses using the ChatGPT library runs in a web browser using Javascript great as it doesn t require any installation and is a fun resource to add something extra document body style height 300pt ref https platform openai com docs api reference chat curl https api openai com v1 chat completions H Content Type application json H Authorization Bearer OPENAI API KEY d model gpt 3 5 turbo messages role user content Hello useful curl converter https curlconverter com javascript const OPENAI API KEY sk G5Q3AsMTTBoxxxxxxxxxxxxF6vYn const response await fetch https api openai com v1 chat completions method POST headers Content Type application json Authorization Bearer OPENAI API KEY body JSON stringify model gpt 3 5 turbo temperature 1 9 n 1 messages role user role assistant content Tell me a joke that includes frogs const jsonResponse await response json console log jsonResponse Create div and put the reponse on the screen for let n 0 n jsonResponse choices length n let div document createElement div document body appendChild div div style fontSize 14pt div innerHTML Response jsonResponse choices n message content hr
s method POST headers Content Type application json Authorization Bearer OPENAI API KEY body JSON stringify model gpt 3 5 turbo temperature 1 9 n 1 messages role user role assistant content Tell me a joke that includes frogs const jsonResponse await response json console log jsonResponse Create div and put the reponse on the screen for let n 0 n jsonResponse choices length n let div document createElement div document body appendChild div div style fontSize 14pt div innerHTML Response jsonResponse choices n message content hr