Session API
api_create_session(runner_id, database_instance, endpoints, runner_args)
Creates a new session for a specific runner.
This function creates a new session by calling the Session
constructor with the provided arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The unique identifier of the runner for which the session is to be created. |
required |
database_instance |
Any
|
The database instance to be used for the session. |
required |
endpoints |
list
|
A list of endpoints for the session. |
required |
runner_args |
dict
|
A dictionary of arguments for the runner. |
required |
Returns:
Type | Description |
---|---|
Session
|
Session |
Source code in moonshot/src/api/api_session.py
api_delete_session(runner_id)
Deletes the session for a specific runner.
This function deletes the session for the runner identified by the given runner_id. It calls the
Session.delete
method with the runner's database instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the session needs to be deleted. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the session is deleted successfully. |
Source code in moonshot/src/api/api_session.py
api_get_all_chats_from_session(runner_id)
Retrieves all chat messages from a specific session.
This function retrieves all chat messages from the session associated with the specified runner ID.
It calls the Session.get_session_chats
method with the runner's database instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The unique identifier of the runner for which the chat messages are to be retrieved. |
required |
Returns:
Type | Description |
---|---|
dict | None
|
dict | None: A dictionary containing all chat messages if available, otherwise None. |
Source code in moonshot/src/api/api_session.py
api_get_all_session_metadata()
Retrieves metadata for all sessions.
This function retrieves the metadata for all active sessions by calling the api_get_available_session_info
method.
Returns:
Name | Type | Description |
---|---|---|
list |
list[dict]
|
A list containing the metadata for all active sessions, sorted by created datetime in descending order. |
Source code in moonshot/src/api/api_session.py
api_get_all_session_names()
Retrieves a list of all session names.
This function calls the api_get_available_session_info
method to obtain the available session information
and returns a list of session names.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of strings, each denoting a session name. |
Source code in moonshot/src/api/api_session.py
api_get_available_session_info()
Retrieves the IDs and database instances of runners with active sessions.
This function retrieves the IDs and database instances of runners with active sessions by querying all runners and checking if each runner has an active session. It returns a tuple containing a list of runner IDs and a list of corresponding session metadata for runners with active sessions.
Returns:
Type | Description |
---|---|
list
|
tuple[list[str], list[str]]: A tuple containing a list of runner IDs and a list of corresponding session |
list
|
metadata for runners with active sessions. |
Source code in moonshot/src/api/api_session.py
api_load_session(runner_id)
Loads the session details for a specific runner.
This function calls the Session.load
method to retrieve the session details associated with the
specified runner ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The unique identifier of the runner for which the session details are to be loaded. |
required |
Returns:
Type | Description |
---|---|
dict | None
|
dict | None: A dictionary containing the session details if available, otherwise None. |
Source code in moonshot/src/api/api_session.py
api_update_attack_module(runner_id, attack_module_id)
Updates the attack module for a specific runner.
This function updates the attack module for a specific runner identified by the given runner_id. It calls the
Session.update_attack_module
method with the runner's database instance,
runner_id, and the new attack_module_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the attack module needs to be updated. |
required |
attack_module_id |
str
|
The new attack module to be set for the runner. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the attack module is updated successfully. |
Source code in moonshot/src/api/api_session.py
api_update_context_strategy(runner_id, context_strategy)
Updates the context strategy for a specific runner.
This function updates the context strategy for a specific runner identified by the given runner_id. It calls the
Session.update_context_strategy
method with the runner's database instance,
runner_id, and the new context_strategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the context strategy needs to be updated. |
required |
context_strategy |
str
|
The new context strategy to be set for the runner. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the context strategy is updated successfully. |
Source code in moonshot/src/api/api_session.py
api_update_cs_num_of_prev_prompts(runner_id, num_of_prev_prompts)
Updates the number of previous prompts used in a context strategy for a specific runner.
This function updates the number of previous prompts used in a context strategy for a specific runner identified by
the given runner_id. It calls the Session.update_cs_num_of_prev_prompts
method with the runner's database
instance, runner_id, and the new num_of_prev_prompts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the number of previous prompts needs to be updated. |
required |
num_of_prev_prompts |
int
|
The new number of previous prompts to be set for the runner. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the number of prompts for context strategy is updated successfully. |
Source code in moonshot/src/api/api_session.py
api_update_metric(runner_id, metric_id)
Updates the metric for a specific runner.
This function updates the metric for a specific runner identified by the given runner_id. It calls the
Session.update_metric
method with the runner's database instance,
runner_id, and the new metric_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the metric needs to be updated. |
required |
metric_id |
str
|
The new metric to be set for the runner. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the metric is updated successfully. |
Source code in moonshot/src/api/api_session.py
api_update_prompt_template(runner_id, prompt_template)
Updates the prompt template for a specific runner.
This function updates the prompt template for a specific runner identified by the given runner_id. It calls the
Session.update_prompt_template
method with the runner's database instance,
runner_id, and the new prompt_template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the prompt template needs to be updated. |
required |
prompt_template |
str
|
The new prompt template to be set for the runner. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the prompt template is updated successfully. |
Source code in moonshot/src/api/api_session.py
api_update_system_prompt(runner_id, system_prompt)
Updates the system prompt for a specific runner.
This function updates the system prompt for a specific runner identified by the given runner_id. It calls the
Session.update_system_prompt
method with the runner's database instance,
runner_id, and the new system_prompt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runner_id |
str
|
The ID of the runner for which the system prompt needs to be updated. |
required |
system_prompt |
str
|
The new system prompt to be set for the runner. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
The status on whether the system prompt is updated successfully. |