最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

openai api - PandasAI Error in VS Code but Works in Google Colab - Stack Overflow

programmeradmin7浏览0评论

I'm using pandasai with AzureOpenAI to analyze a DataFrame. My code works fine in Google Colab but throws an error in VS Code.

Code:

import pandasai as pai
from pandasai_openai import AzureOpenAI
import os

def ask_pandas_ai(df, user_prompt, config_params):
    llm = AzureOpenAI(
        api_version=config_params["api_version"],
        azure_endpoint=config_params["openai_endpoint"],
        deployment_name=config_params["deployment_name"],
        api_token=os.environ["OPENAI_API_KEY"]
    )

    pai.config.set({"llm": llm, "verbose": True, "temperature": 0})

    prompt_template = f"""
    **Role**: Act as a data analyst tasked with extracting actionable insights from the provided dataset.

    **User's Key Question**: "{user_prompt}"

    **Response Requirements**:
    1. Calculate the average fuel level of the vehicles.
    2. Analyze how engine temperature and location temperature affect the fuel level.
    3. Provide insights into trends or anomalies in the data.

    **Forbidden Elements**:
    - Avoid vague phrases like "the data shows."
    - Refrain from suggesting further analysis without providing concrete insights.
    - Do not use technical terms like "SQL" or "statistical analysis."

    Focus on crafting a clear, concise narrative that highlights key findings and their business impact.
    """

    pai_df = pai.DataFrame(df.tail(5))
    result = pai_df.chat(prompt_template)
    print(result)
    return result

Error in VS Code: {'summary': ErrorResponse(type='error', value='Unfortunately, I was not able to get your answer. Please try again.')}

What I Tried: Verified that my Azure OpenAI API key is set correctly in the environment variables.

Ensured that the same API version, endpoint, and deployment name are used in both environments.

Checked for package version mismatches (pandasai, pandasai_openai, etc.).

Ran the script in Google Colab, where it worked fine.

Restarted VS Code and tried running the script again.

Questions: What could be causing this issue specifically in VS Code but not in Google Colab?

Are there any additional dependencies or environment configurations required for pandasai in VS Code?

How can I debug this further to identify the exact issue?

Would appreciate any help in resolving this!

发布评论

评论列表(0)

  1. 暂无评论