Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions ex_app/lib/all_tools/doc-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion ex_app/lib/all_tools/lib/task_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading