pandas-ai icon indicating copy to clipboard operation
pandas-ai copied to clipboard

error requesting data in `json` format

Open avelino opened this issue 1 year ago • 0 comments

traceback:

Traceback (most recent call last):
  File "/Users/avelino/projects/buser/openapi/recommendation-next-travel/use-pandasai.py", line 43, in <module>
    print(pandas_ai.run(
          ^^^^^^^^^^^^^^
  File "/Users/avelino/projects/buser/openapi/recommendation-next-travel/.venv/lib/python3.11/site-packages/pandasai/__init__.py", line 120, in run
    answer = self.run_code(code, data_frame, False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/avelino/projects/buser/openapi/recommendation-next-travel/.venv/lib/python3.11/site-packages/pandasai/__init__.py", line 166, in run_code
    exec(code)
  File "<string>", line 9, in <module>
NameError: name 'json' is not defined

source:

data = {...}
df = pd.DataFrame(data)
llm = OpenAI()
pandas_ai = PandasAI(llm)

print(pandas_ai.run(
    df,
    prompt="""
    suggest when the next trip will be, destination and seat type,
    in JSON format: {"destination": "", "seat-type": ""}
    """))

proposed solution

how I solved it locally, but I believe it is not the best way

add import json in __init__.py

avelino avatar May 04 '23 09:05 avelino