langchain
langchain copied to clipboard
Update PAL to allow passing local and global context to PythonREPL
Passing additional variables to the python environment can be useful for example if you want to generate code to analyze a dataset.
I also added a tracker for the executed code - code_history
.
I wanted to have code history for debugging purposes mostly but also because I was thinking it might be useful for generating some kind of log down the line. But yeah now that I look at it, might make more sense to just return code
in the Dict
returned by the chain call.
Actually, looks like the current behavior in the base Chain
is to assume a single output key, so returning both code and result wouldn't work currently. What is the logic around assuming a single output key?
Actually, looks like the current behavior in the base
Chain
is to assume a single output key, so returning both code and result wouldn't work currently. What is the logic around assuming a single output key?
it can output multiple things! im actually pretty happy to help with that - my question would be: do you want to specify return_code
during run time (eg in chain.run() or chain()) or during init (eg you would do chain = PALChain(llm, return_code=True)?
oh ok cool. I overloaded the run method to return a tuple and then got complaints from the memory buffer, so figured the single key assumption might be important.
I'd say that return_code=True in .run() would be my preference. Thanks for looking into this! This library is awesome.
Removed the code history tracking for now if you wanted to go ahead and merge the addition of globals and locals.