diff --git a/ex_app/lib/agent.py b/ex_app/lib/agent.py index 7107248..aa45fcc 100644 --- a/ex_app/lib/agent.py +++ b/ex_app/lib/agent.py @@ -39,9 +39,7 @@ def load_conversation(checkpointer, conversation_token: str): if conversation_token == '' or conversation_token == '{}': return - print(checkpointer.storage) checkpointer.storage = checkpointer.serde.loads(verify_signature(conversation_token, key).encode()) - print(checkpointer.storage) def export_conversation(checkpointer): return add_signature(checkpointer.serde.dumps(checkpointer.storage).decode('utf-8'), key) diff --git a/ex_app/lib/all_tools/ai.py b/ex_app/lib/all_tools/ai.py index 440f842..07d839b 100644 --- a/ex_app/lib/all_tools/ai.py +++ b/ex_app/lib/all_tools/ai.py @@ -25,7 +25,7 @@ def ask_context_chat(question: str) -> str: 'scopeList': [], 'scopeListMeta': '', } - task_output = run_task(nc, "context_chat:context_chat", task_input) + task_output = run_task(nc, "context_chat:context_chat", task_input).output return task_output['output'] @tool @@ -39,10 +39,28 @@ def transcribe_file(file_url: str) -> str: task_input = { 'input': get_file_id_from_file_url(file_url), } - task_output = run_task(nc, "core:audio2text", task_input) + task_output = run_task(nc, "core:audio2text", task_input).output return task_output['output'] + + @tool + @safe_tool + def generate_document(input: str, format: str) -> str: + """ + 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" + :return: a download link to the generated document + """ + tasktype = "richdocuments:text_to_" + format + 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['file']}/download" + return [ ask_context_chat, transcribe_file, + generate_document, ] \ No newline at end of file diff --git a/ex_app/lib/all_tools/lib/task_processing.py b/ex_app/lib/all_tools/lib/task_processing.py index 4721f0d..b7d2e4d 100644 --- a/ex_app/lib/all_tools/lib/task_processing.py +++ b/ex_app/lib/all_tools/lib/task_processing.py @@ -58,11 +58,10 @@ def run_task(nc, type, task_input): log(nc, LogLvl.DEBUG, task) except ValidationError as e: raise Exception("Failed to parse Nextcloud TaskProcessing task result") from e - if task.status != "STATUS_SUCCESSFUL": raise Exception("Nextcloud TaskProcessing Task failed") - if not isinstance(task.output, dict) or "output" not in task.output: + if not isinstance(task.output, dict) or ("file" not in task.output and "output" not in task.output): raise Exception('"output" key not found in Nextcloud TaskProcessing task result') - return task.output \ No newline at end of file + return task \ No newline at end of file diff --git a/ex_app/lib/all_tools/talk.py b/ex_app/lib/all_tools/talk.py index aaa690a..08d28a3 100644 --- a/ex_app/lib/all_tools/talk.py +++ b/ex_app/lib/all_tools/talk.py @@ -52,7 +52,7 @@ def send_message_to_conversation(conversation_name: str, message: str): def list_messages_in_conversation(conversation_name: str, n_messages: int = 30): """ List messages of a conversation in talk - :param conversation_name: The name of the conversation to list messages of + :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) :param n_messages: The number of messages to receive :return: """ diff --git a/ex_app/lib/memorysaver.py b/ex_app/lib/memorysaver.py index 4f34a51..edd00e2 100644 --- a/ex_app/lib/memorysaver.py +++ b/ex_app/lib/memorysaver.py @@ -1,3 +1,5 @@ +# SPDX-FileCopyrightText: 2024 LangChain, Inc. +# SPDX-License-Identifier: MIT import logging import os import pickle