Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] handles py code? #1062

Closed
lucasjinreal opened this issue Dec 26, 2023 · 15 comments · Fixed by #2144
Closed

[Bug] handles py code? #1062

lucasjinreal opened this issue Dec 26, 2023 · 15 comments · Fixed by #2144
Assignees
Labels
code-execution execute generated code good first issue Good for newcomers

Comments

@lucasjinreal
Copy link
Collaborator

请尝试使用以下更新的代码:
```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?
@rickyloynd-microsoft
Copy link
Contributor

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

@lucasjinreal
Copy link
Collaborator Author

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

@rickyloynd-microsoft
Copy link
Contributor

@sonichi

@sonichi sonichi added the code-execution execute generated code label Dec 30, 2023
@sonichi
Copy link
Contributor

sonichi commented Dec 30, 2023

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

@sonichi sonichi added the good first issue Good for newcomers label Dec 30, 2023
@SANTHOSH-MAMIDISETTI
Copy link

SANTHOSH-MAMIDISETTI commented Jan 13, 2024

@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 ,

@sonichi
Copy link
Contributor

sonichi commented Jan 13, 2024

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

@SANTHOSH-MAMIDISETTI
Copy link

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
Copy link

I'm currently encountering difficulty in assigning myself.

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

@rickyloynd-microsoft
Copy link
Contributor

I'm currently encountering difficulty in assigning myself.

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

I just assigned you.

@sonichi
Copy link
Contributor

sonichi commented Jan 13, 2024

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:

elif lang in ["python", "Python"]:

@SANTHOSH-MAMIDISETTI
Copy link

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

@sonichi
Copy link
Contributor

sonichi commented Jan 13, 2024

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

@debianmaster
Copy link

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

@sonichi
Copy link
Contributor

sonichi commented Jan 13, 2024

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:

raise NotImplementedError(f"{lang} not recognized in code execution")

@SANTHOSH-MAMIDISETTI
Copy link

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

JoshTrim added a commit to JoshTrim/autogen that referenced this issue Mar 25, 2024
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Mar 26, 2024
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Apr 11, 2024
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Apr 11, 2024
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Apr 11, 2024
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Apr 11, 2024
)

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Apr 11, 2024
JoshTrim added a commit to JoshTrim/autogen that referenced this issue Apr 12, 2024
github-merge-queue bot pushed a commit that referenced this issue Apr 12, 2024
* Add "py" as lang in conversable agent (#1062)

* Add conditions to allow for python executable variants (#1062)

* reverted import (#1062)

* Parameterized tests, moved Python variants to a constant (#1062)

* Moved Python variants to a constant (#1062)

* Update autogen/code_utils.py (#1062)

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* Update autogen/coding/local_commandline_code_executor.py (#1062)

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* Added PYTHON_VARIANTS as imported constant (#1062)

* ran pre-commit-check  (#1062)

---------

Co-authored-by: Chi Wang <wang.chi@microsoft.com>
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
jayralencar pushed a commit to jayralencar/autogen that referenced this issue May 28, 2024
* Add "py" as lang in conversable agent (microsoft#1062)

* Add conditions to allow for python executable variants (microsoft#1062)

* reverted import (microsoft#1062)

* Parameterized tests, moved Python variants to a constant (microsoft#1062)

* Moved Python variants to a constant (microsoft#1062)

* Update autogen/code_utils.py (microsoft#1062)

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* Update autogen/coding/local_commandline_code_executor.py (microsoft#1062)

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* Added PYTHON_VARIANTS as imported constant (microsoft#1062)

* ran pre-commit-check  (microsoft#1062)

---------

Co-authored-by: Chi Wang <wang.chi@microsoft.com>
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-execution execute generated code good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants