Use custom code with Open AI API

Hi - I have a slightly complex need.

I would like to use a custom code snippet to build a question/ answer box.

The question can be inputted by the user.

When they input the question, I want it to be used, first, to build an index over a set of documents I’ve got stored on my machine (using gpt-index) and then, second, as a prompt to a gpt model.

I’ve got python code that does the last bit. But I’ve tried to use the custom code to do all the integration and am having some difficulty.

Grateful for any tips or structural reasons this wouldn’t work?