A I Chat Bot Interface - Copy this Html, Tailwind Component to your project
Tôi tài liệu để connect API Google Gemini với model: "gemini-1.5-flash" như sau: Install the Gemini API SDK To use the Gemini API in your own web app, import @google/generative-ai: <script type="importmap"> { "imports": { "@google/generative-ai": "https://esm.run/@google/generative-ai" } } </script> Import the library Import and configure the Google Generative AI library. <html> <body> <!-- ... Your HTML and CSS --> <!-- Import @google/generative-ai, as shown above. --> <script type="module"> import { GoogleGenerativeAI } from "@google/generative-ai"; // Fetch your API_KEY const API_KEY = "..."; </script> </body> </html> Use Node.js bellow: Build an interactive chat You can use the Gemini API to build interactive chat experiences for your users. Using the chat feature of the API lets you collect multiple rounds of questions and responses, allowing users to step incrementally toward answers or get help with multipart problems. This feature is ideal for applications that require ongoing communication, such as chatbots, interactive tutors, or customer support assistants. The following code example shows a basic chat implementation: // Make sure to include these imports: // import { GoogleGenerativeAI } from "@google/generative-ai"; const genAI = new GoogleGenerativeAI(process.env.API_KEY); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); const chat = model.startChat({ history: [ { role: "user", parts: [{ text: "Hello" }], }, { role: "model", parts: [{ text: "Great to meet you. What would you like to know?" }], }, ], }); let result = await chat.sendMessage("I have 2 dogs in my house."); console.log(result.response.text()); result = await chat.sendMessage("How many paws are in my house?"); console.log(result.response.text());