DEV Community

Cover image for DocBot: New Feature Update
Ajo George
Ajo George

Posted on

DocBot: New Feature Update

Introduction

As we got another chance to improve our tool via Lab 03, I chose to add 2 new features. One was about:

  1. Make sure that the program exits with appropriate error codes and helpful error messages (stderr) in all cases. If there are no errors, exit with 0. Otherwise, exit with a non-zero exit code (e.g., 1).

  2. Allow using multiple models at once. The user should be able to specify multiple models, and output files should get generated for each model, allowing for comparisons.

How I accomplished the first issue

As the primary use of sys.exit() in Python is to terminate the execution of a code block with a specific exit code. Some of the common use cases include:

  • Error Handling
  • Testing Debugging

As I felt like this feature will benefit me in the future for testing and proper error handling.

What I did for my issue no one

api.py

image

In this code block, a system exit code is mentioned with 1 when there is no API Key provided.

image

In this code block, the system exits with 1 when the Gorq client fails to initialize, another one is when there is no source file found, and also when there is an error when the source file fails to read.

image

Next one is when there is an IO error; if it fails to write the generated content, it will raise a system error with 1, and finally an error when Gorq clients fail to generate a README.

DocBot.py

image

In this first screenshot, we can see that there is a system error with 0 when the version call is displaying successfully. The next two are of exit calls with 1, the first one when there is no file provided and the other one is about when there is no file in existence in the given path.

image

In this screenshot, we can see that there are three system exit calls with 1. The first case is when the README generation failed, the second one is the same case when there is no multi-file and the README generation fails. Finally, it is when writing the README to the file fails.

I believe this is very useful in the future for proper error handling and debugging information. Thus, this feature should be implemented.

What I did for my issue no 2

Changes in api.py file

Added an array to hold 3 Gorq AI models:
AVAILABLE_MODELS = ["llama3-8b-8192", "mixtral-8x7b-32768", "llava-v1.5-7b-4096-preview"]

image

Added a for loop to iterate through all models the user requests.

image

The output file is then generated as separate files with the model name.

Changes to DocBot.py file

Added a new argument in the CLI to handle the models:
parser.add_argument('--models', '-m', nargs='+', type=str, metavar='model', choices=AVAILABLE_MODELS, help=f"Specify models (default: all available models: {AVAILABLE_MODELS})")

image

In this screenshot, you can see how the models that are to be used are called and the output files are generated.

Conclusion

In this lab, i was able to successfully implement all the requested updates for my tool, Also this lab provided me with knowledge how to properly use git commands which is necessary for merging and changing branches. Also i believe that the two features i choose will benefit my tool in the future such as debugging and enabling users to try another model available with in Gorq AI.

AJO GEORGE 27-08-2024

Top comments (0)