Docs
ChatGemini
ChatGemini
Use different google's Gemini's text generation models by following these instructions:.
Installation
Install peer dependencies:
Add Environment Variables
Copy the code
Add the following code to your utils/chatGemini.ts
file:
Usage
Initialize client
Initialize the ChatGemini client.
Simple Chat
Sample chat with a simple single prompt.
Multi Conversational chat
Sampe chats involving addition of chat history.
Defining Context and other optional parameters
Streaming text
Sample example of creating and handling stream responses.
Counting Tokens
Sample example of counting input tokens, including prompts, and chat histories.
Props
chat
Prop | Type | Description | Default |
---|---|---|---|
prompt | string | Prompt provided by user. | "" |
context | string? | Additional context user wants to provide. | "" |
stream | boolean? | If yes, there will be stream output of texts. | false |
outputFormat | string? | Particular format in which the user wants their output. | "" |
chatHistory | optional | Conversational history. | "" |
systemInstruction | RequestOptions? | Any specific instruction to the system user wants to feed. | "" |
options | RequestOptions? | Additional args as per Google Gemini docs. |
chatWithHistory
Prop | Type | Description | Default |
---|---|---|---|
prompt | string | Prompt provided by user. | "" |
context | string? | Additional context user wants to provide. | "" |
stream | boolean? | If yes, there will be stream output of texts. | false |
outputFormat | string? | Particular format in which the user wants their output. | "" |
chatHistory | optional | Conversational history. | "" |
systemInstruction | RequestOptions? | Any specific instruction to the system user wants to feed. | "" |
maxOutputTokens | number? | Specifying the limitation of output tokens. | "" |
options | RequestOptions? | Additional args as per Google Gemini docs. |
countChatHistoryTokens
Prop | Type | Description | Default |
---|---|---|---|
chatHistory | required | Conversational history. | "" |
options | RequestOptions? | Additional args as per Google Gemini docs. |
countTokens
Prop | Type | Description | Default |
---|---|---|---|
prompt | string | Prompt provided by user. | "" |
options | RequestOptions? | Additional args as per Google Gemini docs. | |
context | string? | Additional context user wants to provide. | "" |
outputFormat | string? | Particular format in which the user wants their output. | "" |
Credits
This component is built on top of Gemini AI's node sdk