devinyf / langchain_qianwen

11 stars 2 forks source link

执行create_pandas_dataframe_agent出现问题 #4

Open rioshyb opened 4 months ago

rioshyb commented 4 months ago

代码: agent = create_pandas_dataframe_agent(llm, df, prefix=custom_prefix, verbose=True)

agent("""validate the following hypothesis with t-test. Null Hypothesis: the survived count of children(age < 12) is less than adult. Alternate Hypothesis: the survived count of children(age < 12) is more than adult.if some python libs are required,import these libs at the beginning'""") 返回是专业的: Action Input:


import numpy as np
from scipy.stats import ttest_ind

# Filter passengers into children and adults
children = df[df['Age'] < 12]
adults = df[df['Age'] >= 12]

# Count the number of survivors for each group
survivors_children = children['Survived'].sum()
survivors_adults = adults['Survived'].sum()

# Calculate the sample sizes
n_children = children.shape[0]
n_adults = adults.shape[0]

# Perform two-sample t-test
t_statistic, p_value = ttest_ind(children['Survived'], adults['Survived'], equal_var=False)

survivors_children, survivors_adults, t_statistic, p_value
```NameError: name 'py' is not definedThe error persists. It seems there's a misunderstanding here, as the `py` variable isn't defined anywhere in the code. Let me try running the corrected code without the reference to `py`.
生成python代码里面一直有py,python_repl_ast解析不了
devinyf commented 4 months ago

我跑下面这个官方的例子, 生成的代码可以正确执行 https://python.langchain.com/v0.1/docs/integrations/toolkits/pandas/ 测试的模型: model_name="qwen-turbo"

as the py variable isn't defined anywhere in the code

这个原因可能是因为代码解释器运行生成的代码的时候, 错误的使用了 py main.py 来运行代码,而系统无法识别 py 正常的情况应该是: python main.py

可以试试在环境变量中手动添加一个 alias 如:

alias py='python3'

看能否解决这个问题