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

Support test code in python tools #175

Open
planetf1 opened this issue Nov 18, 2024 · 1 comment
Open

Support test code in python tools #175

planetf1 opened this issue Nov 18, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@planetf1
Copy link

The bee framework requires that Python tools contain only a single function, with optional imports.

When developing some python code for bee, it is useful to include some test code within the definition.

For example I would typically include something like this at the end:

if name == "main":
f = open('test-data', 'r')
find_stuff('mytextstring',f.read())

This makes it easy to run in vscode and then, for example, cut/paste directly into the bee framework.

There may be other ways of achieving the same goal, ie making it easier to develop small python functions, and then wrap them as an agent

This issue is targetted more at the UI - if coding using the API then there is more flexibility

@Tomas2D Tomas2D added the question Further information is requested label Nov 18, 2024
@JanPokorny
Copy link
Contributor

@planetf1 I am not a big fan of allowing this since people would get confused on what actually gets executed by our runtime. Allowing users to include code that never gets executed (by us) is just inviting trouble and confusion. That's why we settled on the requirement of only having a single function, to ensure that it's absolutely clear that only the function itself is executed by Bee -- so it's different from a standard python my_file.py which would execute top-level code instead.

Could you consider having a second separate test file for your local use?

from find_stuff import find_stuff
f = open('test-data', 'r')
find_stuff('mytextstring',f.read())

Alternatively, you could still copy-paste but only select the function itself, skip the if __name__ == "__main__": ... beneath it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants