GithubHelp home page GithubHelp logo

langchain's Introduction

langchain

LangChain gives you the building blocks to interface with any language model.

Repo Guide

  • (script-chain.py)
  • (script-retrieval_chain.py)
    • A retriever can be backed by anything, DB, data store, internet, or a vector store
  • (script-conversational_retrieval_chain.py)
    • chains above answer only one history-independent question
    • this can handle follow-up questions as well

Usages

LLMs and Prompts

This includes prompt management, prompt optimization, a generic interface for all LLMs, and common utilities for working with LLMs.

Chains:

Chains go beyond a single LLM call and involve sequences of calls (whether to an LLM or a different utility). LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.

Data Augmented Generation:

Data Augmented Generation involves specific types of chains that first interact with an external data source to fetch data for use in the generation step. Examples include summarization of long pieces of text and question/answering over specific data sources.

Agents:

Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end-to-end agents.

Memory:

Memory refers to persisting state between calls of a chain/agent. LangChain provides a standard interface for memory, a collection of memory implementations, and examples of chains/agents that use memory.

Evaluation:

[BETA] Generative models are notoriously hard to evaluate with traditional metrics. One new way of evaluating them is using language models themselves to do the evaluation. LangChain provides some prompts/chains for assisting in this.

Abstractions

Retrieval-Augmented Generation

  1. Retrieval: Retriever retrieves the important context only, to be passed to the LLM, which was not included in the training data.
  2. Prompt
  3. Chat Model

Agents

  1. Prompt: The inputs to language models are often called prompts
    1. Prompts generate structured messages from user input. They are casted into Messages for ChatModels and str for LanguageModels. PromptValue is the interface-like common class.
    2. User input string to these final structured input to models are handled by PromptTemplates.
    3. Types:
      1. MessagePromptTemplate: Consists of role and PromptTemplate. Could be: HumanMessagePromptTemplate, AIMessagePromptTemplate, or SystemMessagePromptTemplate, depending on the role.
      2. ChatPromptTemplate: Consists of list of PromptTemplates depending on variety of roles. Think of it as giving the history of conversation, i.e. list of messages by AI, User, System, or other roles.
  2. Model
    1. Types: LLMs and ChatModels (built upon LLMs and tuned for conversation)
    2. ChatModels take input as a Message: attrs: role and content; different message classes are present in langchain for different roles.
      1. content is either a string or list of dictionaries (for multi-modal input). The message can be classified into HumanMessage or AIMessage
      2. SystemMessage tells model how to behave.
      3. FunctionMessage represents the output of a function call
      4. ToolMessage represents the output of a tool call
  3. Output Parser: Formats AIMessage into human-readable strings
  4. Tools

Storage and Indexing

  1. Document Loader: WebBaseLoader for internet
  2. Text Splitter
  3. Embeddings: OpenAIEmbeddings
  4. Vector Store: Data is embedded into this store for indexing

Extraction

  1. Document Loader
  2. Prompt
  3. Model
  4. Output Parser

langchain's People

Contributors

vedant11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.