Example Using LangChain to Call LLM Model

LangChain provides an uniform interface to communicate with lots of different LLM models. Here is an example of how to use LangChain to call an LLM model within a Palico Agent.

import { Chat } from "@palico-ai/app";
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage } from "@langchain/core/messages";

const handler: Chat = async ({ userMessage }) => {
  const model = new ChatOpenAI({
    model: "gpt-4o-mini",
    temperature: 0,
  });
  const response = await model.invoke([
    new HumanMessage({ content: userMessage }),
  ]);
  return {
    message: response.content,
  };
};

Using LangChain with Palico Effectively

LangChain provides lots of utility libraries to help you the actual implementation of your LLM Application whereas Palico provides the overall architecture. You can build powerful LLM application by combining the two. For example, you can build the core of your application with LangChain, then use Palico to preview changes, run experiments, add logs and tracing, and publish your application behind a REST API

Common Use-Cases with LangChain

Langchain provides lots of component libraries to help build implement your LLM Application. Here are some common use-cases.

Index and Retrieve Documents for RAG Applications

When building a RAG Application, you need to first index your documents to a Vector Database, then retrieve it from that database. LangChain provides variety of tools to communicate with Vector Databases like Pinecone, PGVector, and more. Learn more from the LangChain Documentation.

Prompt Templates

The primary input to an LLM model is the prompt, and as such, we this prompt can become complex. LangChain provides a tool to build these complex prompts using templates. Learn more from the LangChain Documentation.

Communicating with LLM Models

LangChain provides a unified interface to communicate with different LLM models. You can use LangChain to call models from OpenAI, Claude, and more. Learn more from the LangChain Documentation.