-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Allow caller to handle help/argument exceptions #3715
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
Conversation
|
Is the only functional change in this 100-line PR the fact that log_print_usage is now also called on errors? What would the caller want to do besides end the program if invalid command-line arguments were passed? |
Currently, applications in the examples directory simply print the usage message. However, when embedding the common logic as a C/C++ plugin for interpreted languages (which is something I'm working on), it is always desirable not to exit when the arguments are wrong or help is requested. The desired behavior in that case is to let the higher-level language determine if/when to exit the application. Due to the complexity and sheer number of arguments which can be supplied to llama-based applications, it is desirable to have the common logic parse/process command-line arguments instead of having to duplicate the work. |
|
Are you proposing that common.cpp should become a public API? As far as I know, it is only intended to be a place for code that is shared between the internal example programs. |
I think there is sufficient functionality within common to consider moving (at least some) to a public API. As is evident by the number of applications within While that is a lot broader in scope than the changes proposed in this PR—a more flexible way to respond to user input always helps toward that end. 🙂 |
|
@cebtenzzre Per your feedback I reduced the scope of the change by hiding the implementation in a new |
ggerganov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The common code might become some sort of higher-level API in the future, but currently this is not the focus and there are not plans to do so. It's strongly recommended that 3rd party projects avoid using it or depending on it.
Co-authored-by: Georgi Gerganov <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
Understood—I will dream up another solution once the code velocity slows. Thank you for the quick turnaround on this PR in the meantime! |
* Allow caller to handle help/argument exceptions * Prepend newline to usage output * Add new gpt_params_parse_ex function to hide arg-parse impl * Fix issue blocking success case * exit instead of returning false * Update common/common.h Co-authored-by: Georgi Gerganov <[email protected]> * Update common/common.cpp Co-authored-by: Georgi Gerganov <[email protected]> --------- Co-authored-by: Georgi Gerganov <[email protected]>
This change improves robustness of argument-parsing logic by allowing the caller to decide what to do when
-h/--helpis supplied, or when an invalid argument is supplied by the user.