Skip to content

Commit

Permalink
Add ESM and Deployment docs (langchain-ai#147)
Browse files Browse the repository at this point in the history
* Add first stab at ESM and Deployment docs

* Update after review
  • Loading branch information
nfcampos authored Feb 27, 2023
1 parent 1f7045a commit 21fb387
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Deployment

You've built your LangChain app and now you're looking to deploy it to production? You've come to the right place. This guide will walk you through the options you have for deploying your app, and the considerations you should make when doing so.

## Overview

LangChain is a library for building applications that use language models. It is not a web framework, and does not provide any built-in functionality for serving your app over the web. Instead, it provides a set of tools that you can integrate in your API or backend server.

There are a couple of high-level options for deploying your app:

- Deploying to a VM or container
- Persistent filesystem means you can save and load files from disk
- Always-running process means you can cache some things in memory
- You can support long-running requests, such as WebSockets
- Deploying to a serverless environment
- No persistent filesystem means you can load files from disk, but not save them for later
- Cold start means you can't cache things in memory and expect them to be cached between requests
- Function timeouts mean you can't support long-running requests, such as WebSockets

Some other considerations include:

- Do you deploy your backend and frontend together, or separately?
- Do you deploy your backend co-located with your database, or separately?

As you move your LangChains into production, we'd love to offer more comprehensive support. Please fill out [this form](https://forms.gle/57d8AmXBYp8PP8tZA) and we'll set up a dedicated support Slack channel.

## Deployment Options

See below for a list of deployment options for your LangChain app. If you don't see your preferred option, please get in touch and we can add it to this list.

### Deploying to Fly.io

[Fly.io](https://fly.io) is a platform for deploying apps to the cloud. It's a great option for deploying your app to a container environment.

See [our Fly.io template](https://github.com/hwchase17/langchain-template-node-fly) for an example of how to deploy your app to Fly.io.
28 changes: 28 additions & 0 deletions docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ If you are running this on Node.js 16, either:
- run your application with `NODE_OPTIONS='--experimental-fetch' node ...`, or
- install `node-fetch` and follow the instructions [here](https://github.com/node-fetch/node-fetch#providing-global-access)

## Loading the library

We support LangChain on Node.js 16, 18, and 19.

### ESM in Node.js

LangChain is an ESM library currently targeting Node.js environments. To use it, you will need to use the `import` syntax, inside a project with `type: module` in its `package.json`.

```typescript
import { OpenAI } from "langchain";
```

### CommonJS in Node.js

If your project is using CommonJS, you can use LangChain only with the dynamic `import()` syntax.

```typescript
const { OpenAI } = await import("langchain");
```

### Other environments

LangChain currently supports only Node.js-based environments. This includes Vercel Serverless functions (but not Edge functions), as well as other serverless environments, like AWS Lambda and Google Cloud Functions.

We currently do not support running LangChain in the browser. We are listening to the community on additional environments that we should support. Please open an issue if you would like to see support for a specific environment.

Please see [Deployment](./deployment.md) for more information on deploying LangChain applications.

## Picking up a LLM

Using LangChain will usually require integrations with one or more model providers, data stores, apis, etc.
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = {
},
],
},
"deployment",
{
type: "category",
label: "Ecosystem",
Expand Down

0 comments on commit 21fb387

Please sign in to comment.