This is an asynchronous function called 'callCHATGPT()' that sends a POST request to a specified API endpoint and retrieves data from the response.

The function first sets the URL and the API version. It then retrieves the input prompt from an HTML input element with the ID 'prompt' and creates a JSON object with the prompt as its value.

The function then uses the fetch() method to send a POST request to the specified URL with the JSON object as the request body. If the response status is 200, the function retrieves the response body using the getReader() method and decodes the retrieved data into a string using the TextDecoder() method.

If the response status is not 200, the function displays an error message in the HTML element with the ID 'result'.

使用JavaScript异步函数调用CHATGPT API 获取数据

原文地址: https://www.cveoy.top/t/topic/mx61 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录