Sets the model for the AI session. The model specifies which AI model should be used during the session, enabling different types of behavior or capabilities.
| Name | Type | Description |
|---|---|---|
data |
string |
The model to be set. It must be a string representing the AI model. |
id |
string? |
(Optional) The session ID. If omitted, the currently selected session will be used. |
- This function does not return any value.
- The method checks if
datais a valid string. If it is, it will be set as the model for the session. - It stores the model in the session history using
#_insertIntoHistory. - An event is emitted (
setModel) with the model name and the session ID.
Retrieves the model set for the AI session. If no model is set, it returns null.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID. If omitted, the currently selected session will be used. |
string: The model set for the session if available.null: If no model is set for the session.
- The method retrieves the session history data using the provided
idor the currently selected session ID. - It checks if a model is set and returns its value. If no model is found, it returns
null.
Aqui está a documentação em Markdown para o método getModels, seguindo o mesmo estilo organizado e claro:
Retrieves a list of available models for the AI session, optionally paginated.
| Name | Type | Default | Description |
|---|---|---|---|
pageSize |
number |
50 |
The number of models to retrieve per page. |
pageToken |
string | null |
null |
Token for retrieving the next page of models. If omitted, uses internal token. |
Array: A list of models retrieved from the API.
Error: If no model list API handler function (#_getModels) is defined.
- Internally calls a user-defined private method
#_getModelswith the current API key, the page size, and a page token. - If
pageTokenisnull, it will fallback to the value inthis._nextModelsPageToken. - If the model-fetching logic is not configured (
#_getModelsis not a function), it throws an error.
const models = session.getModels(20);
// or
const nextPageModels = session.getModels(20, "eyJwYWdlIjoxfQ==");Note: This method assumes that an external function
#_getModels(apiKey, pageSize, pageToken)is properly implemented to fetch model data.
Retrieves the list of models for the AI session.
- None – This method does not take any parameters.
| Type | Description |
|---|---|
Array |
The list of models available for the AI session. |
const models = session.getModelsList();
console.log(models); // Outputs the list of modelsRetrieves model data from the list of models by searching for a specific model ID.
| Name | Type | Description |
|---|---|---|
id |
string |
The model data ID to search for in the models list. |
| Type | Description |
|---|---|
| `Object | null` |
const modelData = session.getModelData('modelId123');
if (modelData) {
console.log(modelData); // Outputs the model data if found
} else {
console.log('Model not found');
}Checks if a model exists in the list of models by searching for a specific model ID.
| Name | Type | Description |
|---|---|---|
id |
string |
The model ID to check for in the models list. |
| Type | Description |
|---|---|
boolean |
true if the model exists, false otherwise. |
const isModelExists = session.existsModel('modelId123');
if (isModelExists) {
console.log('Model exists!');
} else {
console.log('Model not found.');
}Sets the maximum number of output tokens for a given AI session. This method allows developers to control the maximum output length for the AI's responses.
| Name | Type | Description |
|---|---|---|
value |
number |
The maximum number of output tokens to set. Must be a finite, valid number. |
id |
string? |
(Optional) The session ID to operate on. If omitted, the currently selected session will be used. |
Error: If thevalueis not a valid number (NaN or infinite values are invalid).
void: This method does not return a value.
- Validates the provided
valueto ensure it is a finite number. - If valid, updates the session history with the new
maxOutputTokenssetting. - Emits the
setMaxOutputTokensevent with the new token value and the session ID.
Gets the maximum number of output tokens for a given AI session. This method allows developers to retrieve the current token limit for the AI's responses.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID to operate on. If omitted, the currently selected session will be used. |
number | null: The maximum output tokens value if it is set. If not set, returnsnull.
- Checks the session's history for the
maxOutputTokensvalue. - If the value exists and is a valid number, it returns the token limit.
- If the value is not set or is invalid, it returns
null.
Sets the temperature setting for a given AI session. The temperature value controls the randomness of the AI's responses, with higher values generating more random outputs and lower values making the responses more deterministic.
| Name | Type | Description |
|---|---|---|
value |
number |
The temperature value to be set. Must be a finite, valid number. |
id |
string? |
(Optional) The session ID to operate on. If omitted, the currently selected session will be used. |
Error: If thevalueis not a valid number (NaN or infinite values are invalid).
void: This method does not return a value.
- Validates the provided
valueto ensure it is a finite number. - If valid, updates the session history with the new
temperaturesetting. - Emits the
setTemperatureevent with the new temperature value and the session ID.
Retrieves the temperature setting for a given AI session. The temperature controls the randomness of the AI's responses. If not set, it returns null.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID to operate on. If omitted, the currently selected session will be used. |
number | null: The temperature value if set, otherwisenull.
- Retrieves the
temperaturevalue from the session history. - If the
temperaturevalue is not set, it returnsnull.
Sets the top-p (nucleus sampling) value for a given AI session. The top-p value controls the diversity of the output by considering the smallest set of tokens whose cumulative probability is greater than the top-p value.
| Name | Type | Description |
|---|---|---|
value |
number |
The top-p value to be set. It must be a finite number. |
id |
string? |
(Optional) The session ID to operate on. If omitted, the currently selected session will be used. |
void: This function does not return a value.
- Validates that
valueis a finite number. - Sets the top-p value in the session's history.
- Emits an event named
setTopPwith thevalueandselectedId.
- Throws an error if the
valueis not a valid number.
Retrieves the top-p (nucleus sampling) value for a given AI session. The top-p value controls the diversity of the output by considering the smallest set of tokens whose cumulative probability is greater than the top-p value.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID to retrieve the top-p value for. If omitted, the currently selected session will be used. |
number | null: The top-p value if it is set, ornullif not set.
- Retrieves the
topPvalue from the session's history. - If the value exists and is a valid number, it will return the value.
- If no valid value is found, it will return
null.
Sets the top-k value for a given AI session. The top-k value determines how many of the highest probability tokens are considered when generating output.
| Name | Type | Description |
|---|---|---|
value |
number |
The top-k value to be set. Must be a valid number. |
id |
string? |
(Optional) The session ID to set the top-k value for. If omitted, the currently selected session will be used. |
void: This method does not return a value.
- Throws an error if the provided
valueis not a valid number.
- Sets the
topKvalue in the session's history for the specified session. - Emits a
setTopKevent with the provided value and the session ID.
Retrieves the top-k value for a given AI session. The top-k value represents the number of highest probability tokens considered during output generation.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID to retrieve the top-k value for. If omitted, the currently selected session will be used. |
number | null: Returns thetopKvalue if set for the session, ornullif the top-k value is not set.
- Retrieves the
topKvalue from the session's history for the specified session.
Sets the presence penalty value for a given AI session. The presence penalty influences how much the model avoids generating tokens that have appeared in the context.
| Name | Type | Description |
|---|---|---|
value |
number |
The presence penalty value to be set. Must be a valid number. |
id |
string? |
(Optional) The session ID for which to set the presence penalty. If omitted, the currently selected session will be used. |
void: This function does not return a value.
- Sets the
presencePenaltyin the session's history for the specified session.
Retrieves the presence penalty setting for a given AI session. The presence penalty helps control how much the model avoids repeating tokens already seen in the context.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID for which to retrieve the presence penalty. If omitted, the currently selected session will be used. |
number | null: Returns the presence penalty value if set, ornullif no value is set.
- Retrieves the
presencePenaltyfrom the session's history for the specified session.
Sets the frequency penalty setting for an AI session. The frequency penalty helps to penalize models for repeating the same tokens or phrases, allowing for more diverse responses.
| Name | Type | Description |
|---|---|---|
value |
number |
The frequency penalty value to be set. This value should be a number. |
id |
string? |
(Optional) The session ID. If omitted, the currently selected session will be used. |
void: This function does not return a value.
- If the provided
valueis a valid number, the method sets thefrequencyPenaltyin the session's history. - Emits the
setFrequencyPenaltyevent with the value and selected session ID. - Throws an error if the
valueis not a valid number.
Retrieves the frequency penalty setting for an AI session. The frequency penalty is used to penalize models for repeating the same tokens or phrases, helping to ensure more varied responses.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID. If omitted, the currently selected session will be used. |
number | null: The frequency penalty value, ornullif the value is not set for the session.
- If the
frequencyPenaltyis set in the session's history, the method returns its value. - If the value is not set or not found, the method returns
null.
Sets the setting for enabling enhanced civic answers in an AI session. This setting determines whether the AI should provide enhanced civic answers, typically involving more detailed, accurate, and contextually relevant responses related to civic topics.
| Name | Type | Description |
|---|---|---|
value |
boolean |
A boolean value to enable or disable enhanced civic answers. Set to true to enable, or false to disable. |
id |
string? |
(Optional) The session ID. If omitted, the currently selected session will be used. |
- This function does not return any value.
- If the provided
valueis a boolean, the setting is updated for the specified session. - If the
valueis not a boolean, an error is thrown with the message'Invalid boolean value!'.
Gets the setting for whether enhanced civic answers are enabled in an AI session. This setting indicates whether the AI is configured to provide enhanced civic answers, which might involve more accurate or contextually relevant responses on civic topics.
| Name | Type | Description |
|---|---|---|
id |
string? |
(Optional) The session ID. If omitted, the currently selected session will be used. |
booleanif the setting is enabled or disabled (trueorfalse).nullif the setting has not been set for the session.
- If the setting for enhanced civic answers is available and is a boolean, it will be returned.
- If the setting is not available or not set, it returns
null.