11 Oct 2023
Chains with LLMs
Chains are common parts of any large language model application. From summarization to comparison. This provides the extra ability of LLMs to improve its accuracy and fluency. This also allows to build agents on top, where it can connect to multiple modality (third party APIs or services).
Langchain Chains to Mix Models
Langchain is a very powerful tool to create chains. From simple RAG systems to full blown agents. In the following notebook, I’ve implemented the following workflow:
- Implement a RAG system that will retrieve and summarize the answer to the prompt. I want to identify the parameter that I will use to identify the better answer. I am using llama-2-7b chat as the LLM for the RAG system.
- Using the answers, these will be fed into another LLM chain that will implement the comparison. I am using mistral-7b as the model that implements the comparison.
- The output of step 2 will be used as the main answer that will be presented to the user.
The workflow above is using Langchain’s SimpleChain workflow. This allows to implement sequential chains. You will also notice that the chain are both using Custom Chains. Something worth noting is that these Custom Chains contain a lot of boilerplate in terms of parameters and properties.
Takeaways
- There is a router chain in langchain, where given a “prompt” it will decide which model will be used to answer the prompt.
- Mixture of Experts, I know see how mixture of experts can be done in the LLM space, where given N models with specific “identities” it can be used to improve the accuracy of the answer.
- Similar to mixture of experts and chains, multi-modal language models allow you to integrate to other endpoints, services, or APIs and generate agents that are fine-tuned for a specific set of tasks and thus reducing the “compute” resources needed.
Overall, I am still exploring the router setup and expanding my research with multi-modal language models.