Skip to content

Commit

Permalink
Adding the note to not found entity
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadrezaPourreza committed Mar 26, 2024
1 parent 688f7b0 commit 7ea0148
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions dataherald/services/sql_generations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def update_the_initial_sql_generation(
initial_sql_generation.status = sql_generation.status
initial_sql_generation.error = sql_generation.error
initial_sql_generation.intermediate_steps = sql_generation.intermediate_steps
initial_sql_generation.metadata.update(sql_generation.metadata)
return self.sql_generation_repository.update(initial_sql_generation)

def create(
Expand Down
2 changes: 1 addition & 1 deletion dataherald/sql_generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from typing import Any, Dict, List, Tuple

import sqlparse
from sql_metadata import Parser
from langchain.agents.agent import AgentExecutor
from langchain.callbacks.base import BaseCallbackHandler
from langchain.schema import AgentAction, LLMResult
from langchain.schema.messages import BaseMessage
from langchain_community.callbacks import get_openai_callback
from sql_metadata import Parser

from dataherald.config import Component, System
from dataherald.db_scanner.models.types import TableDescription
Expand Down
3 changes: 2 additions & 1 deletion dataherald/sql_generator/dataherald_finetuning_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ class QuerySQLDataBaseTool(BaseSQLDatabaseTool, BaseTool):
description = """
Input: SQL query.
Output: Result from the database or an error message if the query is incorrect.
Use this tool to execute the SQL query on the database, and return the results.
Use this tool to execute the SQL query on the database.
If the returned result is empty, mention as a comment in you final answer that the SQL query returned no results.
"""
args_schema: Type[BaseModel] = SQLInput

Expand Down
5 changes: 3 additions & 2 deletions dataherald/sql_generator/dataherald_sqlagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class QuerySQLDataBaseTool(BaseSQLDatabaseTool, BaseTool):
Output: Result from the database or an error message if the query is incorrect.
If an error occurs, rewrite the query and retry.
Use this tool to execute SQL queries.
If the returned result is empty, mention as a comment in you final answer that the SQL query returned no results.
"""

@catch_exceptions()
Expand Down Expand Up @@ -315,10 +316,10 @@ class ColumnEntityChecker(BaseSQLDatabaseTool, BaseTool):
Input: Column name and its corresponding table, and an entity.
Output: cell-values found in the column similar to the given entity.
Use this tool to get cell values similar to the given entity in the given column.
IF this tool returns no results, try to generate a SQL query regardless.
If this tool returns no results, try to generate a SQL query regardless. Also mention as a comment in the SQL query that the entity was not found in the column.
Example Input: table1 -> column2, entity
"""
""" # noqa: E501

def find_similar_strings(
self, input_list: List[tuple], target_string: str, threshold=0.4
Expand Down
3 changes: 3 additions & 0 deletions dataherald/utils/agent_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
tip5) If SQL results has None or NULL values, handle them by adding a WHERE clause to filter them out.
tip6) The existance of the string values in the columns should always be checked using the DbColumnEntityChecker tool.
tip7) You should always execute the SQL query by calling the SqlDbQuery tool to make sure the results are correct.
tip8) If DBEntityChecker tool returns no entity values, you should still write a SQL query. But add a comment in the SQL query that the entity values were not found.
""" # noqa: E501

PLAN_WITH_INSTRUCTIONS = """1) Use the DbTablesWithRelevanceScores tool to find relevant tables.
Expand All @@ -46,6 +47,7 @@
tip3) If SQL results has None or NULL values, handle them by adding a WHERE clause to filter them out.
tip4) The existance of the string values in the columns should always be checked using the DbColumnEntityChecker tool.
tip5) You should always execute the SQL query by calling the SqlDbQuery tool to make sure the results are correct.
tip6) If DBEntityChecker tool returns no entity values, you should still write a SQL query. But add a comment in the SQL query that the entity values were not found.
""" # noqa: E501

PLAN_WITH_FEWSHOT_EXAMPLES = """1) Use the FewshotExamplesRetriever tool to retrieve samples of Question/SQL pairs that are similar to the given question, if there is a similar question among the examples, use the SQL query from the example and modify it to fit the given question.
Expand All @@ -63,6 +65,7 @@
tip4) If SQL results has None or NULL values, handle them by adding a WHERE clause to filter them out.
tip5) The existance of the string values in the columns should always be checked using the DbColumnEntityChecker tool.
tip6) You should always execute the SQL query by calling the SqlDbQuery tool to make sure the results are correct.
tip7) If DBEntityChecker tool returns no entity values, you should still write a SQL query. But add a comment in the SQL query that the entity values were not found.
""" # noqa: E501

PLAN_BASE = """1) Use the DbTablesWithRelevanceScores tool to find relevant tables.
Expand Down

0 comments on commit 7ea0148

Please sign in to comment.