Skip to content

Commit feede41

Browse files
Merge pull request #203 from hoomano/xbasset/doc_gen_workflow
Xbasset/doc gen workflow
2 parents 7535fde + 4a3e828 commit feede41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1371
-227
lines changed

backend/app/models/user_task_execution_inputs_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mojodex_core.user_storage_manager.user_audio_file_manager import UserAudioFileManager
22
from mojodex_core.user_storage_manager.user_images_file_manager import UserImagesFileManager
3+
from mojodex_core.user_storage_manager.user_video_file_manager import UserVideoFileManager
34

45

56
class UserTaskExecutionInputsManager:
@@ -9,6 +10,7 @@ class UserTaskExecutionInputsManager:
910
image_type = "image"
1011
multiple_images_type = "multiple_images"
1112
audio_file = "audio_file"
13+
video_file = "video"
1214

1315
def construct_inputs_from_request(self, user_task_execution_json_input_values, inputs, files, user_id, session_id):
1416
try:
@@ -54,6 +56,10 @@ def construct_inputs_from_request(self, user_task_execution_json_input_values, i
5456
if input["input_name"] == file_input:
5557
filename = input["value"]
5658
UserAudioFileManager().store_audio_file_from_form(files[file_input], filename, user_id, session_id)
59+
if input["type"] == self.video_file:
60+
if input["input_name"] == file_input:
61+
filename = input["value"]
62+
UserVideoFileManager().store_video_file(files[file_input], filename, user_id, session_id)
5763

5864
return user_task_execution_json_input_values
5965
except Exception as e:

backend/app/routes/task.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
"image",
106106
"drop_down_list",
107107
"multiple_images",
108-
"audio_file"
108+
"audio_file",
109+
"video"
109110
]
110111
},
111112
"input_name": {
@@ -356,7 +357,8 @@
356357
"image",
357358
"drop_down_list",
358359
"multiple_images",
359-
"audio_file"
360+
"audio_file",
361+
"video"
360362
]
361363
},
362364
"input_name": {

docs/design-principles/products/whats_a_product.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,4 @@ Later, a user can:
7676

7777
> Important note: A user can't have 2 active subscriptions at the same time. If a user is affected with a new subscription, the previous one is automatically cancelled.
7878
79-
2 payment services have been implemented for now:
80-
- [Stripe](https://stripe.com)
81-
- [Apple in-app purchase](https://developer.apple.com/in-app-purchase/)
79+
Payment service implemented: [Stripe](https://stripe.com)
Lines changed: 1 addition & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1,197 +1,3 @@
11
# How To-Do works?
22

3-
To-dos are stored in the database. Typical technical workflow of a To-Do item is as follow:
4-
1) extracted from a task execution
5-
2) organized later if not achieved
6-
3) reminded to the user
7-
4) cleared by the user
8-
9-
## 1. Extract To-Dos from achieved tasks
10-
Mojodex's scheduler is a python module that triggers routes calls at a certain frequency. See `/scheduler/app/main.py`
11-
12-
One of its trigger checks every 10 minutes if a task has just been achieved.
13-
```python
14-
from scheduled_tasks.extract_todos import ExtractTodos
15-
[...]
16-
ExtractTodos(600) # extract todos every 10 minutes
17-
[...]
18-
```
19-
20-
> A task is considered 'just achieved' if it has an associated produced_text which last version's date is between 10 and 20 minutes ago. See `backend/app/routes/extract_todos.py`.
21-
22-
Each of those tasks are sent to the background through route `/extract_todos` for processing.
23-
As a reminder, when a background route is called, the data is processed as follow:
24-
25-
```python
26-
class ExtractTodos(Resource):
27-
[...]
28-
def post(self):
29-
[...]
30-
extract_todos_cortex = ExtractTodosCortex(user_task_execution)
31-
32-
def run_extract_todos_cortex(cortex):
33-
try:
34-
cortex.extract_todos()
35-
except Exception as err:
36-
print("🔴" + str(err))
37-
38-
executor.submit(run_extract_todos_cortex, extract_todos_cortex)
39-
return {"success": "Process started"}, 200
40-
[...]
41-
```
42-
43-
- A cortex (here `background/app/models/cortex/extract_todos_cortex.py`) is created. At construction, the cortex collects all database entries needed for further processing. This is done to avoid database connection out of main thread.
44-
45-
- Then, the main function of the cortex, responsible for processing data (here `extract_todos()`) is called in an asynchronous way.
46-
47-
The method extract_todos() uses prompt `data/prompts/background/todos/extract_todos.txt`– filled with all tasks data to extract To-Dos out of completed task. Notable instructions of this prompt are:
48-
49-
- Extraction instruction: To define what is a To-Do.
50-
```
51-
[...]
52-
Extract any todo the user mentioned in the task as next steps they have to take.
53-
Those todos describes actions the user will have to do in the future. They cannot be passive.
54-
[...]
55-
```
56-
57-
- Explicitely-mentioned only instruction: To avoid any hallucination from the agent.
58-
```
59-
[...]
60-
Extract ONLY next steps the user explicitly mentioned in the task.
61-
[...]
62-
```
63-
64-
- Assigned-only instruction: To avoid including To-Dos' that could be assigned to the user's contact in an email task or other participant mentioned in a meeting minutes, for example.
65-
```
66-
[...]
67-
Extract ONLY next steps assigned to the user.
68-
[...]
69-
```
70-
71-
The result of the prompt is a json list of dictionnary defining To-Do items.
72-
```json
73-
{
74-
"todo_definition": "<Definition as it will be displayed in the user's todo list.
75-
The definition should help the user remember what was the original task.
76-
Mention any name, company,... that can help them get the context.>",
77-
"mentioned_as_todo": <Did the user explicitly mentioned this as a todo? yes/no>,
78-
"due_date": "<Date at which the todo will be displayed in user's todo list. Format yyyy-mm-dd>"
79-
}
80-
```
81-
82-
This json is parsed and items are added to the database, related to the task.
83-
84-
![extract_todos](../../images/to-dos_flow/extract_todos.png)
85-
86-
## 2. Organize
87-
Another hourly trigger of the scheduler takes care of reorganizing user's To-Do list every night to keep it up-to-date.
88-
89-
```python
90-
from scheduled_tasks.reschedule_todos import RescheduleTodos
91-
[...]
92-
RescheduleTodos(3600) # reschedule todos every 1 hour
93-
[...]
94-
```
95-
96-
This trigger calls Mojodex's backend route `/todo_scheduling` to retrieve all To-Dos items that:
97-
- Belongs to a user whose local time is between 1am and 2am
98-
- Has not been deleted, nor completed
99-
- Was due for the day before
100-
101-
Each of those To-Dos are sent to the background using route `/reschedule_todos` for processing.
102-
103-
Here, the route uses cortex `backend/app/models/cortex/reschedule_todo_cortex.py` to process the data. The main function of the cortex, responsible for processing data is `reschedule_todo`.
104-
105-
It uses prompt `data/prompts/background/todos/reschedule_todo.txt` provided with:
106-
- related task data
107-
- To-Do item along with the number of times it has already been rescheduled and
108-
- User's To-Do list in upcoming days
109-
110-
```
111-
[...]
112-
Regarding the TASK, TODO ITEM and USER TODO LIST, decide when to reschedule the TODO ITEM for later.
113-
The task was currently scheduled for yesterday.
114-
Provide the new scheduled date.
115-
[...]
116-
```
117-
118-
This prompt outputs a json answer that can be parsed so that a new scheduling can be added to database.
119-
120-
![reschedule_todos](../../images/to-dos_flow/reschedule_todos.png)
121-
122-
## 3. Remind the user
123-
Here comes Mojodex's scheduler again with another hourly trigger.
124-
125-
`/scheduler/app/main.py`
126-
```python
127-
from scheduled_tasks.purchase_expiration_checker import PurchasesExpirationChecker
128-
[...]
129-
emails = 'AWS_ACCESS_KEY_ID' in os.environ and os.environ['AWS_ACCESS_KEY_ID']
130-
if emails:
131-
[...]
132-
SendTodoDailyEmails(3600) # send todo daily emails every 1 hour (filtered by timezone)
133-
[...]
134-
```
135-
136-
> Note that this trigger is only activated if the environment variable `AWS_ACCESS_KEY_ID` is set. This variable is used to send emails through AWS SES, only emails mechanism implemented in Mojodex for now.
137-
138-
139-
This triggers calls Mojodex's backend route `/todo_daily_emails` to retrieve all users whose local time is `DAILY_TODO_EMAIL_TIME` (defined in *env vars* see: `.env.example`).
140-
141-
142-
For each of those users, the assistant will collect all To-Dos that are due for the coming day + the re-organization work it has done (cf step 4) and send those data to the background using route `events_generation` with parameter `'event_type': 'todo_daily_emails'`.
143-
144-
The background uses its `TodoDailyEmailsGenerator` (`background/app/models/events/todo_daily_emails_generator.py`) with prompt `data/prompts/engagement/emails/todo_daily_emails_text_prompt.txt` to draft a friendly reminding emails to send to the user from provided data.
145-
146-
Once an email is ready, the background sends it to the backend using route `/event` with parameters so that the backend sends the email to the user using AWS SES and logs it to the database.
147-
148-
`backend/app/routes/event.py`
149-
```python
150-
[...]
151-
mojo_mail_client.send_email(subject=subject,
152-
recipients=[email],
153-
html_body=body)
154-
# add notification to db
155-
email_event = MdEvent(creation_date=datetime.now(), event_type=event_type,
156-
user_id=user_id,
157-
message=message)
158-
db.session.add(email_event)
159-
db.session.commit()
160-
[...]
161-
```
162-
163-
![remind_user](../../images/to-dos_flow/remind_user.png)
164-
165-
## 4. User actions
166-
Users can of course also act on their own To-Dos. For now, they can take 2 actions:
167-
- Delete a To-Do item, if it was not relevant to add it or the assistant made any mistake. As any application call, this call is made to the backend and the route is DELETE `/todo`.
168-
> Note: an item is never deleted for real in the database. It is only marked as deleted so that it does not appear in the user's To-Do list anymore. This is to keep track of all the work the assistant has done.
169-
`backend/app/routes/todo.py`
170-
```python
171-
class Todos(Resource):
172-
[...]
173-
def delete(self, user_id):
174-
[...]
175-
todo.deleted_by_user = datetime.now()
176-
db.session.commit()
177-
[...]
178-
179-
```
180-
181-
- Mark a To-Do as completed as soon as they don't need it anymore to remember of the work they have to do. As any application call, this call is made to the backend and the route is POST `/todo`.
182-
`backend/app/routes/todo.py`
183-
```python
184-
class Todos(Resource):
185-
[...]
186-
def post(self, user_id):
187-
[...]
188-
todo.completed = datetime.now()
189-
db.session.commit()
190-
[...]
191-
192-
```
193-
194-
195-
![user_actions](../../images/to-dos_flow/user_actions.png)
196-
197-
> Note: find every API specification in the [Backend API documentation](../../openAPI/backend_api.yaml) and the [Background API documentation](../../openAPI/background_api.yaml)
3+
TODO.

docs/design-principles/workflows/execute_workflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The `WorkflowExecution` is the epicenter of workflow execution. The function `ru
117117
- Run current step
118118
- Ask for user validation once the step is executed
119119

120-
![start_user_workflow_execution_from_form](../../images/workflow_execution/start_user_workflow_execution_from_form.png)
120+
![start_user_workflow_execution_from_form](../../images/task_execution/start_user_task_execution_from_form.png)
121121

122122
> The Workflow Execution detailled flow is described in part 3.
123123

docs/images/md_task.png

152 KB
Loading
86.8 KB
Loading
39.3 KB
Loading

docs/images/md_todo.png

82.7 KB
Loading

docs/images/md_user.png

299 KB
Loading

0 commit comments

Comments
 (0)