Python code as knowledge file

Is it possible to provide python code to a customGPT through its knowledge file?
I’ve uploaded a python file as knowledge file, but the GPT always start by failing to execute functions from it, and reimplement similar code on its own:

It seems that the necessary helper functions aren’t directly accessible in my current environment. I will implement the required functions for our game manually. Let’s start the game! I will make the first move. ​​

How can I make it directly accessible to its environment?
Or is there any trick to make it load silently the code without mentioning it back to the user?

1 Like

Yes. I’ve stored python code in a .docx, manually uploaded that as a knowledge file, and used the ‘Instructions’ section of the customGPT setup to tell it to run that python code. The GPT runs the stored code rather than writing its own code. Alternatively you can store your prescribed python code in the GTP’s ‘Instructions’ section itself to the same effect. For example:

### INSTRUCTIONS:
Step 1. …… 

Step 2. Run the code contained in the "### CODE BLOCK 1" section. 
….
Step 4. Run the code exactly as shown in the "### CODE BLOCK 2" section. 

### CODE BLOCK 1
…..
### END OF CODE BLOCK 1


### CODE BLOCK 2
…..
### END OF CODE BLOCK 2

1 Like

Yes its possible to run python files instruct GPT to import the functions like this

Using your code interpreter import xyz.py using the exact code below.
import sys
sys.path.append(‘/mnt/data’)
from xyz import xyz

1 Like

Would I be able to use this to get elapsed time since some event? For example, when a user starts a new chat, give my GPT instructions to get data from my API and record the current time (seconds since the epoch using time()), then the next time it needs to respond, get the current time and see if elapsed time is greater than 3600 seconds, if so, call my API for a data refresh.

I can do this in my API, but it requires an extra call.