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 G5Q3Axxxxxxxxxxxxxxxxx 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 messages role user content Tell me a joke that includes chickens const jsonResponse await response json console log jsonResponse Create div and put the reponse on the screen let div document createElement div document body appendChild div div style fontSize 14pt div innerHTML Response jsonResponse choices 0 message content
onse 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 messages role user content Tell me a joke that includes chickens const jsonResponse await response json console log jsonResponse Create div and put the reponse on the screen let div document createElement div document body appendChild div div style fontSize 14pt div innerHTML Response jsonResponse choices 0 message content