Project

General

Profile

SendRequest() method » History » Version 12

Tomislav Pleše, 09/21/2025 12:08 PM

1 1 Tomislav Pleše
# SendRequest() method
2 2 Tomislav Pleše
3 4 Tomislav Pleše
Context is created from message with following roles: 
4
* system (content: instructions to AI model), 
5
* assistant (content: AI model responses), 
6
* user (content: user prompts)
7 1 Tomislav Pleše
8 5 Tomislav Pleše
Context is created as a messageList where:
9
* first element is the assistant role/content if it exists
10
* following elements are an ascending list of user prompts and assistant responses in ascending order
11
* last element is the newest user prompt
12
13 10 Tomislav Pleše
Sub-prompt 
14
15
Sub-prompt is a prompt that is created from the contents of the Response of the currently selected Point (node - prompt + response). Flow:
16
1. FE - User selects a portion of the current Point's response
17
2. FE - And from this selected text, the new Prompt is started (user can add more text to the selected text)
18
3. FE - User then sends this new Prompt to the AI model 
19
4. FE - From this new Prompt is created a new Point
20
5. FE - The current Point (from which the selected text comes from) now becomes a Shard Point (Shard is added to that Point). This Shard has an Anchor (containing among other: the start and end positions of the selected text)
21
6. FE - The new Point is added to the shardPointChildren list inside the Shard
22
7. FE - On the phone's screen, the node's Response message part (in the tree view) is split into two (sharding): first part (shard) is the text before the end position of the selected text (in the Anchor), and the second part (shard) is the text after that and till the end of the Response.
23
8. FE - The new node (with the new prompt) is placed indented under the first part (first shard) in the tree view 
24 11 Tomislav Pleše
9. FE - Create Context as the messageList. This is how the context for the Shard is created:
25
26 12 Tomislav Pleše
|- T-001: Shard-01   <-- 12. added to context (the text from the endPosition up to the start of the Response message - dissregarding any text that comes after the endPosition)
27
|  |- T-004: Point
28
|  |- T-015: Point
29
|- T-001: Shard-02  <-- 11. added to context  (the text from the endPosition up to the start of the Response message - dissregarding any text that comes after the endPosition - this includes point "<-- 12.")
30
|  |- T-016: Point  <-- 10. added to context
31
|  |- T-017: Point  <-- 9. added to context
32
|  |- T-005: Shard-01  <-- 8. added to context (the text from the endPosition up to the start of the Response message - dissregarding any text that comes after the endPosition)
33
|  |  |- T-006: Point  <-- 7. added to context
34
|  |  |- T-014: Point  <-- 6. added to context
35
|  |  |- T-007: Shard-01  <-- 5. added to context 
36
|  |  |  |- T-010: Point
37
|  |  |  |- T-013: Point 
38
|  |  |- T-007: Shard-02  <-- 3. added to context (the text from the endPosition up to the start of the Response message - dissregarding any text that comes after the endPosition - this includes point "<-- 4.")
39
|  |  |  |- T-011: Point  <-- 2. added to context
40
|  |  |  |- T-012: Point  <-- 1. starting point
41
|  |  |- T-007: Shard-03 
42
|  |  |- T-008: Point
43
|  |- T-005: Shard-02 
44
|  |  |- T-018: Point
45
|  |- T-005: Shard-03 
46
|  |- T-009: Point
47
|- T-001: Shard-03 
48
|- T-002: Point
49
|- T-003: Point 
50
51 11 Tomislav Pleše
52
53 10 Tomislav Pleše
54
55
creates a new regular Point
56
5. selectedRegular Point 
57 9 Tomislav Pleše
1st Sharding - Regular Point becomes Shard Point (ThreadMap = not empty, ShardList = empty) - Shard is created and added to ShardList, new Point is added to ShardPointChildren
58 8 Tomislav Pleše
* previous Response creates a new Point that is inserted in between the response of a current Regular Point. The splitting of the current Point is at the point of  that by this becomes a Shard
59 4 Tomislav Pleše
60 8 Tomislav Pleše
61 4 Tomislav Pleše
Cases for the flow of sending requests to AI model:
62
63 1 Tomislav Pleše
1. Root Point - First Prompt
64 6 Tomislav Pleše
    1. FE - Create new Point
65
    2. FE - Show new Point on Screen - only the Prompt
66
    3. FE - Create Context as the messageList.
67
    4. FE - Send new Point and the messageList to BE
68
    5. BE - Save new Point to DB
69
    6. BE - Send messageList to OpenAI. The JSON should comprise of: model, messages, max_tokens
70
    7. BE - Receive the Response from OpenAI
71
    8. BE - Save Response to DB (into the previously saved new Point document)
72
    9. BE - Send the new Point (with updated Response and other elements like Metadata) to FE
73
    10. FE - Show updated new Point on Screen - node consisting of both Prompt message content and Response message content 
74 1 Tomislav Pleše
75 2 Tomislav Pleše
2. Existing Point - Second prompt
76 6 Tomislav Pleše
    1. FE - Create new Point
77
    2. FE - Show new Point on Screen - the Prompt, under the previous Point
78
    3. FE - Create Context as the messageList.
79
    4. FE - Send new Point and the messageList to BE
80
    5. BE - Save new Point to DB
81
    6. BE - Send messageList to OpenAI. The JSON should comprise of: model, messages, max_tokens
82
    7. BE - Receive the Response from OpenAI
83
    8. BE - Save Response to DB (into the previously saved new Point document)
84
    9. BE - Send the new Point (with updated Response and other elements like Metadata) to FE
85 7 Tomislav Pleše
    10. FE - Show updated new Point on Screen - node consisting of both Prompt message content and Response message content 
86 1 Tomislav Pleše
87 8 Tomislav Pleše
3. New shard -   
88 1 Tomislav Pleše
    1. FE - Create new Point
89 8 Tomislav Pleše
    2. FE - Create a Shard in the current Prompt 
90
3. FE - 
91
    3. FE - Show new Point on Screen - the Prompt, under the previous Point
92 7 Tomislav Pleše
    3. FE - Create Context as the messageList.
93
    4. FE - Send new Point and the messageList to BE
94
    5. BE - Save new Point to DB
95
    6. BE - Send messageList to OpenAI. The JSON should comprise of: model, messages, max_tokens
96
    7. BE - Receive the Response from OpenAI
97
    8. BE - Save Response to DB (into the previously saved new Point document)
98
    9. BE - Send the new Point (with updated Response and other elements like Metadata) to FE
99
    10. FE - Show updated new Point on Screen - node consisting of both Prompt message content and Response message content 
100 6 Tomislav Pleše
101 7 Tomislav Pleše
4. Existing Shard - sub-prompt under a Point that has already been a Shard