Skip to content

Commit

Permalink
DH-5001/removing the markdowns from queries for gpt-4-turbo (#247)
Browse files Browse the repository at this point in the history
* DH-5001/removing the markdowns from queries for gpt-4-turbo

* DH-5001/reformat with black

* DH-5001/add logs
  • Loading branch information
MohammadrezaPourreza authored Nov 14, 2023
1 parent a6040cf commit efea0c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dataherald/sql_generator/dataherald_sqlagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def _run(
run_manager: CallbackManagerForToolRun | None = None, # noqa: ARG002
) -> str:
"""Execute the query, return the results or an error message."""
if "```sql" in query:
logger.info("**** Removing markdown formatting from the query\n")
query = query.replace("```sql", "").replace("```", "")
logger.info(f"**** Query after removing markdown formatting: {query}\n")
return self.db.run_sql(query, top_k=top_k)[0]

async def _arun(
Expand Down Expand Up @@ -690,7 +694,14 @@ def generate_response(
for step in result["intermediate_steps"]:
action = step[0]
if type(action) == AgentAction and action.tool == "sql_db_query":
sql_query_list.append(self.format_sql_query(action.tool_input))
query = self.format_sql_query(action.tool_input)
if "```sql" in query:
logger.info("**** Removing markdown formatting from the query\n")
query = query.replace("```sql", "").replace("```", "")
logger.info(
f"**** Query after removing markdown formatting: {query}\n"
)
sql_query_list.append(query)
intermediate_steps = self.format_intermediate_representations(
result["intermediate_steps"]
)
Expand Down
2 changes: 2 additions & 0 deletions dataherald/utils/models_context_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
"gpt-3.5-turbo-0613": 4000,
"gpt-3.5-turbo-16k-0613": 16000,
"gpt-3.5-turbo-0301": 4000,
"gpt-4-1106-preview": 128000,
"gpt-3.5-turbo-1106": 16000,
}

0 comments on commit efea0c3

Please sign in to comment.