Skip to content
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

add log feedback #309

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion application/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def user_feedback(input_data: FeedBackInput):
return upvote_res
else:
downvote_res = service.user_feedback_downvote(input_data.data_profiles, user_id, session_id, input_data.query,
input_data.query_intent, input_data.query_answer)
input_data.query_intent, input_data.query_answer,
input_data.error_description, input_data.error_categories,
input_data.correct_sql_reference)
return downvote_res


Expand Down
3 changes: 3 additions & 0 deletions application/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class FeedBackInput(BaseModel):
query_answer: str
session_id: str = "-1"
user_id: str = "admin"
error_description: str = ""
error_categories: str = ""
correct_sql_reference: str = ""


class Option(BaseModel):
Expand Down
17 changes: 12 additions & 5 deletions application/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from nlq.business.connection import ConnectionManagement
from nlq.business.datasource.factory import DataSourceFactory
from nlq.business.log_feedback import FeedBackManagement
from nlq.business.model import ModelManagement
from nlq.business.nlq_chain import NLQChain
from nlq.business.profile import ProfileManagement
Expand Down Expand Up @@ -297,26 +298,32 @@ def user_feedback_upvote(data_profiles: str, user_id: str, session_id: str, quer


def user_feedback_downvote(data_profiles: str, user_id: str, session_id: str, query: str, query_intent: str,
query_answer):
query_answer, error_description="", error_categories="", correct_sql_reference=""):
try:
error_info_dict = {
"error_description": error_description,
"error_categories": error_categories,
"correct_sql_reference": correct_sql_reference
}
error_info = json.dumps(error_info_dict, ensure_ascii=False)
if query_intent == "normal_search":
log_id = generate_log_id()
current_time = get_current_time()
LogManagement.add_log_to_database(log_id=log_id, user_id=user_id, session_id=session_id,
FeedBackManagement.add_log_to_database(log_id=log_id, user_id=user_id, session_id=session_id,
profile_name=data_profiles,
sql=query_answer, query=query,
intent="normal_search_user_downvote",
log_info="",
log_info=error_info,
time_str=current_time,
log_type="feedback_downvote")
elif query_intent == "agent_search":
log_id = generate_log_id()
current_time = get_current_time()
LogManagement.add_log_to_database(log_id=log_id, user_id=user_id, session_id=session_id,
FeedBackManagement.add_log_to_database(log_id=log_id, user_id=user_id, session_id=session_id,
profile_name=data_profiles,
sql=query_answer, query=query,
intent="agent_search_user_downvote",
log_info="",
log_info=error_info,
time_str=current_time,
log_type="feedback_downvote")
return True
Expand Down
5 changes: 3 additions & 2 deletions application/nlq/business/connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging

from nlq.data_access.dynamo_connection import ConnectConfigDao, ConnectConfigEntity
from nlq.data_access.database import RelationDatabase
from utils.logging import getLogger

logger = logging.getLogger(__name__)
logger = getLogger()


class ConnectionManagement:
Expand Down
18 changes: 18 additions & 0 deletions application/nlq/business/log_feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import logging

from nlq.data_access.dynamo_query_log import DynamoQueryLogDao
from utils.logging import getLogger

logger = getLogger()


class FeedBackManagement:
dynammo_log_dao = DynamoQueryLogDao()

@classmethod
def add_log_to_database(cls, log_id, user_id, session_id, profile_name, sql, query, intent, log_info, time_str,
log_type='chat_history'):
cls.dynammo_log_dao.add_log(log_id=log_id, profile_name=profile_name, user_id=user_id, session_id=session_id,
sql=sql, query=query, intent=intent, log_info=log_info, time_str=time_str,
log_type=log_type)
4 changes: 2 additions & 2 deletions application/nlq/business/log_store.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import logging

from nlq.data_access.opensearch_query_log import OpenSearchQueryLogDao
from utils.logging import getLogger

logger = logging.getLogger(__name__)
logger = getLogger()


class LogManagement:
Expand Down
5 changes: 3 additions & 2 deletions application/nlq/business/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging

from nlq.data_access.dynamo_model import ModelConfigDao, ModelConfigEntity
from utils.logging import getLogger

logger = logging.getLogger(__name__)
logger = getLogger()


class ModelManagement:
Expand Down
5 changes: 3 additions & 2 deletions application/nlq/business/profile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging

from nlq.data_access.dynamo_profile import ProfileConfigDao, ProfileConfigEntity
from utils.logging import getLogger

logger = logging.getLogger(__name__)
logger = getLogger()

class ProfileManagement:
profile_config_dao = ProfileConfigDao()
Expand Down
6 changes: 3 additions & 3 deletions application/nlq/business/vector_store.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
import os

import boto3
import json
from nlq.data_access.opensearch import OpenSearchDao
from utils.env_var import BEDROCK_REGION, AOS_HOST, AOS_PORT, AOS_USER, AOS_PASSWORD, opensearch_info, \
SAGEMAKER_ENDPOINT_EMBEDDING
from utils.env_var import bedrock_ak_sk_info
from utils.llm import invoke_model_sagemaker_endpoint
from utils.logging import getLogger

logger = logging.getLogger(__name__)
logger = getLogger()


class VectorStore:
Expand Down