Skip to content

Commit 2cfe4ce

Browse files
authored
Merge pull request #27 from nextcloud/feat/more-docs
Feat: more document generation formats
2 parents 74570e5 + 31f20f1 commit 2cfe4ce

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

ex_app/lib/all_tools/doc-gen.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,48 @@ def get_tools(nc: Nextcloud):
1313
@safe_tool
1414
def generate_document(input: str, format: str) -> str:
1515
"""
16-
Generate a document with the input string as description
16+
Generate a document with the input string as description.
1717
:param text: the instructions for the document
18-
:param format: the format of the generated file, available are "text_document" and "spreadsheet_document"
18+
:param format: the format of the generated file, allowed values are "text document", "pdf", "spreadsheet", "excel spreadsheet" and "slides"
1919
:return: a download link to the generated document
2020
"""
21-
tasktype = "richdocuments:text_to_" + format
22-
task_input = {
23-
'text': input,
24-
}
21+
match format:
22+
case "text document":
23+
tasktype = "richdocuments:text_to_text_document"
24+
task_input = {
25+
'text': input,
26+
'target_format': 'docx'
27+
}
28+
29+
case "pdf":
30+
tasktype = "richdocuments:text_to_text_document"
31+
task_input = {
32+
'text': input,
33+
'target_format': 'pdf'
34+
}
35+
36+
case "spreadsheet":
37+
tasktype = "richdocuments:text_to_spreadsheet_document"
38+
task_input = {
39+
'text': input,
40+
'target_format': 'ods'
41+
}
42+
43+
case "excel spreadsheet":
44+
tasktype = "richdocuments:text_to_spreadsheet_document"
45+
task_input = {
46+
'text': input,
47+
'target_format': 'xlsx'
48+
}
49+
50+
case "slides":
51+
tasktype = "richdocuments:slide_deck_generation"
52+
task_input = {
53+
'text': input,
54+
}
55+
task = run_task(nc, tasktype, task_input)
56+
return f"https://nextcloud.local/ocs/v2.php/apps/assistant/api/v1/task/{task.id}/output-file/{task.output['slide_deck']}/download"
57+
2558
task = run_task(nc, tasktype, task_input)
2659
return f"https://nextcloud.local/ocs/v2.php/apps/assistant/api/v1/task/{task.id}/output-file/{task.output['file']}/download"
2760

ex_app/lib/all_tools/lib/task_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def run_task(nc, type, task_input):
6161
if task.status != "STATUS_SUCCESSFUL":
6262
raise Exception("Nextcloud TaskProcessing Task failed")
6363

64-
if not isinstance(task.output, dict) or all(x not in ["file", "output", "images"] for x in task.output):
64+
if not isinstance(task.output, dict) or all(x not in ["file", "output", "images", "slide_deck"] for x in task.output):
6565
raise Exception('"output" key not found in Nextcloud TaskProcessing task result')
6666

6767
return task

0 commit comments

Comments
 (0)