Skip to content

Commit

Permalink
DH-4314 Add more logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjc712 committed Jul 27, 2023
1 parent cda7835 commit ce00148
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dataherald/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def scan_db(self, db_alias: str, table_name: str | None = None) -> bool:
@override
def answer_question(self, question: str, db_alias: str) -> NLQueryResponse:
"""Takes in an English question and answers it based on content from the registered databases"""
logger.info(f"Answer question: {question}")
cache = self.system.instance(SmartCache)
sql_generation = self.system.instance(SQLGenerator)
evaluator = self.system.instance(Evaluator)
Expand All @@ -95,6 +96,8 @@ def answer_question(self, question: str, db_alias: str) -> NLQueryResponse:
generated_answer = sql_generation.generate_response(
user_question, database_connection, context
)

logger.info("Starts evaluator...")
if evaluator.is_acceptable_response(
user_question, generated_answer, database_connection
):
Expand Down
3 changes: 1 addition & 2 deletions dataherald/context_store/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def __init__(self, system: System):
def retrieve_context_for_question(
self, nl_question: NLQuery, number_of_samples: int = 3
) -> List[dict] | None:
logger.info(f"getting context for {nl_question.question}")

logger.info(f"Getting context for {nl_question.question}")
closest_questions = self.vector_store.query(
query_texts=[nl_question.question],
db_alias=nl_question.db_alias,
Expand Down
2 changes: 1 addition & 1 deletion dataherald/smart_cache/in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, settings: Settings):

@override
def add(self, key: str, value: NLQueryResponse) -> dict[str, Any]:
logger.info(f"Adding to cache: {value.dict()}")
logger.info(f"Adding to cache: {key}")
self.cache[key] = value
return {key: value}

Expand Down
4 changes: 4 additions & 0 deletions dataherald/sql_database/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SQL wrapper around SQLDatabase in langchain."""
import logging
from typing import Any, List

from langchain.sql_database import SQLDatabase as LangchainSQLDatabase
Expand All @@ -9,6 +10,8 @@
from dataherald.sql_database.models.types import DatabaseConnection
from dataherald.utils.encrypt import FernetEncrypt

logger = logging.getLogger(__name__)


class SQLDatabase(LangchainSQLDatabase):
"""SQL Database.
Expand Down Expand Up @@ -43,6 +46,7 @@ def from_uri(

@classmethod
def get_sql_engine(cls, database_info: DatabaseConnection) -> "SQLDatabase":
logger.info(f"Connecting db: {database_info.alias}")
fernet_encrypt = FernetEncrypt()
if database_info.use_ssh:
return cls.from_uri_ssh(database_info)
Expand Down
4 changes: 2 additions & 2 deletions dataherald/sql_generator/langchain_sqlchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ def generate_response(
context: List[dict] = None,
) -> NLQueryResponse:
start_time = time.time()
self.database = SQLDatabase.get_sql_engine(database_connection)
logger.info(
f"Generating SQL response to question: {str(user_question.dict())} with passed context {context}"
)
self.database = SQLDatabase.get_sql_engine(database_connection)
if context is not None:
samples_prompt_string = "The following are some similar previous questions and their correct SQL queries from these databases: \
\n"
for sample in context:
samples_prompt_string += (
f"Question: {sample['nl_question']} \nSQL: {sample['sql_query']} \n"
)
if context is not None:

prompt = PROMPT_WITH_CONTEXT.format(
user_question=user_question.question, context=samples_prompt_string
)
Expand Down

0 comments on commit ce00148

Please sign in to comment.