diff --git a/ex_app/lib/all_tools/doc-gen.py b/ex_app/lib/all_tools/doc-gen.py index 0bc6ba1..4106f1d 100644 --- a/ex_app/lib/all_tools/doc-gen.py +++ b/ex_app/lib/all_tools/doc-gen.py @@ -13,15 +13,48 @@ def get_tools(nc: Nextcloud): @safe_tool def generate_document(input: str, format: str) -> str: """ - Generate a document with the input string as description + Generate a document with the input string as description. :param text: the instructions for the document - :param format: the format of the generated file, available are "text_document" and "spreadsheet_document" + :param format: the format of the generated file, allowed values are "text document", "pdf", "spreadsheet", "excel spreadsheet" and "slides" :return: a download link to the generated document """ - tasktype = "richdocuments:text_to_" + format - task_input = { - 'text': input, - } + match format: + case "text document": + tasktype = "richdocuments:text_to_text_document" + task_input = { + 'text': input, + 'target_format': 'docx' + } + + case "pdf": + tasktype = "richdocuments:text_to_text_document" + task_input = { + 'text': input, + 'target_format': 'pdf' + } + + case "spreadsheet": + tasktype = "richdocuments:text_to_spreadsheet_document" + task_input = { + 'text': input, + 'target_format': 'ods' + } + + case "excel spreadsheet": + tasktype = "richdocuments:text_to_spreadsheet_document" + task_input = { + 'text': input, + 'target_format': 'xlsx' + } + + case "slides": + tasktype = "richdocuments:slide_deck_generation" + task_input = { + 'text': input, + } + task = run_task(nc, tasktype, task_input) + return f"https://nextcloud.local/ocs/v2.php/apps/assistant/api/v1/task/{task.id}/output-file/{task.output['slide_deck']}/download" + task = run_task(nc, tasktype, task_input) return f"https://nextcloud.local/ocs/v2.php/apps/assistant/api/v1/task/{task.id}/output-file/{task.output['file']}/download" diff --git a/ex_app/lib/all_tools/lib/task_processing.py b/ex_app/lib/all_tools/lib/task_processing.py index 613a539..770eef6 100644 --- a/ex_app/lib/all_tools/lib/task_processing.py +++ b/ex_app/lib/all_tools/lib/task_processing.py @@ -61,7 +61,7 @@ def run_task(nc, type, task_input): if task.status != "STATUS_SUCCESSFUL": raise Exception("Nextcloud TaskProcessing Task failed") - if not isinstance(task.output, dict) or all(x not in ["file", "output", "images"] for x in task.output): + if not isinstance(task.output, dict) or all(x not in ["file", "output", "images", "slide_deck"] for x in task.output): raise Exception('"output" key not found in Nextcloud TaskProcessing task result') return task \ No newline at end of file