SendRequest() method » History » Version 18
Tomislav Pleše, 09/21/2025 01:43 PM
| 1 | 1 | Tomislav Pleše | # SendRequest() method |
|---|---|---|---|
| 2 | 2 | Tomislav Pleše | |
| 3 | 16 | Tomislav Pleše | # **Regular prompt** |
| 4 | Context for regular Point is created from message with following roles: |
||
| 5 | 4 | Tomislav Pleše | * system (content: instructions to AI model), |
| 6 | * assistant (content: AI model responses), |
||
| 7 | * user (content: user prompts) |
||
| 8 | 1 | Tomislav Pleše | |
| 9 | 17 | Tomislav Pleše | Context for regular Point is created as a messageList where: |
| 10 | 5 | Tomislav Pleše | * first element is the assistant role/content if it exists |
| 11 | * following elements are an ascending list of user prompts and assistant responses in ascending order |
||
| 12 | * last element is the newest user prompt |
||
| 13 | |||
| 14 | 1 | Tomislav Pleše | |
| 15 | 15 | Tomislav Pleše | # **Sub-prompt** |
| 16 | Sub-prompt is a prompt that is created from the contents of the Response of the currently selected Point (node - prompt + response). |
||
| 17 | This is how the context is created for the Sub-prompt: |
||
| 18 | 11 | Tomislav Pleše | |
| 19 | 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) |
| 20 | | |- T-004: Point |
||
| 21 | | |- T-015: Point |
||
| 22 | |- 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.") |
||
| 23 | | |- T-016: Point <-- 10. added to context |
||
| 24 | | |- T-017: Point <-- 9. added to context |
||
| 25 | | |- 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) |
||
| 26 | | | |- T-006: Point <-- 7. added to context |
||
| 27 | | | |- T-014: Point <-- 6. added to context |
||
| 28 | | | |- T-007: Shard-01 <-- 5. added to context |
||
| 29 | | | | |- T-010: Point |
||
| 30 | | | | |- T-013: Point |
||
| 31 | | | |- 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.") |
||
| 32 | | | | |- T-011: Point <-- 2. added to context |
||
| 33 | 1 | Tomislav Pleše | | | | |- T-012: Point <-- 1. starting point |
| 34 | 12 | Tomislav Pleše | | | |- T-007: Shard-03 |
| 35 | | | |- T-008: Point |
||
| 36 | | |- T-005: Shard-02 |
||
| 37 | 1 | Tomislav Pleše | | | |- T-018: Point |
| 38 | | |- T-005: Shard-03 |
||
| 39 | | |- T-009: Point |
||
| 40 | |- T-001: Shard-03 |
||
| 41 | |- T-002: Point |
||
| 42 | |- T-003: Point |
||
| 43 | |||
| 44 | 15 | Tomislav Pleše | So this is the Context when it's a sub-prompt from a Shard: |
| 45 | 1 | Tomislav Pleše | * first element is the assistant role/content if it exists |
| 46 | * following elements are an ascending list of user prompts and assistant responses in ascending order: [012, 011, 007(S01+S02), 014, 006, 005(S01), 017, 016, 001(S01+S02) ] |
||
| 47 | * last element is the newest user prompt |
||
| 48 | 15 | Tomislav Pleše | |
| 49 | |||
| 50 | |||
| 51 | 18 | Tomislav Pleše | # **Flow of sending a Request to OpenAI API endpoint (with AI model 3.5-turbo):** |
| 52 | 6 | Tomislav Pleše | 1. Root Point - First Prompt |
| 53 | 1. FE - Create new Point |
||
| 54 | 2. FE - Show new Point on Screen - only the Prompt |
||
| 55 | 3. FE - Create Context as the messageList. |
||
| 56 | 1 | Tomislav Pleše | 4. FE - Send new Point and the messageList to BE |
| 57 | 5. BE - Save new Point to DB |
||
| 58 | 6. BE - Send messageList to OpenAI. The JSON should comprise of: model, messages, max_tokens |
||
| 59 | 7. BE - Receive the Response from OpenAI |
||
| 60 | 8. BE - Save Response to DB (into the previously saved new Point document) |
||
| 61 | 9. BE - Send the new Point (with updated Response and other elements like Metadata) to FE |
||
| 62 | 10. FE - Show updated new Point on Screen - node consisting of both Prompt message content and Response message content |
||
| 63 | |||
| 64 | 2. Existing Point - Second prompt |
||
| 65 | 1. FE - Create new Point |
||
| 66 | 2. FE - Show new Point on Screen - the Prompt, under the previous Point |
||
| 67 | 3. FE - Create Context as the messageList. |
||
| 68 | 4. FE - Send new Point and the messageList to BE |
||
| 69 | 5. BE - Save new Point to DB |
||
| 70 | 6. BE - Send messageList to OpenAI. The JSON should comprise of: model, messages, max_tokens |
||
| 71 | 7. BE - Receive the Response from OpenAI |
||
| 72 | 8. BE - Save Response to DB (into the previously saved new Point document) |
||
| 73 | 6 | Tomislav Pleše | 9. BE - Send the new Point (with updated Response and other elements like Metadata) to FE |
| 74 | 10. FE - Show updated new Point on Screen - node consisting of both Prompt message content and Response message content |
||
| 75 | |||
| 76 | 3. New shard - |
||
| 77 | 17 | Tomislav Pleše | 1. FE - User selects a portion of the current Point's response |
| 78 | 2. FE - And from this selected text, the new Prompt is started (user can add more text to the selected text) |
||
| 79 | 3. FE - User then sends this new Prompt to the AI model |
||
| 80 | 4. FE - From this new Prompt is created a new Point |
||
| 81 | 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) |
||
| 82 | 6. FE - The new Point is added to the shardPointChildren list inside the Shard |
||
| 83 | 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. |
||
| 84 | 8. FE - The new node (with the new prompt) is placed indented under the first part (first shard) in the tree view |
||
| 85 | 9. FE - Create Context as the messageList. This is how the context for the Shard is created: |
||
| 86 | 10. FE - Send new Point, the current Point (which has become Shard) and the messageList to BE |
||
| 87 | 11. BE - Save new Point to DB |
||
| 88 | 12. BE - Update the current Point (the one that bacame Shard) |
||
| 89 | 13. BE - Send messageList to OpenAI. The JSON should comprise of: model, messages, max_tokens |
||
| 90 | 14. BE - Receive the Response from OpenAI |
||
| 91 | 15. BE - Save Response to DB (into the previously saved new Point document) |
||
| 92 | 16. BE - Send the new Point (with updated Response and other elements like Metadata) to FE |
||
| 93 | 17. FE - Show updated new Point on Screen - node consisting of both Prompt message content and Response message content |
||
| 94 | 1 | Tomislav Pleše | |
| 95 | 4. Existing Shard - sub-prompt under a Point that has already been a Shard |