Skip to content

Commit 40a4ad4

Browse files
authored
Merge pull request #1830 from sinaptik-ai/fix/result_not_found_error
fix: template not adding the response type
2 parents dc51adb + 0e12f38 commit 40a4ad4

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

‎pandasai/core/code_execution/code_executor.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def execute_and_return_result(self, code: str) -> Any:
3939

4040
# Get the result
4141
if "result" not in self._environment:
42-
raise NoResultFoundError("No result returned")
42+
raise NoResultFoundError(
43+
"No result was returned from the code execution. Please return the result in dictionary format, for example: result = {'type': ..., 'value': ...}"
44+
)
4345

4446
return self._environment.get("result", None)
4547

‎pandasai/core/prompts/templates/generate_python_code_with_sql.tmpl‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def execute_sql_query(sql_query: str) -> pd.Dataframe
1010
"""This method connects to the database, executes the sql query and returns the dataframe"""
1111
</function>
1212

13-
{% if last_code_generated != "" and context.memory.count() > 0 %}
13+
{% if last_code_generated and context.memory.count() > 0 %}
14+
Last code generated:
1415
{{ last_code_generated }}
1516
{% else %}
1617
Update this initial code:
@@ -26,7 +27,8 @@ import pandas as pd
2627
{% include 'shared/vectordb_docs.tmpl' with context %}
2728
{{ context.memory.get_last_message() }}
2829

29-
At the end, declare "result" variable as a dictionary of type and value.
30+
At the end, declare "result" variable as a dictionary of type and value in the following format:
31+
{% include 'shared/output_type_template.tmpl' with context %}
3032

3133

3234
Generate python code and return full updated code:

‎tests/unit_tests/prompts/test_sql_prompt.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ def execute_sql_query(sql_query: str) -> pd.Dataframe
9494
9595
9696
97-
At the end, declare "result" variable as a dictionary of type and value.
97+
At the end, declare "result" variable as a dictionary of type and value in the following format:
98+
99+
{output_type_template}
100+
98101
99102
100103
Generate python code and return full updated code:

0 commit comments

Comments
 (0)