Top Related Projects
Integrate cutting-edge LLM technology quickly and easily into your apps
:mag: AI orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
LlamaIndex is a data framework for your LLM applications
Examples and guides for using the OpenAI API
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Quick Overview
LangChain Hub is a repository of resources for the LangChain library, which is used for developing applications powered by language models. It contains prompts, chains, and agents that can be easily integrated into LangChain projects, serving as a central location for sharing and discovering reusable components.
Pros
- Provides a wide variety of pre-built components for LangChain projects
- Facilitates community collaboration and sharing of resources
- Regularly updated with new contributions
- Simplifies the process of integrating advanced language model capabilities into applications
Cons
- Quality of community-contributed components may vary
- Requires familiarity with LangChain to fully utilize the resources
- Some components may become outdated as the main LangChain library evolves
- Limited documentation for individual components
Code Examples
Here are a few examples of how to use components from LangChain Hub:
- Loading a prompt template:
from langchain.prompts import load_prompt
prompt = load_prompt("hwchase17/human-bot-prompt")
- Using a pre-defined chain:
from langchain.chains import load_chain
chain = load_chain("hwchase17/summarize")
result = chain.run("Your long text to summarize goes here.")
- Implementing an agent:
from langchain.agents import load_agent
agent = load_agent("hwchase17/conversational-react-description")
agent.run("What's the weather like today?")
Getting Started
To start using LangChain Hub, follow these steps:
- Install LangChain:
pip install langchain
- Import and use components from LangChain Hub:
from langchain.prompts import load_prompt
from langchain.chains import load_chain
from langchain.agents import load_agent
# Load a prompt
prompt = load_prompt("hwchase17/human-bot-prompt")
# Load a chain
chain = load_chain("hwchase17/summarize")
# Load an agent
agent = load_agent("hwchase17/conversational-react-description")
# Use the components in your application
Remember to check the LangChain documentation for more detailed information on how to use these components effectively in your projects.
Competitor Comparisons
Integrate cutting-edge LLM technology quickly and easily into your apps
Pros of Semantic Kernel
- More comprehensive documentation and examples
- Stronger integration with Microsoft Azure services
- Active development and frequent updates
Cons of Semantic Kernel
- Less flexible and modular compared to LangChain Hub
- Steeper learning curve for developers new to Microsoft ecosystems
- Limited support for non-Microsoft language models and services
Code Comparison
LangChain Hub example:
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
tools = load_tools(["serpapi", "llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
Semantic Kernel example:
using Microsoft.SemanticKernel;
IKernel kernel = KernelBuilder.Create();
kernel.Config.AddOpenAITextCompletionService("davinci", "your-api-key");
var result = await kernel.RunAsync("Tell me a joke", "FunSkill");
:mag: AI orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
Pros of Haystack
- More comprehensive end-to-end NLP framework with broader functionality
- Better suited for production-ready applications with scalability features
- Offers more advanced retrieval and ranking capabilities
Cons of Haystack
- Steeper learning curve due to its extensive feature set
- Less flexibility for custom integrations compared to LangChain Hub
Code Comparison
Haystack:
from haystack import Pipeline
from haystack.nodes import TextConverter, PreProcessor, Retriever, Reader
pipeline = Pipeline()
pipeline.add_node(component=TextConverter(), name="TextConverter", inputs=["File"])
pipeline.add_node(component=PreProcessor(), name="PreProcessor", inputs=["TextConverter"])
pipeline.add_node(component=Retriever(), name="Retriever", inputs=["PreProcessor"])
pipeline.add_node(component=Reader(), name="Reader", inputs=["Retriever"])
LangChain Hub:
from langchain import PromptTemplate, LLMChain
from langchain.llms import OpenAI
template = """Question: {question}
Answer: Let's approach this step-by-step:"""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=OpenAI())
LlamaIndex is a data framework for your LLM applications
Pros of LlamaIndex
- More focused on efficient indexing and retrieval of large language models
- Provides advanced features for document chunking and embedding
- Offers a wider range of index types (e.g., vector, list, tree) for different use cases
Cons of LlamaIndex
- Less integration with external tools and services compared to LangChain Hub
- Steeper learning curve for beginners due to more specialized functionality
- Smaller community and fewer contributed resources
Code Comparison
LlamaIndex:
from llama_index import GPTSimpleVectorIndex, Document
documents = [Document('content1'), Document('content2')]
index = GPTSimpleVectorIndex.from_documents(documents)
response = index.query("What is the content about?")
LangChain Hub:
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
qa_chain = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=retriever)
response = qa_chain.run("What is the content about?")
Both repositories aim to enhance interactions with large language models, but LlamaIndex focuses more on efficient indexing and retrieval, while LangChain Hub provides a broader set of tools for building language model applications. LlamaIndex offers more specialized indexing features, while LangChain Hub excels in integrations and ease of use for beginners.
Examples and guides for using the OpenAI API
Pros of OpenAI Cookbook
- Focuses specifically on OpenAI's API and models, providing in-depth examples and best practices
- Regularly updated with new features and capabilities of OpenAI's offerings
- Includes a wide range of practical use cases and applications
Cons of OpenAI Cookbook
- Limited to OpenAI's ecosystem, not covering other language models or AI frameworks
- May require more technical expertise to implement examples compared to LangChain Hub
Code Comparison
OpenAI Cookbook example:
import openai
response = openai.Completion.create(
engine="text-davinci-002",
prompt="Translate the following English text to French: '{}'",
max_tokens=60
)
LangChain Hub example:
from langchain import PromptTemplate, LLMChain
from langchain.llms import OpenAI
template = "Translate the following English text to French: {text}"
prompt = PromptTemplate(template=template, input_variables=["text"])
llm_chain = LLMChain(prompt=prompt, llm=OpenAI())
The OpenAI Cookbook example directly uses the OpenAI API, while LangChain Hub provides a higher-level abstraction for working with language models, including OpenAI's.
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Pros of Transformers
- Extensive library of pre-trained models for various NLP tasks
- Well-documented and actively maintained by a large community
- Seamless integration with PyTorch and TensorFlow
Cons of Transformers
- Steeper learning curve for beginners
- Focused primarily on NLP tasks, less versatile for other AI applications
Code Comparison
Transformers:
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
result = classifier("I love this product!")[0]
print(f"Label: {result['label']}, Score: {result['score']:.4f}")
LangChain Hub:
from langchain import PromptTemplate, LLMChain
from langchain.llms import OpenAI
template = "Classify the sentiment: {text}"
prompt = PromptTemplate(template=template, input_variables=["text"])
llm_chain = LLMChain(prompt=prompt, llm=OpenAI())
result = llm_chain.run("I love this product!")
print(result)
Key Differences
- Transformers focuses on providing pre-trained models and tools for NLP tasks
- LangChain Hub emphasizes building applications with language models and chains
- Transformers has a more extensive collection of models, while LangChain Hub offers more flexibility in combining different AI components
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
LangChainHub
ð This repo is getting replaced by our hosted LangChain Hub Product! Visit it at https://smith.langchain.com/hub ð |
---|
Introduction
Taking inspiration from Hugging Face Hub, LangChainHub is collection of all artifacts useful for working with LangChain primitives such as prompts, chains and agents. The goal of this repository is to be a central resource for sharing and discovering high quality prompts, chains and agents that combine together to form complex LLM applications.
We are starting off the hub with a collection of prompts, and we look forward to the LangChain community adding to this collection. We hope to expand to chains and agents shortly.
Contributing
Since we are using GitHub to organize this Hub, adding artifacts can best be done in one of three ways:
- Create a fork and then open a PR against the repo.
- Create an issue on the repo with details of the artifact you would like to add.
- Add an artifact with the appropriate Google form:
Each of the different types of artifacts (listed below) will have different instructions on how to upload them. Please refer to the appropriate documentation to do so.
ð Prompts
At a high level, prompts are organized by use case inside the prompts
directory.
To load a prompt in LangChain, you should use the following code snippet:
from langchain.prompts import load_prompt
prompt = load_prompt('lc://prompts/path/to/file.json')
In addition to prompt files themselves, each sub-directory also contains a README explaining how best to use that prompt in the appropriate LangChain chain.
For more detailed information on how prompts are organized in the Hub, and how best to upload one, please see the documentation here.
ð Chains
At a high level, chains are organized by use case inside the chains
directory.
To load a chain in LangChain, you should use the following code snippet:
from langchain.chains import load_chain
chain = load_chain('lc://chains/path/to/file.json')
In addition to chain files themselves, each sub-directory also contains a README explaining what that chain contains.
For more detailed information on how chains are organized in the Hub, and how best to upload one, please see the documentation here.
ð¤ Agents
At a high level, agents are organized by use case inside the agents
directory.
To load an agent in LangChain, you should use the following code snippet:
from langchain.agents import initialize_agent
llm = ...
tools = ...
agent = initialize_agent(tools, llm, agent="lc://agents/self-ask-with-search/agent.json")
In addition to agent files themselves, each sub-directory also contains a README explaining what that agent contains.
For more detailed information on how agents are organized in the Hub, and how best to upload one, please see the documentation here.
ð· Agent Executors
Coming soon!
Top Related Projects
Integrate cutting-edge LLM technology quickly and easily into your apps
:mag: AI orchestration framework to build customizable, production-ready LLM applications. Connect components (models, vector DBs, file converters) to pipelines or agents that can interact with your data. With advanced retrieval methods, it's best suited for building RAG, question answering, semantic search or conversational agent chatbots.
LlamaIndex is a data framework for your LLM applications
Examples and guides for using the OpenAI API
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot