3 ms·
I wrote my own simplest-possible implementation of ReAct in Python here, which I think helps demonstrate quite how much you can get done with this pattern usin
by simonw 4y ago
I wrote my own simplest-possible implementation of ReAct in Python here, which I think helps demonstrate quite how much you can get done with this pattern using only a very small amount of code:
https://til.simonwillison.net/llms/python-react-pattern https://til.simonwillison.net/llms/python-react-pattern
- kfarr 4y agoLove this example! No offense to OP research paper but I appreciate the simplicity of your Python version instead PS also thanks for this genuine LOL moment from the intro: > A popular nightmare scenario for AI is giving it access to tools, so it can make API calls and execute its own code and generally break free of the constraints of its initial environment. > Let's do that now!
- doctor_eval 4y agoThat’s nuts. Thanks for sharing.
- nighthawk454 4y agoCheers, Simon - been seeing your comments around and enjoying your blog and coverage of this stuff. Is that prompt in your TIL really all it takes to inform it of these 3 actions? That's pretty impressive. I wonder how many actions it can scale to? I kind of expected some kind of classifier layer to predict if an action was necessary!
- simonw 4y agoI've not tested its limits yet. The thing to consider is prompt length - depending on the model you get around 4,000 tokens, and the prompt itself is already 264 according to https://platform.openai.com/tokenizer https://platform.openai.com/tokenizer - you need a bunch of space left for providing the output of your various actions, so tokens get used up pretty quickly. The ReAct paper talks about fine-tuning to teach a model actions. I'd be interested to see an experiment that fine-tunes the LLaMA model to teach it actions - I have a hunch that might work really well, and save a bunch of token space in the actual execution phase.
- bestcoder69 4y agoHow reliable has it been for you? After struggling with langchain & GPT4 I was planning to try your lib next before maybe writing my own - I plan to make a super generalized version so that my bot can code itself, so might have to pull out some tricks. (Before I got api access I got ChatGPT4 to do this - just not with a proper ReAct pattern - via a tampermonkey extension it wrote me…lol)
- simonw 4y agoI spent about 30 minutes writing the code and 15 minutes writing it up - I haven't spent much time at all testing it and making sure it's robust and reliable. I just wanted to illustrate the concept.
- dragonwriter 4y agoIt’s not particularly robust, but its so accessible that its easy to tweak and improve. The code seems fine, even if clearly not structured the way a “production” product would be. The prompt can definitely use tweaking to improve the ability of ChatGPT to make best use of the actions – particularly, I’ve found it needs a firmer reminder to use valid Python expressions or its tends to pass math-in-English – e.g., with thousands separators, for instance – or other syntactically invalid things to the ‘calculate’ action, but once you’ve got the code and the prompt you’ve done as a starting point, adding actions, tweaking the prompt, etc., is pretty straightforward.
- johntash 4y agoThanks for writing this up. I read through it the other day and it was a lot simpler to get through than digging through Langchain for the first time. I took your example and added a couple other "actions" like searching a searxng instance and returning the markdown version of a certain url. It's surprising how much more useful it can be when it has the ability to look stuff up on the internet.
- matthewfcarlson 4y agoCheers Simon! I really appreciated your article on how LLMs and LLaMA are having their Stable Diffusion moment. It was well thought through. I might take your python and expand it to try to make an actually intelligent home assistant that can answer more helpful questions.
- dragonwriter 4y agoThis is awesome – a very accessible and easily extensible implementation of the concept.