Skip to content

Commit

Permalink
Merge pull request langchain-ai#14 from langchain-ai/erick/hub-docs
Browse files Browse the repository at this point in the history
Hub Docs
  • Loading branch information
hinthornw authored Aug 30, 2023
2 parents 8660eec + 2aaa6c4 commit 5a2ece9
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 1 deletion.
57 changes: 57 additions & 0 deletions docs/hub/dev-setup-py.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
sidebar_label: Python Setup
sidebar_position: 2
---
# Python Setup

This guide will continue from the hub quickstart, using the Python SDK to interact with the hub instead of the Playground UI.

This guide assumes you've gone through the Hub [Quick Start](./quickstart) including login-required steps.

If you don't yet have an account, you'll only be able to pull public objects in steps 1 and 3.

## 1. Install/upgrade packages

**Note:** You likely need to upgrade even if they're already installed!

```bash
pip install --upgrade langchain langchainhub
```

## 2. Configuring environment variables

Get an API key for your **Personal** organization if you have not yet. The hub will not work with your non-personal organization's api key!

```bash
export LANGCHAIN_HUB_API_KEY="ls_..."
```

## 3. Pull an object from the hub and use it

```python
from langchain import hub

# pull a chat prompt
prompt = hub.pull("efriis/my-first-prompt")

# create a model to use it with
from langchain.chat_models import ChatOpenAI
model = ChatOpenAI()

# use it in a runnable
runnable = prompt | model
runnable.invoke({
"profession": "biologist",
"question": "What is special about parrots?",
})
```

## 4. Push it back to your personal organization as a private prompt

For this step, you'll need the `handle` for your account!

```python
from langchain import hub

hub.push("<handle>/my-first-prompt", prompt)
```
60 changes: 60 additions & 0 deletions docs/hub/dev-setup-ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
sidebar_label: TypeScript Setup
sidebar_position: 3
---
# TypeScript Setup

This guide will continue from the hub quickstart, using the TypeScript SDK to interact with the hub instead of the Playground UI.

This guide assumes you've gone through the Hub [Quick Start](./quickstart) including login-required steps.

If you don't yet have an account, you'll only be able to pull public objects in steps 1 and 3.

## 1. Install/upgrade packages

**Note:** You likely need to upgrade even if they're already installed!

```bash
yarn add langchain langchainhub
```

## 2. Configuring environment variables

Get an API key for your **personal** organization if you have not yet. The hub will not work with your non-personal organization's api key!

```bash
export LANGCHAIN_HUB_API_KEY="ls_..."
```

## 3. Pull an object from the hub and use it

```ts
// import
import * as hub from "langchain/hub";
import { ChatOpenAI } from "langchain/chat_models/openai";

// pull a chat prompt
const prompt = await hub.pull("efriis/my-first-prompt");

// create a model to use it with
const model = new ChatOpenAI();

// use it in a runnable
const runnable = prompt.pipe(model);
const result = await runnable.invoke({
"profession": "biologist",
"question": "What is special about parrots?",
});

console.log(result);
```

## 4. Push it back to your personal organization as a private prompt

For this step, you'll need the `handle` for your account!

```ts
import * as hub from "langchain/hub";

await hub.push("<handle>/my-first-prompt", prompt);
```
21 changes: 21 additions & 0 deletions docs/hub/faq.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
sidebar_label: FAQs
sidebar_position: 4
---
# Frequently Asked Questions

### Why can't I use my organization with hub?

Hub is currently only available for "Personal" organizations! We are working on adding support for other organizations.

### Why can't I push anything other than PromptTemplates and ChatPromptTemplates?

Hub currently only supports these two types of LangChain objects. We are working on adding support for more!

### Can I upload a prompt to the hub from a LangSmith Trace?

Coming soon!

### Can LangChain Hub do ____?

Maybe, and we'd love to hear from you! Please join the `hub-feedback` [discord](https://discord.gg/6adMQxSpJS) channel
93 changes: 93 additions & 0 deletions docs/hub/quickstart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
sidebar_label: Quick Start
sidebar_position: 1
---

# Quick Start

## What is LangChain Hub?

LangChain Hub lets you discover, share, and version control prompts for LangChain and LLMs in general.

It's a great place to find inspiration for your own prompts, or to share your own prompts with the world!

Currently, it supports LangChain prompt templates, and more object types are coming soon.

:::tip Public Features
Some hub features can be used without logging in [here](https://smith.langchain.com/hub)! However, creating and modifying prompts requires a non-waitlisted account.
:::

The steps in this guide will acquaint you with LangChain Hub:

1. Browse the hub for a prompt of interest
2. Try out a prompt in the playground
3. Log in and set a handle
4. Modify the prompt in the playground and commit it back to the hub

## 1. Browse the hub for a prompt of interest

You can access the public view of the hub directly at [https://smith.langchain.com/hub](https://smith.langchain.com/hub).

From this screen, you can browse prompts that others have published.

![Hub Home](static/hub-home.png)

On the left side, you can filter by different **tags**, such as types of prompts (Chat vs. Regular), use cases, or models they're designed to be used with (llama-2 vs. gpt-4).

If you see a prompt that looks interesting, you can either click into its page, or you can jump straight to using it in the playground with the "Try it" button.

## 2. Try out a prompt in the playground

For this example, we'll use the following prompt: [https://smith.langchain.com/hub/langchain/my-first-prompt](https://smith.langchain.com/hub/efriis/my-first-prompt)

![Hub Prompt](static/hub-repo.png)

To start, you can get a sense of what the prompt does just by looking at it (this one is pretty straightforward).
Below the contents of the prompt, you can see a code snippet of how to use it in Python. For more information on
using hub prompts from code, finish this guide and check out the developer guides in [Python](dev-setup-py) or [TypeScript](dev-setup-ts).

Next, let's try out the object in the playground by clicking the [playground button](https://smith.langchain.com/hub/efriis/my-first-prompt/playground) in the top-right.

The playground should look like this:

![Hub Playground](static/hub-playground.png)

On the left, we see an editable view of our Chat Prompt.

To the right, we can configure our inputs and model, and above that, you can add API Keys for playground-supported model providers.

Let's try it out! First, fill out your OpenAI API Key in "Secrets", and fill out a profession (e.g. biologist) and question (e.g. "what is 1 fun fact about parrots?"). Now click "Run"!
The output should look something like this:

![Hub Playground after running](static/hub-playground-complete.png)

## 3. Log in and set a handle (One-Time Setup)

:::note
You must log into an account, where the "Personal" organization is not waitlisted, in order to proceed with steps 3 and 4.
:::

Now that we've tried out a prompt, let's log in and set a handle. This will allow us to commit changes to the prompt back to the hub under our own user!

First, let's click that "Login" button in the top-right and log in. If you find yourself on the waitlist, you can enter your access code if you have one, or hang tight! We're letting people off every week.

Second, go to the [hub home](https://smith.langchain.com/hub). If you haven't set a handle yet, you'll be prompted to add one, so people can associate your prompts with you!

The handle reserves a namespace for all of your prompts, so everything you add will be saved under `your-handle/prompt-name`.

![Hub Set Handle](static/hub-handle.png)


## 4. Commit to a new repo under your user


Staying on [efriis/my-first-prompt's playground](https://smith.langchain.com/hub/efriis/my-first-prompt/playground), let's make some changes and commit it back to a
repository under your user. To start, let's modify the prompt to change the style of the response. Instead of answering "cheerfully," pick a new adverb (e.g. "angrily").

Once you've run it, we can commit it directly to a new prompt under your user. Click the "Commit" button in the top-right, and you should see a modal like this:

**Note:** you may have to return to the repo page and click the "Playground" button in order to see the "Commit" button.

![Hub Playground Commit](static/hub-playground-commit.png)

Here, you can create a new repo called `my-first-prompt` and use this as a first commit! Once you've done that, you'll be redirected to your new prompt.
Binary file added docs/hub/static/hub-handle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/hub/static/hub-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/hub/static/hub-playground-commit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/hub/static/hub-playground-complete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/hub/static/hub-playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/hub/static/hub-repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ It lets you debug, test, evaluate, and monitor chains and intelligent agents bui

LangSmith is developed by LangChain, the company behind the open source LangChain framework.

:::note Waitlist
LangSmith is currently in private beta. If you'd like to be added to the waitlist, please sign up for an account [here](https://smith.langchain.com/).
:::

:::note Active Development
LangSmith is an early product in beta. We may need to periodically gate new signups to ensure a smooth experience for our users. If you run into any urgent issues or bugs, please reach out to us at <a href="mailto:support@langchain.dev">support@langchain.dev</a>.
LangSmith is an early product in beta. If you run into any urgent issues or bugs, please reach out to us at <a href="mailto:support@langchain.dev">support@langchain.dev</a>.

We appreciate your patience.
:::
Expand Down
13 changes: 13 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ module.exports = {
type: "generated-index",
description: 'Use LangSmith to collaborate with your team on all your LLM applications. Check out the guides below for more information.',
},
},
{
type: "category",
label: "Hub",
collapsed: false,
collapsible: false,
items: [
{ type: "autogenerated", dirName: "hub" }
],
link: {
type: "generated-index",
description: 'Discover, share, and version control prompts in the LangChain Hub.',
},
}
],
};

0 comments on commit 5a2ece9

Please sign in to comment.