Skip to content

Commit

Permalink
Live agent flag (#1194)
Browse files Browse the repository at this point in the history
* rasa 3.6 upgrade

* changed pymupdf

* fixed docker anf gitlabci

* added prod and dev requirements

* fixed requirements

* removed mock stores

* add pip upgrade

* added folder creation with parents folder

* added docker system cleanup

* fixed validate prompts test case

* added kairon version 3 docker

* fix kairon base tag

* added models in base image for nltk, spacy

* fixed setupfiles

* removed virtual env

* fix step in gitlab

* python version in setup.sh

* gitlab ci corrected

* gitlab ci corrected

* pyssl issue fixed

* added virtual env with caching

* added pip upgrade in venv

* web search action merged

* event server changes

* added elastic search as dependency

* fixed action server issue

* optmised docker image

* test fixed for ujson

* merge chatserver and pyscript action

* fixed kairon LanguageModelFeaturizer

* merged master changes

* optmised docker to improve build and push time

* evaluator service corrected

* changed debug log to error

* added timeout for chat and action server

* added timeout for chat and action server

* added environment variable for chat and action server for timeout

* 1. added default config for kairon rule policy
2. added granian for action and chat server
3. added error log level for action and chat server

* 1. added default config for kairon rule policy
2. added granian for action and chat server

* fix multi-flow stories

* 1. fix action test
2. actor version
3. fix get request for external api

* add channel changes

* changed the name of kairon rule policy to KRulePolicy

* xray removed

* removed kairon KRulePolicy

* test cases fixed

* test cases fixed

* removed constrain_similarities

* moved kairon RulePolicy from base to chatserver

* changes tracker condition

* merged event db changes for db server

* added pyston

* email error fixed

* fix kairon history saving issue

* removed pyston from test pipeline

* base image version fix

* updated rasa version

* added meta data in tracker events

* fix form action not running

* added entities to slot autofill

* fix auto-fill feature for slots

* 1. form fixes

* hard delete for bot data.

* 1. added granian
2 added default tab

* build corected

* library updated

* removed granian

* form fix

* fixed test failures due to merge conflicts

* fixed test failures due to merge conflicts

* when intent is deleted then all the respected training example must be deleted

* test case fixed

* added asynccontext manager startup and shutdown event deprecated

* Fixed - All stories are getting converted to QnA after file upload.
1. Changed the logic of get_template_type function to retrieve the template type.
2. Fixed test cases.

* allow adding conditions to slot mappings and filter slot mappings attached to form

* change slack to slack_sdk deprecated

* changed the default port 8083 to somthing random

* apm turn off for services

* test case fixed for apm client

* test case fixed for apm client

* lifespan fixed for fastapi

* fixed test failure

* added dependency and fixed test failures

* Modified get_slot_mappings function.

* 1. added deprecated components for config
2. updated rasa and other libraries

* removed versions for domain.yml

* fix for add bot data in prod

* dependencies updated

* merged the prod changes

* library updated

* removed default path parameter and added google my business dependency

Co-authored-by: udit-pandey <[email protected]>
Co-authored-by: nupur-khare <[email protected]>

* fixed test failures post code merge from master

* added json support for pyscript action

* added json support for pyscript action

* Fixed - onboarding not working on new uat.
Changed domain.yml's path

* Upload & Download -> Database Action.

* Modified moto version in requirements.txt

* Modified moto version in requirements.txt and dev.txt

* Multiple parameters/collections in prompt action.
1. Gave prompt-specific hyperparameters, collection top_results, and similarity_threshold.
2. Added unit and integration test cases.
3. Fixed test cases.

* kairon 2.x changes merged in 3.x

* kairon 2.x changes merged in 3.x

* log level fixed

* log level fixed

* on boarding fix

* added test case for copy pretrained model

* kernel security fix

* onboarding fix

* onboarding fix test cases

* onboarding fix test cases

* 1. updated open ai embedding model
2. added security fix for amazonlinux

* removed docker build stage

* Fixed the download chat history issue on New UAT.

* Fixed the download chat history issue on New UAT and fixed the test case.

* download history fixed

* moved to single docker image

* history download fix

* removed force from gitlab pipeline

* changes in linkedin scope

* fixed chat test cases

* fixed chat test cases

* Gpt fix.

* fixed chat test cases

* gitlab ci stages removed

* removed release docker build

* prod changes merged

* updated rasa 3.6.18

* 1. added open telemetry
2. updated rasa to 3.6.19

* otel bootstrap corrected

* downgraded otel dude to dependencies issue

* packaging updated

* downgraded packing version

* added instrumentation for cli

* Line integration (#1158)

* tempurary commit

* Line platform integration

* removed unnecessary imports

---------

Co-authored-by: spandan.mondal <[email protected]>

* added only required library for instrumentation

* Fixed load model exception issue and fixed test cases. (#1159)

Co-authored-by: Mahesh <[email protected]>

* merged changes from production

* http action logs

* removed unidentifying resources

* Fixed Prompt action

* removed unidentifying resources

* Fixed Prompt action

* info logging for linkedin sso

* info logging for linkedin sso

* - removing 'run_async' as its no more required by rasa SDK

* Added default date range of 6 months for the trends APIs and made changes in aggregation pipeline for few APIs and fixed test cases. (#1167)

Co-authored-by: Mahesh <[email protected]>

* linkedin sso fix

* info logging for linkedin sso

* info logging for linkedin sso

* linkedin sso fix

* - removing 'run_async' as its no more required by rasa SDK

* - removing await for slack

* - Added link in template as dynamic link

* - Added link in template as dynamic link

* Prevent Any Slot (#1169)

* Added validation to prevent the slot with any type while adding or updating the form.

* Added validation to prevent the slot with any type while adding or updating the form.

---------

Co-authored-by: Mahesh <[email protected]>

* model training issue fixed

* fixed docker vulnerabilities

* fixed docker vulnerabilities

* live agent

* 1. added model train in Dockerfile
2. add the logic to handle flag for similarity prompt

* added logger for timestamp validation for history

* DB Action with user msg (#1176)

* db action query with user message and added and fixed few test cases.

* db action query with user message and added and fixed few test cases.

* db action query with user message and added and fixed few test cases.

* Added llm_settings validation while creating and updating the db_action.

---------

Co-authored-by: Mahesh <[email protected]>

* Slot mapping normalization (#1179)

Co-authored-by: spandan.mondal <[email protected]>

* changed tester roles for configure nudge and configure telemetry. (#1178)

Co-authored-by: Mahesh <[email protected]>

* fixed issue related to security

* fixed from_date issue on analytics api

* fixed from_date issue on analytics api

* Removed validation for the payload value while creating the db action (#1181)

Co-authored-by: Mahesh <[email protected]>

* fixed issue related to security

* Upload with Prompt Action (#1182)

* Fixed the validation issue for prompt action while uploading the files.

* Fixed the validation issue for prompt action while uploading the files.

* Added test cases for the prompt action with bot_content as source.

---------

Co-authored-by: Mahesh <[email protected]>

* fixed issue related to security

* Prompt Action response time (#1186)

* Added response time for the prompt action and fixed test cases

* Added response time for the prompt action and fixed test cases

---------

Co-authored-by: Mahesh <[email protected]>

* 1. rasa version updated
2. added single day for test script generation

* test cases fixed

* live agent integration

* live agent integration

* removed default bot in kairon

* live agent integration

* light agent -small changes

* light agent -small changes -part 2

* light agent -small changes -part 3

* light agent -code cleanup

* code cleanup

* code cleanup

* code cleanup

* code cleanup

* test case fixes

* test case fixes

* test case fixes

* flag for live agent, added type for live_agent_action in get_stories

---------

Co-authored-by: Fahad Ali Shaikh <[email protected]>
Co-authored-by: udit_pandey <[email protected]>
Co-authored-by: Nupur Khare <[email protected]>
Co-authored-by: Udit Pandey <[email protected]>
Co-authored-by: nupur-khare <[email protected]>
Co-authored-by: Mahesh <[email protected]>
Co-authored-by: hghuge <[email protected]>
Co-authored-by: spandan.mondal <[email protected]>
Co-authored-by: maheshsattala <[email protected]>
Co-authored-by: sushantpatade <[email protected]>
  • Loading branch information
11 people authored May 9, 2024
1 parent 5dc2c49 commit b17ecd4
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 13 deletions.
1 change: 0 additions & 1 deletion kairon/chat/handlers/channels/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ async def _handle_user_message(
@staticmethod
async def process_message(bot: str, user_message: UserMessage):
await AgentProcessor.handle_channel_message(bot, user_message)
#await AgentProcessor.get_agent(bot).handle_message(user_message)


class MessengerBot(OutputChannel):
Expand Down
2 changes: 2 additions & 0 deletions kairon/shared/data/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,8 @@ def get_stories(self, bot: Text):
step['type'] = StoryStepType.database_action.value
elif event['name'] in web_search_actions:
step["type"] = StoryStepType.web_search_action.value
elif event['name'] == 'live_agent_action':
step["type"] = StoryStepType.live_agent_action.value
elif str(event["name"]).startswith("utter_"):
step["type"] = StoryStepType.bot.value
else:
Expand Down
35 changes: 24 additions & 11 deletions kairon/shared/live_agent/live_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
class LiveAgentHandler:

@staticmethod
def is_live_agent_service_enabled():
v = Utility.environment.get('live_agent', {}).get('enable', False)
print(f"live agent {v}")
return v
@staticmethod
async def request_live_agent(bot_id: str, sender_id: str, channel: str):
if not LiveAgentHandler.is_live_agent_service_enabled():
return None
url = f"{Utility.environment['live_agent']['url']}/conversation/request"
auth_token = Utility.environment['live_agent']['auth_token']

Expand All @@ -28,20 +35,24 @@ async def request_live_agent(bot_id: str, sender_id: str, channel: str):
raise Exception(res.get('message', "Failed to process request"))
return res.get('data')


@staticmethod
async def close_conversation(identifier):
url = f"{Utility.environment['live_agent']['url']}/conversation/close/{identifier}"
headers = {
'Content-Type': 'application/json'
}
res, status, _ = await ActionUtility.execute_request_async(url, 'GET', None, headers)
if status != 200:
raise Exception(res.get('message', "Failed to process request"))
return res.get('data')
#
# @staticmethod
# async def close_conversation(identifier):
# if not LiveAgentHandler.is_live_agent_service_enabled():
# raise Exception("Live agent service is not enabled")
# url = f"{Utility.environment['live_agent']['url']}/conversation/close/{identifier}"
# headers = {
# 'Content-Type': 'application/json'
# }
# res, status, _ = await ActionUtility.execute_request_async(url, 'GET', None, headers)
# if status != 200:
# raise Exception(res.get('message', "Failed to process request"))
# return res.get('data')

@staticmethod
async def process_live_agent(bot_id, userdata: UserMessage):
if not LiveAgentHandler.is_live_agent_service_enabled():
raise Exception("Live agent service is not enabled")
text = userdata.text
if text is None or text.strip() == "":
return False
Expand All @@ -64,6 +75,8 @@ async def process_live_agent(bot_id, userdata: UserMessage):

@staticmethod
async def check_live_agent_active(bot_id, userdata: UserMessage):
if not LiveAgentHandler.is_live_agent_service_enabled():
return False
channel = userdata.output_channel.name()
sender_id = userdata.sender_id
url = f"{Utility.environment['live_agent']['url']}/conversation/status/{bot_id}/{channel}/{sender_id}"
Expand Down
1 change: 1 addition & 0 deletions system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,6 @@ core:
- SpacyFeaturizer

live_agent:
enable: true
url: ${LIVE_AGENT_SERVER_URL:"http://localhost:8000/api/v1"}
auth_token: ${LIVE_AGENT_AUTH_TOKEN:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoia2Fpcm9uIn0.EJXuG2n8dy72h9J-8SoIBToVmnB4gpXDGKg_Smcz-C8"}
56 changes: 55 additions & 1 deletion tests/integration_test/chat_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3735,4 +3735,58 @@ def test_chat_when_botownerchanged():
assert actual["success"]
assert not actual["error_code"]
assert actual["data"]
assert not actual["message"]
assert not actual["message"]



@pytest.mark.asyncio
async def _mock_check_live_agent_active_true(*args, **kwargs):
return True



@responses.activate
def test_channel_chat_when_live_agent_disabled():
def _mock_validate_hub_signature(*args, **kwargs):
return True
Utility.environment['live_agent']['enable'] = False
with patch.object(LiveAgentHandler, "check_live_agent_active", _mock_check_live_agent_active_true):
with mock.patch('kairon.shared.live_agent.live_agent.LiveAgentHandler.process_live_agent') as mock_process_live_agent:
with patch.object(InstagramHandler, "validate_hub_signature", _mock_validate_hub_signature):


response = client.post(
f"/api/bot/instagram/{bot}/{token}",
headers={"hub.verify_token": "valid"},
json={
"entry": [
{
"id": "17841456706109718",
"time": 1707144192,
"changes": [
{
"value": {
"from": {
"id": "6489091794524304",
"username": "_hdg_photography"
},
"media": {
"id": "18013303267972611",
"media_product_type": "REELS"
},
"id": "18009764417219042",
"parent_id": "18009764417219041",
"text": "Hi"
},
"field": "comments"
}
]
}
],
"object": "instagram"
})


actual = response.json()

mock_process_live_agent.assert_not_called()
1 change: 1 addition & 0 deletions tests/testing_data/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ core:
- SpacyEntityExtractor

live_agent:
enable: true
url: ${LIVE_AGENT_SERVER_URL:"http://localhost:8000/api/v1"}
auth_token: ${LIVE_AGENT_AUTH_TOKEN:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoia2Fpcm9uIn0.EJXuG2n8dy72h9J-8SoIBToVmnB4gpXDGKg_Smcz-C8"}

0 comments on commit b17ecd4

Please sign in to comment.