langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Update PAL to allow passing local and global context to PythonREPL

Open nickFurlotte opened this issue 2 years ago • 5 comments

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.

nickFurlotte avatar Jan 28 '23 04:01 nickFurlotte

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.

nickFurlotte avatar Jan 28 '23 17:01 nickFurlotte

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?

nickFurlotte avatar Jan 28 '23 21:01 nickFurlotte

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)?

hwchase17 avatar Jan 28 '23 21:01 hwchase17

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.

nickFurlotte avatar Jan 28 '23 21:01 nickFurlotte

Removed the code history tracking for now if you wanted to go ahead and merge the addition of globals and locals.

nickFurlotte avatar Jan 31 '23 02:01 nickFurlotte