Gemini is a powerful text generation tool provided by Google that enables you to create diverse content using various input methods. This repository demonstrates how to leverage the Gemini API for different scenarios.
When the prompt input includes only text, you can use the gemini-pro
model. To generate text output, run:
nodemon index.js
Gemini also provides a multimodal model (gemini-pro-vision), allowing input of both text and images. Ensure you review the image requirements for prompts. To generate text output from text-and-image input, run:
nodemon app.js
Gemini facilitates the creation of freeform conversations across multiple turns. The SDK simplifies the process by managing the conversation state, eliminating the need to store the history manually.
To build a multi-turn conversation using the gemini-pro model, initialize the chat by calling startChat(). Then, use sendMessage() to send a new user message, which will also append the message and the response to the chat history.
There are two possible roles associated with the content in a conversation:
user: The role providing the prompts (default for sendMessage calls). model: The role providing the responses. This role can be used when calling startChat() with existing history. To build a multi-turn conversation, run:
nodemon server.js
Feel free to explore and adapt the provided examples to suit your specific use case.
-
You can customize the chat behavior by modifying the generationConfig and safetySettings in the script:
-
generationConfig: Adjust temperature, topK, topP, and maxOutputTokens for model output.
-
safetySettings: Configure safety settings for blocking harmful content.
nodemon prompt.js
- Node.js
- Gemini API Key (set as an environment variable)
This project is licensed under the MIT License.