Validity check python code

Currently I am writing a chatbot, using chatgpt3.5 API. I would like to the chatbot to assist me writing code with my custom python library. I have embedded my documentation and created some templates. The results are very promising.

However, sometimes chatgpt forgets imports or imports methods of functions which not exist. I was thinking about writing a manual check, using function calling and searching trough all my library if the function/method exists. But I was wondering if anyone already approached this problem. It seems like a common recurring problem.

The code interpreter would not work in this case, because the library I am using is not installed there.

Any advice is much appreciated.

1 Like

There are two ways in which you can go about it.

You can have a static list of functions in your libraries with which you can match your import statement against to see whether that function exists or not.

Another way would be to write a script that based on import statement can check whether the module exists or not and then check whether the function called exists in the module or not.