-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bot Specific Executor Logs #1572
Changes from 1 commit
277e6d5
b00d3c1
7e60e81
bcce2ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
from kairon.shared.data.processor import MongoProcessor | ||
from kairon.shared.data.training_data_generation_processor import TrainingDataGenerationProcessor | ||
from kairon.shared.data.utils import DataUtility | ||
from kairon.shared.events.processor import ExecutorProcessor | ||
from kairon.shared.importer.data_objects import ValidationLogs | ||
from kairon.shared.importer.processor import DataImporterLogProcessor | ||
from kairon.shared.live_agent.live_agent import LiveAgentHandler | ||
|
@@ -1705,6 +1706,27 @@ async def get_llm_logs( | |
return Response(data=data) | ||
|
||
|
||
@router.get("/executor/logs", response_model=Response) | ||
async def get_executor_logs( | ||
start_idx: int = 0, page_size: int = 10, | ||
event_class: str = None, task_type: str = None, | ||
current_user: User = Security(Authentication.get_current_user_and_bot, scopes=TESTER_ACCESS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid function call in argument default The static analysis tool Ruff has flagged a potential issue with performing a function call in the argument default for the To address this, you can modify the function signature as follows: from fastapi import Depends
@router.get("/executor/logs", response_model=Response)
async def get_executor_logs(
start_idx: int = 0,
page_size: int = 10,
event_class: str = None,
task_type: str = None,
current_user: User = Depends(Authentication.get_current_user_and_bot)
):
# ... rest of the function This change uses FastAPI's 🧰 Tools🪛 Ruff
|
||
): | ||
""" | ||
Get executor logs data based on filters provided. | ||
""" | ||
logs = list(ExecutorProcessor.get_executor_logs(current_user.get_bot(), start_idx, page_size, | ||
event_class=event_class, task_type=task_type)) | ||
row_cnt = ExecutorProcessor.get_row_count(current_user.get_bot(), | ||
event_class=event_class, | ||
task_type=task_type) | ||
data = { | ||
"logs": logs, | ||
"total": row_cnt | ||
} | ||
return Response(data=data) | ||
|
||
|
||
@router.get("/metadata/llm", response_model=Response) | ||
async def get_llm_metadata( | ||
current_user: User = Security(Authentication.get_current_user_and_bot, scopes=TESTER_ACCESS)) -> Response: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from abc import abstractmethod | ||
|
||
from typing import Any | ||
|
||
from kairon.shared.constants import EventClass | ||
from kairon.shared.data.constant import EVENT_STATUS, TASK_TYPE | ||
|
@@ -13,7 +13,7 @@ class ExecutorBase: | |
def execute_task(self, event_class: EventClass, data: dict, **kwargs): | ||
raise NotImplementedError("Provider not implemented") | ||
|
||
def log_task(self, event_class: EventClass, task_type: TASK_TYPE, data: dict, status: EVENT_STATUS, **kwargs): | ||
def log_task(self, event_class: EventClass, task_type: TASK_TYPE, data: Any, status: EVENT_STATUS, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Issue Detected: Type Inconsistency in The Recommendations:
🔗 Analysis chainApproved: The change from
To ensure this change doesn't introduce unexpected behavior, please run the following verification: |
||
from bson import ObjectId | ||
from kairon.shared.cloud.utils import CloudUtility | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from typing import Any | ||
|
||
import ujson as json | ||
import os | ||
import time | ||
|
@@ -57,7 +59,7 @@ def delete_file(bucket, file): | |
s3.delete_object(Bucket=bucket, Key=file) | ||
|
||
@staticmethod | ||
def trigger_lambda(event_class: EventClass, env_data: dict, task_type: TASK_TYPE = TASK_TYPE.ACTION.value, | ||
def trigger_lambda(event_class: EventClass, env_data: Any, task_type: TASK_TYPE = TASK_TYPE.ACTION.value, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing Changing the type annotation of Ensure Since |
||
from_executor: bool = False): | ||
""" | ||
Triggers lambda based on the event class. | ||
|
@@ -103,6 +105,9 @@ def log_task(event_class: EventClass, task_type: TASK_TYPE, data: dict, status: | |
from kairon.shared.events.data_objects import ExecutorLogs | ||
|
||
executor_log_id = kwargs.get("executor_log_id") if kwargs.get("executor_log_id") else ObjectId().__str__() | ||
bot_id = CloudUtility.get_bot_id_from_env_data(event_class, data, | ||
from_executor=kwargs.get("from_executor", False), | ||
task_type=task_type) | ||
Comment on lines
+108
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for In the |
||
|
||
try: | ||
log = ExecutorLogs.objects(executor_log_id=executor_log_id, task_type=task_type, event_class=event_class, | ||
|
@@ -116,9 +121,47 @@ def log_task(event_class: EventClass, task_type: TASK_TYPE, data: dict, status: | |
for key, value in kwargs.items(): | ||
if not getattr(log, key, None) and Utility.is_picklable_for_mongo({key: value}): | ||
setattr(log, key, value) | ||
log.bot = bot_id | ||
log.save() | ||
return executor_log_id | ||
|
||
@staticmethod | ||
def get_bot_id_from_env_data(event_class: EventClass, data: Any, **kwargs): | ||
bot = None | ||
from_executor = kwargs.get("from_executor") | ||
|
||
if isinstance(data, dict) and 'bot' in data: | ||
bot = data['bot'] | ||
|
||
elif event_class == EventClass.web_search: | ||
bot = data.get('bot') | ||
|
||
elif event_class == EventClass.pyscript_evaluator: | ||
predefined_objects = data.get('predefined_objects', {}) | ||
|
||
if 'slot' in predefined_objects and 'bot' in predefined_objects['slot']: | ||
bot = predefined_objects['slot']['bot'] | ||
|
||
task_type = kwargs.get("task_type") | ||
if task_type == "Callback" and 'bot' in predefined_objects: | ||
bot = predefined_objects['bot'] | ||
Comment on lines
+145
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type mismatch when comparing In line 146, if task_type == "Callback" and 'bot' in predefined_objects: If
This ensures that the comparison behaves correctly. |
||
|
||
elif event_class == EventClass.scheduler_evaluator and isinstance(data, list): | ||
for item in data: | ||
if item.get('name') == 'PREDEFINED_OBJECTS': | ||
predefined_objects = item.get('value', {}) | ||
if 'bot' in predefined_objects: | ||
bot = predefined_objects['bot'] | ||
break | ||
|
||
elif from_executor and isinstance(data, list): | ||
for item in data: | ||
if item.get('name') == 'BOT': | ||
bot = item.get('value') | ||
break | ||
|
||
return bot | ||
Comment on lines
+128
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor The
|
||
|
||
@staticmethod | ||
def lambda_execution_failed(response): | ||
return (response['StatusCode'] != 200 or | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from kairon.shared.events.data_objects import ExecutorLogs | ||
|
||
|
||
class ExecutorProcessor: | ||
|
||
@staticmethod | ||
def get_executor_logs(bot: str, start_idx: int = 0, page_size: int = 10, **kwargs): | ||
""" | ||
Get all executor logs data . | ||
@param bot: bot id. | ||
@param start_idx: start index | ||
@param page_size: page size | ||
@return: list of logs. | ||
""" | ||
event_class = kwargs.get("event_class") | ||
task_type = kwargs.get("task_type") | ||
query = {"bot": bot} | ||
if event_class: | ||
query.update({"event_class": event_class}) | ||
if task_type: | ||
query.update({"task_type": task_type}) | ||
for log in ExecutorLogs.objects(**query).order_by("-timestamp").skip(start_idx).limit(page_size): | ||
executor_logs = log.to_mongo().to_dict() | ||
executor_logs.pop('_id') | ||
yield executor_logs | ||
|
||
@staticmethod | ||
def get_row_count(bot: str, **kwargs): | ||
""" | ||
Gets the count of rows in a ExecutorLogs for a particular bot. | ||
:param bot: bot id | ||
:return: Count of rows | ||
""" | ||
event_class = kwargs.get("event_class") | ||
task_type = kwargs.get("task_type") | ||
query = {"bot": bot} | ||
if event_class: | ||
query.update({"event_class": event_class}) | ||
if task_type: | ||
query.update({"task_type": task_type}) | ||
return ExecutorLogs.objects(**query).count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Some calls to
perform_web_search
are missing thebot
parameter.Please update all instances of
perform_web_search
to include thebot
parameter to ensure consistency and proper functionality.Affected locations:
tests/unit_test/action/action_test.py
tests/integration_test/action_service_test.py
🔗 Analysis chain
LGTM! Consider updating docstring and verify other method calls.
The addition of the
bot
parameter to theperform_web_search
method call is correct and consistent with the changes mentioned in the summary. This change allows for better flexibility and potentially improved separation of concerns.However, to ensure completeness:
perform_web_search
in the codebase have been updated to include this new parameter.execute
method to reflect this change, mentioning that it now passes the bot information to the web search function.To verify other calls to
perform_web_search
, you can run the following script:This will help ensure that all relevant calls have been updated consistently across the codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 90
Script:
Length of output: 6976