Skip to content

Commit dd70fa8

Browse files
author
Erick Friis
authored
Merge pull request langchain-ai#16 from langchain-ai/erick/hub-docs-updates
Hub Docs Updates
2 parents 432f8c0 + ab8c8d0 commit dd70fa8

File tree

5 files changed

+156
-94
lines changed

5 files changed

+156
-94
lines changed

docs/hub/dev-setup-ts.mdx

-60
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
---
2-
sidebar_label: Python Setup
2+
sidebar_label: Developer Setup
33
sidebar_position: 2
44
---
5-
# Python Setup
65

7-
This guide will continue from the hub quickstart, using the Python SDK to interact with the hub instead of the Playground UI.
6+
import {
7+
HubInstallationCodeTabs,
8+
HubPullCodeTabs,
9+
HubPushCodeTabs,
10+
} from "@site/src/components/Hub";
11+
12+
# Developer Setup
13+
14+
This guide will continue from the hub quickstart, using the Python or TypeScript SDK to interact with the hub instead of the Playground UI.
815

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

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

1320
## 1. Install/upgrade packages
1421

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

17-
```bash
18-
pip install --upgrade langchain langchainhub
19-
```
24+
<HubInstallationCodeTabs />
2025

2126
## 2. Configuring environment variables
2227

@@ -26,32 +31,14 @@ Get an API key for your **Personal** organization if you have not yet. The hub w
2631
export LANGCHAIN_HUB_API_KEY="ls_..."
2732
```
2833

29-
## 3. Pull an object from the hub and use it
30-
31-
```python
32-
from langchain import hub
34+
If you already have `LANGCHAIN_API_KEY` set to a personal organization’s api key from LangSmith, you can skip this.
3335

34-
# pull a chat prompt
35-
prompt = hub.pull("efriis/my-first-prompt")
36-
37-
# create a model to use it with
38-
from langchain.chat_models import ChatOpenAI
39-
model = ChatOpenAI()
36+
## 3. Pull an object from the hub and use it
4037

41-
# use it in a runnable
42-
runnable = prompt | model
43-
runnable.invoke({
44-
"profession": "biologist",
45-
"question": "What is special about parrots?",
46-
})
47-
```
38+
<HubPullCodeTabs />
4839

49-
## 4. Push it back to your personal organization as a private prompt
40+
## 4. Push a prompt to your personal organization
5041

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

53-
```python
54-
from langchain import hub
55-
56-
hub.push("<handle>/my-first-prompt", prompt)
57-
```
44+
<HubPushCodeTabs />

docs/hub/faq.mdx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
22
sidebar_label: FAQs
3-
sidebar_position: 4
3+
sidebar_position: 3
44
---
55
# Frequently Asked Questions
66

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

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

11-
### Why can't I push anything other than PromptTemplates and ChatPromptTemplates?
11+
### Why can't I push anything other than prompts?
1212

13-
Hub currently only supports these two types of LangChain objects. We are working on adding support for more!
13+
Hub currently only supports LangChain prompt objects. We are working on adding support for more!
14+
15+
If you have a specific request, please join the `hub-feedback` [discord](https://discord.gg/6adMQxSpJS) channel and let us know!
1416

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

docs/hub/quickstart.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ For this example, we'll use the following prompt: [https://smith.langchain.com/h
4444

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

4949
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.
5050

@@ -91,3 +91,4 @@ Once you've run it, we can commit it directly to a new prompt under your user. C
9191
![Hub Playground Commit](static/hub-playground-commit.png)
9292

9393
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.
94+

src/components/Hub.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import React from 'react';
2+
import Tabs from "@theme/Tabs";
3+
import TabItem from "@theme/TabItem";
4+
import CodeBlock from '@theme/CodeBlock';
5+
6+
import {
7+
CodeTabs,
8+
PythonBlock,
9+
TypeScriptBlock,
10+
ShellBlock,
11+
} from './InstructionsWithCode';
12+
13+
export const HubInstallationCodeTabs = () => (
14+
<CodeTabs
15+
groupId="client-language"
16+
tabs={[
17+
{
18+
value: 'python',
19+
label: 'pip',
20+
language: 'bash',
21+
content: `pip install -U langchain langchainhub`,
22+
},
23+
{
24+
value: 'typescript',
25+
label: 'yarn',
26+
language: 'bash',
27+
content: `yarn add langchain langchainhub`,
28+
},
29+
{
30+
value: 'npm',
31+
label: 'npm',
32+
language: 'bash',
33+
content: `npm install -S langchain langchainhub`,
34+
},
35+
{
36+
value: 'pnpm',
37+
label: 'pnpm',
38+
language: 'bash',
39+
content: `pnpm add langchain langchainhub`,
40+
},
41+
]}
42+
/>
43+
);
44+
45+
export const HubPullCodeTabs = ({}) => {
46+
const pyBlock = `from langchain import hub
47+
48+
# pull a chat prompt
49+
prompt = hub.pull("efriis/my-first-prompt")
50+
51+
# create a model to use it with
52+
from langchain.chat_models import ChatOpenAI
53+
model = ChatOpenAI()
54+
55+
# use it in a runnable
56+
runnable = prompt | model
57+
runnable.invoke({
58+
"profession": "biologist",
59+
"question": "What is special about parrots?",
60+
})`;
61+
62+
const jsBlock = `// import
63+
import * as hub from "langchain/hub";
64+
import { ChatOpenAI } from "langchain/chat_models/openai";
65+
66+
// pull a chat prompt
67+
const prompt = await hub.pull("efriis/my-first-prompt");
68+
69+
// create a model to use it with
70+
const model = new ChatOpenAI();
71+
72+
// use it in a runnable
73+
const runnable = prompt.pipe(model);
74+
const result = await runnable.invoke({
75+
"profession": "biologist",
76+
"question": "What is special about parrots?",
77+
});
78+
79+
console.log(result);`
80+
81+
return (
82+
<Tabs groupId="client-language">
83+
<TabItem key="python" value="python" label="Python">
84+
<CodeBlock className="python" language="python">
85+
{pyBlock}
86+
</CodeBlock>
87+
</TabItem>
88+
<TabItem key="typescript" value="typescript" label="TypeScript">
89+
<CodeBlock className="typescript" language="typescript">
90+
{jsBlock}
91+
</CodeBlock>
92+
</TabItem>
93+
</Tabs>
94+
);
95+
};
96+
97+
export const HubPushCodeTabs = ({}) => {
98+
const pyBlock = `from langchain import hub
99+
from langchain.prompts.chat import ChatPromptTemplate
100+
101+
prompt = ChatPromptTemplate.from_template("tell me a joke about {topic}")
102+
103+
hub.push("<handle>/topic-joke-generator", prompt)`;
104+
105+
const jsBlock = `import * as hub from "langchain/hub";
106+
import {
107+
ChatPromptTemplate,
108+
HumanMessagePromptTemplate,
109+
} from 'langchain/prompts';
110+
111+
const message = HumanMessagePromptTemplate.fromTemplate(
112+
'tell me a joke about {topic}'
113+
);
114+
const prompt = ChatPromptTemplate.fromPromptMessages([message]);
115+
116+
await hub.push("<handle>/my-first-prompt", prompt);`
117+
118+
return (
119+
<Tabs groupId="client-language">
120+
<TabItem key="python" value="python" label="Python">
121+
<CodeBlock className="python" language="python">
122+
{pyBlock}
123+
</CodeBlock>
124+
</TabItem>
125+
<TabItem key="typescript" value="typescript" label="TypeScript">
126+
<CodeBlock className="typescript" language="typescript">
127+
{jsBlock}
128+
</CodeBlock>
129+
</TabItem>
130+
</Tabs>
131+
);
132+
};

0 commit comments

Comments
 (0)