Building a RCI Chain for Agents with LangChain Expression Language

  Рет қаралды 9,281

Sam Witteveen

Sam Witteveen

Күн бұрын

Colab: drp.li/OJuLY
RCI Paper: arxiv.org/abs/2303.17491
LCEL Blog post: blog.langchain.dev/langchain-...
My Links:
Twitter - / sam_witteveen
Linkedin - / samwitteveen
Github:
github.com/samwit/langchain-t... (updated)
github.com/samwit/llm-tutorials
Timestamps
00:00 Intro
01:11 Paper: Language Models Can Solve Computer Task
01:18 Paper: Reflexion: Language Agents with Verbal Reinforcement Learning
01:35 RCI Recursive Criticism and Improvements
02:44 Three Prompts
04:33 Three Prompts Diagram
05:10 Code Time
05:42 Multi Chains
09:02 RCI with LCEL
13:26 Combined Chain

Пікірлер: 32
10 ай бұрын
Excellent work Sam. Thank you very much!
@mi7
@mi7 10 ай бұрын
oh thanks mate as usual ur content is the best , Cheers from Chile :)
@snakesolid6080
@snakesolid6080 10 ай бұрын
Summary. ---------------------------------------------- Evaluating yourself is critical when building autonomous agents around large language models. In this video, I'd like to discuss the concept of RCI chains and how to build them using the new LangChain expression language. Autonomous agents often have problems without testing, so there is a need to find a way to test them. And surprisingly, one of the best ways to test them is to let the language model check its output itself. We are going to introduce the concept of RCI chains. This concept comes from a paper called Recursive Critique and Improvement of Language Models for Computer Tasks.RCI stands for Recursive Critique and Improvement. They show a simple idea: we can start with a zero-initial cue, ask questions or pose problems to the language model, and then improve it by critiquing and inspecting the output. Finally, we use the results of the critique and improvement as new prompts and move on to the next round of critique and improvement. This is the basic idea of the RCI chain, which allows for multiple critiques and improvements recursively. In this video, we will focus on three prompts and three chains. The first prompt is the initial question, the second prompt is the assessment of the initial question, and the third prompt is the improvement prompt. We will build the RCI chain by combining these three chains. We first define two chains, an initial problem chain and an evaluation chain. Then, we define an RCI chain that takes the output of the initial problem chain as the input to the assessment chain and the output of the assessment chain as the input to the improvement chain. In this way, we combined the three chains to form the complete RCI chain. In the code, we use the LangChain expression language to define and run these chains. We do this by connecting different hints and models together to form a chain structure, and by running each link in the chain to enable recursive critique and improvement. Finally, we run the entire RCI chain and get the final output. In this example, we use a chat model, give it a problem, and keep improving the output through a process of critique and improvement. In the end, we get an output that fulfills the requirements. To summarize, RCI Chaining is a method for improving the output of a language model using recursive criticism and improvement. It can be applied to a variety of tasks such as question and answer, writing, etc. By building and running RCI chains, we can continually improve the capabilities of language models and achieve more accurate and reliable results. We hope this article has helped you understand the concept and application of RCI chains. If you have any questions, please leave a comment below. Thanks for reading!
@rajivmehtapy
@rajivmehtapy 10 ай бұрын
Great content you have generated.
@siddharthvij9087
@siddharthvij9087 10 ай бұрын
This is useful..m stuck in similar issue ...will try this approach Thank you for sharing
@micbab-vg2mu
@micbab-vg2mu 10 ай бұрын
Great video - thank you
@aiexplainai2
@aiexplainai2 10 ай бұрын
very cool as always - I like LangChain take a step to simplify the process but this piping still seems to have quite a limitation and only works well with relatively simple chain
@fabianaltendorfer11
@fabianaltendorfer11 10 ай бұрын
Great video, as always! I'm curious how this would work with an external vector DB attached and/or with user feedback, like chain2 changes it's opinion based on the feedback of the user. This would be a very interesting use case imo.
@umeshtiwari9249
@umeshtiwari9249 10 ай бұрын
Gud video . Thanks. please make a playlist on this chain and cover some use cases as well. thanks again
@Market-MOJOE
@Market-MOJOE 10 ай бұрын
Thats funny Months back I put together a fewbot comparing and contrasting itself to another similar functional one. One tnhat comes to mind was Phind v perplexity then used gpt4 as a objective 3rd sat but thought I was spinning my wheels.never got into the Os models but prety sure I have (bard v claud)+gpt few others but interestingm thanks 4 content
@klammer75
@klammer75 10 ай бұрын
Can’t wait for the series and keep,up the great work!🥳😎🦾
@AdrienSales
@AdrienSales 10 ай бұрын
Just in time while I was asking myself about best practices around using multiple chains... inclduing the DOs and the DONTs ;-p
@ShlomiSchwartz
@ShlomiSchwartz 10 ай бұрын
Great video! Quick question: Can we direct the chain to use an alternate chain based on the critique_chain outcome? Like A->B->C to A->B->D? Thanks! 😊
@hiranga
@hiranga 10 ай бұрын
awesome! @Sam Witteveen - great video👌🏾👌🏾👌🏾👌🏾👌🏾👌🏾👌🏾👌🏾Have you got OpenAI Function Agent streaming working in any of your experiments? Trying to set this up for a Fastapi POST request but finding streaming quite a challenge - was wondering if you may have already crossed that hurdle before??
@blueman333
@blueman333 10 ай бұрын
Super neat!! I have one question. Can we attach conditional routing using the language expression? I am asking for something like chain1 | Condition(if_true, chain_true, chain_false) | chain_4
@samwitteveenai
@samwitteveenai 10 ай бұрын
This a good question. Don't think it will work in the style you wrote above (but I could be wrong). You can do it with router chains and also probably with nested functions. I will look at make a video about this.
@user-mn8hz1vb5p
@user-mn8hz1vb5p 8 ай бұрын
Thank you very much for the LangChain resources. Trying the same approach with LLaMA 2 and doesn't seems working with the Lang chain agents and tools. Curious how will langchain components like Agents, Output parsers etc. work with LLaMA 2
@MariuszWoloszyn
@MariuszWoloszyn 10 ай бұрын
Unfortunately there's a subtle bug in your code. When you create final chain (chain3) it uses chain1 as well as critque_chain which also uses the same chain1. The caveat is that the chain1 is called twice and returns different answers each time. I realized that when I created initial model like that: `model = ChatOpenAI(model_name="gpt-4", temperature=0, streaming=True, callbacks=[StreamingStdOutCallbackHandler()])` and used the streamig callback as debug rather than langchain.debug = True. There's additional issue with the original code as ChatOpenAI does not have model argument but rather mode_name but since it accepts all **kwargs it's easy to miss that, especially in the colab without proper linter.
@samwitteveenai
@samwitteveenai 10 ай бұрын
Thanks for pointing this out. I thought this might be the case after I published and have been traveling since. I will check it out and update the Colab in the next day or two.
@fkltan
@fkltan 10 ай бұрын
awesome video as always. btw, can u do a tutorial video on langchain but using chromdb as a server to store embeddings (with chromadb running as a server in a docker container)? there's almost nothing available online about it apart from that single page on the langchain website. almost all code examples refer only to the basic saving to disk/persistent use case. i've been trying to get that setup working with a different embedding function (Instructor) but having a lot of issues getting it to work.
@jawadmansoor6064
@jawadmansoor6064 10 ай бұрын
how about using a small model like 7b llama? or even pythia small models?
@anthanh1921
@anthanh1921 10 ай бұрын
Thinking this could be improve if we find a way to pass back the chain3 output to the evaluator and iterate until it the evaluator approve to make it a true RCI agent, else it's still a linear pipeline that enhance the initial output 1 time.
@cbusse7842
@cbusse7842 10 ай бұрын
wouldnt it be better to combine MPT and falcon models or llama2 than open AI to prove the value of the RCI chain compared to GPT4?
@alvintsoiwc1908
@alvintsoiwc1908 9 ай бұрын
instead of openai, can build a rci example with llama 2?
@aliattieh9216
@aliattieh9216 10 ай бұрын
Hey sam love your videos. I was wondering if there is a way to create a csv_agent using initialize_agent function and passing tools to it. The reason is that i need to pass multiple tools to the agent other than csv. is this possible?
@samwitteveenai
@samwitteveenai 10 ай бұрын
I think you could do it as having the csv retrieval be a tool. I have done something similar for the Vectorstore retrieval as a tool in the past, but not directly for CSV etc.
@dhrumil5977
@dhrumil5977 10 ай бұрын
Can you make a video on how to us llama2 with petals and langchain
@attilavass6935
@attilavass6935 10 ай бұрын
Has anyone tried this concept for code generation / fix / improvement? When it generates eg. Python code, runs it in a sandbox env, uses error / warning / log messages as feedback / evaluation for the LLM, etc.
@samwitteveenai
@samwitteveenai 10 ай бұрын
yeah kind of, this is what the GPT-4 code interpreter does a lot
@winxalex1
@winxalex1 10 ай бұрын
You break the idea of the pipes by executing chain1 and then pass the result. Simple you could done DictionaryOutParser/JsonOutParser or custom method in chain or so on...
@rafaeldelrey9239
@rafaeldelrey9239 10 ай бұрын
This LCEL doesn't seem too straightforward or intuitive at all.
@JOHNSMITH-ve3rq
@JOHNSMITH-ve3rq 10 ай бұрын
Pretty good but also very verbose and amateur.
How to Run LLaMA-2-70B on the Together AI
13:17
Sam Witteveen
Рет қаралды 12 М.
Understanding ReACT with LangChain
21:10
Sam Witteveen
Рет қаралды 43 М.
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 57 МЛН
бесит старшая сестра!? #роблокс #анимация #мем
00:58
КРУТОЙ ПАПА на
Рет қаралды 2,9 МЛН
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 64 МЛН
LangGraph 101: it's better than LangChain
32:26
James Briggs
Рет қаралды 51 М.
Using LangChain Output Parsers to get what you want out of LLMs
23:04
✅ Easiest Way to Build AI Agents With RAG & CrewAI Locally
8:07
Analytics Camp
Рет қаралды 1,8 М.
Building Custom Tools and Agents with LangChain (gpt-3.5-turbo)
16:48
LangGraph Crash Course with code examples
39:01
Sam Witteveen
Рет қаралды 63 М.
Information Extraction with LangChain & Kor
17:05
Sam Witteveen
Рет қаралды 20 М.
LangChain Expression Language (LCEL) Explained!
25:38
James Briggs
Рет қаралды 16 М.
SmartGPT: Make ChatGPT Smarter
12:57
Prompt Engineering
Рет қаралды 10 М.
Iphone or nokia
0:15
rishton vines😇
Рет қаралды 1,9 МЛН
Main filter..
0:15
CikoYt
Рет қаралды 11 МЛН
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 27 МЛН
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1,1 МЛН