autogen icon indicating copy to clipboard operation
autogen copied to clipboard

[Bug] handles py code?

Open lucasjinreal opened this issue 2 years ago • 15 comments

请尝试使用以下更新的代码:
```py
# filename: news_report.py

import requests

url = 'https://newsapi.org/v2/top-headlines?country=us&apiKey=<your_api_key>'
response = requests.get(url)
data = response.json()

headlines = [article['title'] for article in data['articles']]
markdown_report = '\n'.join(['- ' + headline for headline in headlines])

print(markdown_report)

在您的计算机上创建一个名为news_report.py的新文件,并将此代码粘贴到其中。 然后,请替换<your_api_key>为您的News API密钥。 如果您没有密钥,请访问News API注册并获取一个免费的API密钥。 保存文件后,在命令行中运行以下命令以执行脚本:

python news_report.py

当脚本成功执行时,它将显示新闻标题列表。 请注意,由于API限制和网络延迟,结果可能有所不同。


EXECUTING CODE BLOCK 0 (inferred language is py)... user_proxy (to assistant):

exitcode: 1 (execution failed) Code output: unknown language py



How to handle py code?

Obviously, py is a valid lan in most markdown format...... and very human knows it's python, why this stupid agent not?

lucasjinreal avatar Dec 26 '23 12:12 lucasjinreal

@lucasjinreal Can you provide a complete example in English only?

rickyloynd-microsoft avatar Dec 26 '23 15:12 rickyloynd-microsoft

For summay, the code can not be executed when LLM produces code in markdown format with py code mark.

lucasjinreal avatar Dec 27 '23 02:12 lucasjinreal

@sonichi

rickyloynd-microsoft avatar Dec 27 '23 02:12 rickyloynd-microsoft

Let's add "py" to line 1119 of conversable_agent.py

sonichi avatar Dec 30 '23 19:12 sonichi

@rickyloynd-microsoft @sonichi is it solved or there is something to be worked on to solve it ?, If yes , I am interested in working on this issue ,

SANTHOSH-MAMIDISETTI avatar Jan 13 '24 13:01 SANTHOSH-MAMIDISETTI

It's not solved. You can assign yourself and work on it.

sonichi avatar Jan 13 '24 14:01 sonichi

Let's add "py" to line 1119 of conversable_agent.py

@sonichi can you please elaborate what does this mean, I have briefly gone through the conversable_agent.py present at autogen/agentchat/conversable_agent.py and also the line number 1119 image

It was an else statement. Maybe I am missing a few more details , I am not quite sure of how to proceed

Let's add "py" to line 1119 of conversable_agent.py

suggestions are appreciated :)

SANTHOSH-MAMIDISETTI avatar Jan 13 '24 15:01 SANTHOSH-MAMIDISETTI

I'm currently encountering difficulty in assigning myself.

It's not solved. You can assign yourself and work on it.

SANTHOSH-MAMIDISETTI avatar Jan 13 '24 15:01 SANTHOSH-MAMIDISETTI

I'm currently encountering difficulty in assigning myself.

It's not solved. You can assign yourself and work on it.

I just assigned you.

rickyloynd-microsoft avatar Jan 13 '24 15:01 rickyloynd-microsoft

Let's add "py" to line 1119 of conversable_agent.py

@sonichi can you please elaborate what does this mean, I have briefly gone through the conversable_agent.py present at autogen/agentchat/conversable_agent.py and also the line number 1119 image

It was an else statement. Maybe I am missing a few more details , I am not quite sure of how to proceed

Let's add "py" to line 1119 of conversable_agent.py

suggestions are appreciated :)

The file is updated. The new line is: https://github.com/microsoft/autogen/blob/44260934f34b2e237fbf6d3da0cedd514642e294/autogen/agentchat/conversable_agent.py#L1395

sonichi avatar Jan 13 '24 15:01 sonichi

Oh alright, in that case , I believe that the issue has been solved ? @sonichi @rickyloynd-microsoft

or the same line has to be added even at line 1119 as mentioned in the below

Let's add "py" to line 1119 of conversable_agent.py

SANTHOSH-MAMIDISETTI avatar Jan 13 '24 16:01 SANTHOSH-MAMIDISETTI

It hasn't been solved. Just the line number has changed.

sonichi avatar Jan 13 '24 16:01 sonichi

can you also add support for language type "yaml" for which a file has to be created ? just guide me so i can change

debianmaster avatar Jan 13 '24 19:01 debianmaster

can you also add support for language type "yaml" for which a file has to be created ? just guide me so i can change

Two places need to be modified to add an "elif" branch: https://github.com/microsoft/autogen/blob/44260934f34b2e237fbf6d3da0cedd514642e294/autogen/code_utils.py#L224 https://github.com/microsoft/autogen/blob/44260934f34b2e237fbf6d3da0cedd514642e294/autogen/agentchat/conversable_agent.py#L1406

sonichi avatar Jan 13 '24 19:01 sonichi

In that case, I think , adding "py" along with python and all other languages mentioned over there completes this issue , is that all ?

SANTHOSH-MAMIDISETTI avatar Jan 14 '24 10:01 SANTHOSH-MAMIDISETTI