Get Started
1. Create a index.html
Create a new directory for your project and navigate to that directory. Initialize a new HTML file, like a index.html
touch index.html
2. Load CDN
Load the freegptjs library from jsDelivr:
<script src="https://cdn.jsdelivr.net/gh/ashishagarwal2023/freegptjs@1.0.2/src/freegpt.min.js"></script>
Prefer to load the library from head and use in body.
Example Code for index.html:
<!DOCTYPE html> <html lang="en"> <head> <!-- Load from jsDelivr --> <script src="https://cdn.jsdelivr.net/gh/ashishagarwal2023/freegptjs@1.0.2/src/freegpt.min.js"></script> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My demo page</title> </head> <body> </body> </html>
Usage
How to use?
Use the await with gpt.ask(query)
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Load from jsDelivr -->
<script src="https://cdn.jsdelivr.net/gh/ashishagarwal2023/freegptjs@1.0.2/src/freegpt.min.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My demo page</title>
</head>
<body>
<script>
const response = await gpt.ask("Hello there, chatgpt!"); // bot will respond in few secs
alert(response);
</script>
</body></html>