Spaces:
Runtime error
Runtime error
Download application/static/js/components/request.js from yasirme/ChatBot-UI-With-API: direct link, hf CLI and curl.
- Browser
- Download file 970 Bytes
-
https://huggingface.co/spaces/yasirme/ChatBot-UI-With-API/resolve/main/application/static/js/components/request.js
- Command line
-
hf download hf://spaces/yasirme/ChatBot-UI-With-API/application/static/js/components/request.js
-
curl -L -o request.js https://huggingface.co/spaces/yasirme/ChatBot-UI-With-API/resolve/main/application/static/js/components/request.js
970 Bytes
| class Request{ | |
| constructor(){ | |
| } | |
| async request(method,url,headers={},payload=null,stream=false){ | |
| try { | |
| const response = await fetch(url,{ | |
| method: method, | |
| headers: headers, | |
| body: payload | |
| }) | |
| if(stream && response.ok){ | |
| return this.handleStream(response) | |
| } else{ | |
| return response | |
| } | |
| } catch (error) { | |
| return error | |
| } | |
| } | |
| async *handleStream(response){ | |
| const reader = response.body.getReader(); | |
| const decoder = new TextDecoder(); | |
| while(true){ | |
| const {done,value} = await reader.read() | |
| if(done){ | |
| break | |
| } | |
| const chunk = decoder.decode(value,{stream:true}) | |
| yield chunk | |
| } | |
| } | |
| } | |
| const requests = new Request() | |
| export default requests |