|
| 1 | +--- |
| 2 | +declaration: |
| 3 | + call: declare |
| 4 | + version: 0.1 |
| 5 | + description: Description placeholder for 'bgk-BOT' |
| 6 | + method: post |
| 7 | + accepts: json |
| 8 | + returns: json |
| 9 | + namespace: backoffice |
| 10 | + allowlist: |
| 11 | + body: |
| 12 | + - field: message |
| 13 | + type: string |
| 14 | + description: Body field 'message' |
| 15 | + - field: sender |
| 16 | + type: string |
| 17 | + description: Body field 'sender' |
| 18 | + - field: authorId |
| 19 | + type: string |
| 20 | + description: "Parameter 'authorId'" |
| 21 | + - field: holidayNames |
| 22 | + type: string |
| 23 | + description: "Body field 'holidayNames'" |
| 24 | + - field: holidays |
| 25 | + type: string |
| 26 | + description: "Body field 'holidays'" |
| 27 | + |
| 28 | +extract_data: |
| 29 | + assign: |
| 30 | + currentDate: ${new Date().toISOString().split('T')[0]} |
| 31 | + sender: ${incoming.body.sender} |
| 32 | + authorId: ${incoming.body.authorId} |
| 33 | + holidays: ${incoming.body.holidays} |
| 34 | + holidayNames: ${incoming.body.holidayNames} |
| 35 | + event: "" |
| 36 | + |
| 37 | +assignBgkConfig: |
| 38 | + assign: |
| 39 | + strictness: "[#BGK_STRICTNESS]" |
| 40 | + max_tokens: "[#BGK_MAX_TOKENS]" |
| 41 | + documents: "[#BGK_DOCUMENTS]" |
| 42 | + index_name: "[#BGK_INDEX_NAME]" |
| 43 | + query_type: "[#BGK_QUERY_TYPE]" |
| 44 | + system_message: "[#BGK_SYSTEM_MESSAGE]" |
| 45 | + |
| 46 | +logstepAZURESAADAME: |
| 47 | + log: ${incoming.body.message} |
| 48 | + |
| 49 | +assign_data_sources: |
| 50 | + assign: |
| 51 | + data_sources: |
| 52 | + - type: azure_search |
| 53 | + parameters: |
| 54 | + endpoint: "[#SEARCH_ENDPOINT]" |
| 55 | + index_name: ${index_name} |
| 56 | + semantic_configuration: azureml-default |
| 57 | + query_type: ${query_type} |
| 58 | + in_scope: true |
| 59 | + strictness: ${parseInt(strictness ?? '3')} |
| 60 | + top_n_documents: ${parseInt(documents ?? '5')} |
| 61 | + authentication: |
| 62 | + type: api_key |
| 63 | + key: "[#CHATBOT_EXTERNAL_KEY]" |
| 64 | + embedding_dependency: |
| 65 | + type: endpoint |
| 66 | + endpoint: "[#EMBEDDED_ENDPOINT_AZURE]" |
| 67 | + authentication: |
| 68 | + type: api_key |
| 69 | + key: "[#CHATBOT_EXTERNAL_API_KEY]" |
| 70 | + |
| 71 | +logstepAZUREDS: |
| 72 | + log: ${data_sources} |
| 73 | + |
| 74 | +get_chat_messages: |
| 75 | + call: http.post |
| 76 | + args: |
| 77 | + url: "[#CHATBOT_RESQL]/get-chat-messages" |
| 78 | + body: |
| 79 | + chatId: ${sender} |
| 80 | + result: chat_messages_res |
| 81 | + |
| 82 | +prepare_messages: |
| 83 | + call: http.post |
| 84 | + args: |
| 85 | + url: "[#CHATBOT_DMAPPER]/hbs/chat-bot/prepare-llm-messages" |
| 86 | + headers: |
| 87 | + type: json |
| 88 | + body: |
| 89 | + prompt_message: "${system_message} The current date is ${currentDate}" |
| 90 | + messages: ${chat_messages_res.response.body} |
| 91 | + new_message: ${incoming.body.message ?? ''} |
| 92 | + result: prepare_messages_res |
| 93 | + |
| 94 | +assign_messages: |
| 95 | + assign: |
| 96 | + messages: ${prepare_messages_res.response.body} |
| 97 | + |
| 98 | +logstepAZUREMSG: |
| 99 | + log: ${messages} |
| 100 | + |
| 101 | +post_answer: |
| 102 | + call: http.post |
| 103 | + args: |
| 104 | + url: "[#CHATBOT_EXTERNAL_BOT_URL]" |
| 105 | + headers: |
| 106 | + Content-Type: application/json |
| 107 | + api-key: "[#CHATBOT_EXTERNAL_API_KEY]" |
| 108 | + body: |
| 109 | + data_sources: ${data_sources} |
| 110 | + messages: ${messages} |
| 111 | + temperature: 0 |
| 112 | + max_tokens: ${parseInt(max_tokens ?? '1000')} |
| 113 | + stream: false |
| 114 | + frequency_penalty: 0 |
| 115 | + presence_penalty: 0 |
| 116 | + result: test |
| 117 | + |
| 118 | +logstepAZUREBOT: |
| 119 | + log: ${test} |
| 120 | + |
| 121 | +assign_value: |
| 122 | + assign: |
| 123 | + correct_value: |
| 124 | + - recipient_id: ${sender} |
| 125 | + text: ${test.response.body.choices[0].message.content.replace(/\n/g,"\\n").replace(" \. ", ". ")} |
| 126 | + context: ${test.response.body.choices[0].message.context} |
| 127 | + next: check_value |
| 128 | + |
| 129 | +check_value: |
| 130 | + switch: |
| 131 | + - condition: ${correct_value === 'ERROR'} |
| 132 | + next: return_value |
| 133 | + - condition: ${correct_value.map((item) => item.text)[0] === '$backoffice' || correct_value.map((item) => item.text)[0].startsWith('$backoffice')} |
| 134 | + next: assign_back_office_event |
| 135 | + - condition: ${correct_value.map((item) => item.text)[0].startsWith('$validate_')} |
| 136 | + next: assign_validation_event |
| 137 | + next: format_messages |
| 138 | + |
| 139 | +return_value: |
| 140 | + return: ${correct_value} |
| 141 | + next: end |
| 142 | + |
| 143 | +assign_validation_event: |
| 144 | + assign: |
| 145 | + correct_value: |
| 146 | + - recipient_id: ${sender} |
| 147 | + text: ${correct_value.map((item) => item.text)[0].replace('$validate_', '')} |
| 148 | + context: ${test.response.body.choices[0].message.context} |
| 149 | + event: "waiting_validation" |
| 150 | + next: change_chat_status |
| 151 | + |
| 152 | +change_chat_status: |
| 153 | + call: http.post |
| 154 | + args: |
| 155 | + url: "[#CHATBOT_RUUTER_PUBLIC]/chats/change-status" |
| 156 | + body: |
| 157 | + chatId: ${sender} |
| 158 | + status: "VALIDATING" |
| 159 | + holidays: ${holidays} |
| 160 | + holidayNames: ${holidayNames} |
| 161 | + result: change_chat_status_res |
| 162 | + next: check_chat_status_result |
| 163 | + |
| 164 | +check_chat_status_result: |
| 165 | + switch: |
| 166 | + - condition: ${change_chat_status_res.response.body.response === "Status Changed Successfully"} |
| 167 | + next: format_messages |
| 168 | + next: assign_unavailable_message |
| 169 | + |
| 170 | +assign_unavailable_message: |
| 171 | + assign: |
| 172 | + correct_value: |
| 173 | + - recipient_id: ${sender} |
| 174 | + text: "Edasine lahendamine toimub vastavalt pöördumiste protsessile väljaspool AI-assistendi lahendust." |
| 175 | + context: ${test.response.body.choices[0].message.context} |
| 176 | + event: "" |
| 177 | + next: format_messages |
| 178 | + |
| 179 | +assign_back_office_event: |
| 180 | + assign: |
| 181 | + correct_value: |
| 182 | + - recipient_id: ${sender} |
| 183 | + text: "Kahjuks ei oska ma hetkel teie küsimusele vastata. Kas soovite, et suunan küsimuse nõustajale?" |
| 184 | + context: ${test.response.body.choices[0].message.context} |
| 185 | + event: "ask_to_forward_to_csa" |
| 186 | + next: format_messages |
| 187 | + |
| 188 | +format_messages: |
| 189 | + call: http.post |
| 190 | + args: |
| 191 | + url: "[#CHATBOT_DMAPPER]/hbs/chat-bot/llm_responses_to_messages" |
| 192 | + headers: |
| 193 | + type: json |
| 194 | + body: |
| 195 | + data: |
| 196 | + { |
| 197 | + "botMessages": "${correct_value}", |
| 198 | + "chatId": "${sender}", |
| 199 | + "authorId": "${authorId}", |
| 200 | + "authorFirstName": "", |
| 201 | + "authorLastName": "", |
| 202 | + "event": "${event ?? ''}", |
| 203 | + "authorTimestamp": "${new Date().toISOString()}", |
| 204 | + "created": "${new Date().toISOString()}", |
| 205 | + } |
| 206 | + result: converted_messages_res |
| 207 | + next: return_formatted_value |
| 208 | + |
| 209 | +return_formatted_value: |
| 210 | + return: ${converted_messages_res.response.body} |
| 211 | + next: end |
0 commit comments