Data Interpreter - Large JSON/tabular data being returned by a tool, should not be included in subsequent code prompts.
Bug description
I have a tool, that returns a large JSON/tabular data. I find that the DI takes all this data(50,000) chars and tries to add it to the prompt for subsequent analysis. (This is too expensive and slow) I could return a file name from the tool, where I dumped the JSON into, but this doesn't ALWAYS work, sometimes the DI tries to write all the data into the prompt, or worse still, truncates it.
What is a more efficient way to do this?
Bug solved method
Environment information
OpenAI gpt-4-1106-preview Python 3.10 Ubuntu 22.04
- LLM type and model name:
- System version:
- Python version:
- MetaGPT version or branch:
- packages version:
- installation method:
Screenshots or logs
@garylin2099 could you take a look at this?
Let me clarify the question, so DI is expected to generate a string for your downstream tasks, and you want the string to contain the file name instead of the file content, which is very long, is my understanding correct?
umm, let me explain: Tools could return various kinds of outputs, correct? In my case, my tool returns the rows of a table, as JSON(This could be huge). What happens, is that after the tool execution has completed, DI picks up the output from the logs/working memory and adds it all to the prompt, to continue to the next steps(which could be training a model on the data, etc) This makes the prompt enormous and time-consuming.
I was wondering if there was a way to do this more efficiently, one way I thought of was to dump the JSON in a file and return the file name for the DI to continue with. This doesn't always work, because the DI ignores the filename sometimes.
So another way I've tried, which has worked better, is to return a Dataframe object and tell DI in the prompt, "to store all outputs in dataframe df" - this helps in my case, since I'm calling a single tool. For multiple tool calls, or calls that are chained, I'm not sure how this will help.
So to conclude, the file name return is only one way to solve the problem.
This also leads me to question if the DI should mandate that all tools should return a particular type of output. (I remember working on OpenAI's assistant API, they expect a string to be returned and submitted as tool outputs in a submit_tool_outputs call).
These lines might hold a clue, to the issue: https://github.com/geekan/MetaGPT/blob/aa715fcace7577ec711ba675c51d0c22cfab84b3/metagpt/roles/di/data_interpreter.py#L186