Code Monkey home page Code Monkey logo

langchain_dart's Introduction

πŸ¦œοΈπŸ”— LangChain.dart

tests docs langchain MIT

Build powerful LLM-based Dart/Flutter applications.

What is LangChain.dart?

Check out the announcement post: Introducing LangChain.dart πŸ¦œοΈπŸ”—

LangChain.dart is a Dart port of the popular LangChain Python framework created by Harrison Chase.

LangChain provides a set of ready-to-use components for working with language models and the concept of chains, which allows to "chain" components together to formulate more advanced use cases around LLMs.

The components can be grouped into a few core modules:

LangChain.dart

  • πŸ“ƒ Model I/O: streamlines the interaction between the model inputs (prompt templates), the Language Model (abstracting different providers), and the model output (output parsers).
  • πŸ“š Retrieval: assists in loading user data (document loaders), modifying it (document transformers and embedding models), storing (vector stores), and retrieving when needed (retrievers).
  • πŸ”— Chains: a way to compose multiple components or other chains into a single pipeline.
  • 🧠 Memory: equips chains or agents with both short-term and long-term memory capabilities, facilitating recall of prior interactions with the user.
  • πŸ€– Agents: "Bots" that harness LLMs to perform tasks. They serve as the link between LLM and the tools (web search, calculators, database lookup, etc.). They determine what has to be accomplished and the tools that are more suitable for the specific task.

Motivation

Large Language Models (LLMs) have revolutionized Natural Language Processing (NLP), serving as essential components in a wide range of applications, such as question-answering, summarization, translation, and text generation.

The adoption of LLMs is creating a new tech stack in its wake. However, emerging libraries and tools are predominantly being developed for the Python and JavaScript ecosystems. As a result, the number of applications leveraging LLMs in these ecosystems has grown exponentially.

In contrast, the Dart / Flutter ecosystem has not experienced similar growth, which can likely be attributed to the scarcity of Dart and Flutter libraries that streamline the complexities associated with working with LLMs.

LangChain.dart aims to fill this gap by abstracting the intricacies of working with LLMs in Dart and Flutter, enabling developers to harness their combined potential effectively.

Packages

LangChain.dart has a modular design where the core langchain package provides the LangChain API and each integration with a model provider, database, etc. is provided by a separate package.

Package Version Description
langchain langchain Core LangChain API (base components abstraction, logic for chaining them (LCEL), etc.)
langchain_openai langchain_openai OpenAI integration (GPT-3.5, GPT-4, Embeddings, Functions, Vision, DALLΒ·E 3, etc.)
langchain_google langchain_google Google integration (GoogleAI, VertexAI, Gemini, PaLM 2, Embeddings, Vector Search, etc.)
langchain_ollama langchain_ollama Ollama integration (Llama 2, Code Llama, Mistral, Vicuna, Orca, Starling, etc.)
langchain_mistralai langchain_mistralai Mistral AI integration (Mistral-7B, Mixtral 8x7B, embeddings, etc.).
langchain_pinecone langchain_pinecone Pinecone vector database integration
langchain_chroma langchain_chroma Chroma vector database integration

Functionality provided by each package:

Package LLMs Chat models Embeddings Vector stores Chains Agents Tools
langchain β˜… β˜… β˜… β˜… β˜… β˜… β˜…
langchain_openai βœ” βœ” βœ” βœ” βœ” βœ”
langchain_google βœ” βœ” βœ” βœ”
langchain_ollama βœ” βœ” βœ”
langchain_mistralai βœ” βœ”
langchain_pinecone βœ”
langchain_chroma βœ”

The following packages are maintained (and used internally) by LangChain.dart, although they can also be used independently:

Package Version Description
chromadb chromadb Chroma DB API client
googleai_dart googleai_dart Google AI for Developers (Gemini API) client
mistralai_dart mistralai_dart Mistral AI API client
ollama_dart ollama_dart Ollama API client
openai_dart openai_dart OpenAI API client
vertex_ai vertex_ai GCP Vertex AI API client

Getting started

To start using LangChain.dart, add langchain as a dependency to your pubspec.yaml file. Also, include the dependencies for the specific integrations you want to use (e.g.langchain_openai):

dependencies:
  langchain: {version}
  langchain_openai: {version}

The most basic building block of LangChain.dart is calling an LLM on some prompt:

final llm = OpenAI(apiKey: openaiApiKey);
final prompt = PromptValue.string('Hello world!');
final result = await openai.invoke(prompt);
// Hello everyone! I'm new here and excited to be part of this community.

But you can build complex pipelines by chaining together multiple components.

For example, the following pipeline does the following:

  1. Asks the model where the given person is from.
  2. Uses the answer to ask the model to return the country where the city is located in the given language.
final promptTemplate1 = ChatPromptTemplate.fromTemplate(
  'What is the city {person} is from? Only respond with the name of the city.',
);
final promptTemplate2 = ChatPromptTemplate.fromTemplate(
  'What country is the city {city} in? Respond in {language}.',
);

final model = ChatOpenAI(apiKey: openaiApiKey);
const stringOutputParser = StringOutputParser();

final chain = Runnable.fromMap({
  'city': promptTemplate1 | model | stringOutputParser,
  'language': Runnable.getItemFromMap('language'),
}) |
promptTemplate2 |
model |
stringOutputParser;

final res = await chain.invoke({
'person': 'Rafael Nadal',
'language': 'Spanish',
});
print(res);
// La ciudad de Manacor se encuentra en EspaΓ±a.

This is just a very simple example of a pipeline using LangChain Expression Language (LCEL). You can construct far more intricate pipelines by connecting various components, such as a Retrieval-Augmented Generation (RAG) pipeline that would accept a user query, retrieve relevant documents from a vector store, format them using templates, prompt the model, and parse the output in a specific manner using an output parser.

Documentation

Support

Having trouble? Get help in the official LangChain.dart Discord.

Contribute

πŸ“’ Call for Collaborators πŸ“’
We are looking for collaborators to join the core group of maintainers.

New contributors welcome! Check out our Contributors Guide for help getting started.

Join us on Discord to meet other maintainers. We'll help you get your first contribution in no time!

Related projects

Sponsors

License

LangChain.dart is licensed under the MIT License.

langchain_dart's People

Contributors

davidmigloz avatar dependabot[bot] avatar mauricepoirrier avatar faithoflifedev avatar mthongvanh avatar walsha2 avatar f3ath avatar derek-x-wang avatar itp2023 avatar mirkancal avatar dileep9490 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.