Skip to content

Commit c09a222

Browse files
authored
Merge pull request #19 from nextcloud/feat/doc-gen
Feat: generate Office documents
2 parents b28c474 + d48f22c commit c09a222

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

ex_app/lib/agent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
def load_conversation(checkpointer, conversation_token: str):
4040
if conversation_token == '' or conversation_token == '{}':
4141
return
42-
print(checkpointer.storage)
4342
checkpointer.storage = checkpointer.serde.loads(verify_signature(conversation_token, key).encode())
44-
print(checkpointer.storage)
4543

4644
def export_conversation(checkpointer):
4745
return add_signature(checkpointer.serde.dumps(checkpointer.storage).decode('utf-8'), key)

ex_app/lib/all_tools/ai.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def ask_context_chat(question: str) -> str:
2525
'scopeList': [],
2626
'scopeListMeta': '',
2727
}
28-
task_output = run_task(nc, "context_chat:context_chat", task_input)
28+
task_output = run_task(nc, "context_chat:context_chat", task_input).output
2929
return task_output['output']
3030

3131
@tool
@@ -39,10 +39,28 @@ def transcribe_file(file_url: str) -> str:
3939
task_input = {
4040
'input': get_file_id_from_file_url(file_url),
4141
}
42-
task_output = run_task(nc, "core:audio2text", task_input)
42+
task_output = run_task(nc, "core:audio2text", task_input).output
4343
return task_output['output']
4444

45+
46+
@tool
47+
@safe_tool
48+
def generate_document(input: str, format: str) -> str:
49+
"""
50+
Generate a document with the input string as description
51+
:param text: the instructions for the document
52+
:param format: the format of the generated file, available are "text_document" and "spreadsheet_document"
53+
:return: a download link to the generated document
54+
"""
55+
tasktype = "richdocuments:text_to_" + format
56+
task_input = {
57+
'text': input,
58+
}
59+
task = run_task(nc, tasktype, task_input)
60+
return f"https://nextcloud.local/ocs/v2.php/apps/assistant/api/v1/task/{task.id}/output-file/{task.output['file']}/download"
61+
4562
return [
4663
ask_context_chat,
4764
transcribe_file,
65+
generate_document,
4866
]

ex_app/lib/all_tools/lib/task_processing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ def run_task(nc, type, task_input):
5858
log(nc, LogLvl.DEBUG, task)
5959
except ValidationError as e:
6060
raise Exception("Failed to parse Nextcloud TaskProcessing task result") from e
61-
6261
if task.status != "STATUS_SUCCESSFUL":
6362
raise Exception("Nextcloud TaskProcessing Task failed")
6463

65-
if not isinstance(task.output, dict) or "output" not in task.output:
64+
if not isinstance(task.output, dict) or ("file" not in task.output and "output" not in task.output):
6665
raise Exception('"output" key not found in Nextcloud TaskProcessing task result')
6766

68-
return task.output
67+
return task

ex_app/lib/all_tools/talk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def send_message_to_conversation(conversation_name: str, message: str):
5252
def list_messages_in_conversation(conversation_name: str, n_messages: int = 30):
5353
"""
5454
List messages of a conversation in talk
55-
:param conversation_name: The name of the conversation to list messages of
55+
:param conversation_name: The name of the conversation to list messages of (can only be one conversation per Tool call, obtainable via list_talk_conversations)
5656
:param n_messages: The number of messages to receive
5757
:return:
5858
"""

ex_app/lib/memorysaver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2024 LangChain, Inc.
2+
# SPDX-License-Identifier: MIT
13
import logging
24
import os
35
import pickle

0 commit comments

Comments
 (0)