Cookbook API
api_create_cookbook(name, description, recipes)
Creates a new cookbook.
This function takes the name, description, and recipes for a new cookbook as input. It then creates a new CookbookArguments object with these details and an empty id. The id is left empty because it will be generated from the name during the creation process. The function then calls the Cookbook's create_cookbook method to create the new cookbook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the new cookbook. |
required |
description |
str
|
A brief description of the new cookbook. |
required |
recipes |
list[str]
|
A list of recipes to be included in the new cookbook. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The ID of the newly created cookbook. |
Source code in moonshot/src/api/api_cookbook.py
api_delete_cookbook(cb_id)
Deletes a cookbook based on the provided cookbook ID.
This function calls the delete
method of the Cookbook
class with the given cookbook ID. If the cookbook
is successfully deleted, the method returns True, otherwise it returns False.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cb_id |
str
|
The ID of the cookbook to delete. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the cookbook was successfully deleted. |
Raises:
Type | Description |
---|---|
Exception
|
If the deletion process encounters an error. |
Source code in moonshot/src/api/api_cookbook.py
api_get_all_cookbook()
Retrieves all available cookbooks.
This function calls the get_available_cookbooks
method of the Cookbook
class, which returns a tuple
containing a list of cookbook IDs and a list of CookbookArguments
objects. The function then returns a list
of dictionaries, each representing a cookbook.
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of dictionaries, each representing a cookbook. |
Source code in moonshot/src/api/api_cookbook.py
api_get_all_cookbook_name()
Retrieves the names of all available cookbooks.
This function calls the get_available_cookbooks
method of the Cookbook
class, which returns a tuple
containing a list of cookbook IDs and a list of CookbookArguments
objects. The function then returns the
list of cookbook IDs, which are the names of the cookbooks.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of cookbook names. |
Source code in moonshot/src/api/api_cookbook.py
api_read_cookbook(cb_id)
Retrieves a cookbook based on the provided cookbook ID.
This function reads a cookbook using the read_cookbook
method
of the Cookbook
class, and converts the returned Cookbook
object to a dictionary using its to_dict
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cb_id |
str
|
A cookbook ID. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary representing a cookbook. |
Source code in moonshot/src/api/api_cookbook.py
api_read_cookbooks(cb_ids)
Retrieves a list of cookbooks based on the provided list of cookbook IDs.
This function iterates over the list of provided cookbook IDs, reads each cookbook using the read_cookbook
method
of the Cookbook
class, and converts the returned Cookbook
objects to dictionaries using their to_dict
method.
It then returns a list of these dictionary representations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cb_ids |
conlist(str, min_length=1
|
A list of cookbook IDs. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of dictionaries representing the cookbooks. |
Source code in moonshot/src/api/api_cookbook.py
api_update_cookbook(cb_id, **kwargs)
Updates the fields of an existing cookbook with the provided keyword arguments.
This function first checks if the cookbook with the given ID exists. If it does, it updates the fields of the cookbook with the provided keyword arguments. If a field does not exist on the cookbook, it is ignored. After updating the fields, it persists the changes to the cookbook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cb_id |
str
|
The ID of the cookbook to update. |
required |
**kwargs |
Arbitrary keyword arguments representing the fields to update and their new values. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the cookbook was successfully updated. |
Raises:
Type | Description |
---|---|
Exception
|
If there's an error during the update process. |