From 519f31ca40a302f229614f330cbc9b1870365119 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Sun, 3 Sep 2023 20:34:22 -0700 Subject: [PATCH 1/4] formatting, env var --- docs/hub/dev-setup-ts.mdx | 60 ---------- docs/hub/{dev-setup-py.mdx => dev-setup.mdx} | 43 +++---- docs/hub/faq.mdx | 2 +- docs/hub/quickstart.mdx | 1 + src/components/Hub.js | 120 +++++++++++++++++++ 5 files changed, 137 insertions(+), 89 deletions(-) delete mode 100644 docs/hub/dev-setup-ts.mdx rename docs/hub/{dev-setup-py.mdx => dev-setup.mdx} (57%) create mode 100644 src/components/Hub.js diff --git a/docs/hub/dev-setup-ts.mdx b/docs/hub/dev-setup-ts.mdx deleted file mode 100644 index 2aeb584ee692a..0000000000000 --- a/docs/hub/dev-setup-ts.mdx +++ /dev/null @@ -1,60 +0,0 @@ ---- -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("/my-first-prompt", prompt); -``` diff --git a/docs/hub/dev-setup-py.mdx b/docs/hub/dev-setup.mdx similarity index 57% rename from docs/hub/dev-setup-py.mdx rename to docs/hub/dev-setup.mdx index e8fb681b99762..d80393097f36c 100644 --- a/docs/hub/dev-setup-py.mdx +++ b/docs/hub/dev-setup.mdx @@ -1,10 +1,17 @@ --- -sidebar_label: Python Setup +sidebar_label: Developer 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. +import { + HubInstallationCodeTabs, + HubPullCodeTabs, + HubPushCodeTabs, +} from "@site/src/components/Hub"; + +# Developer Setup + +This guide will continue from the hub quickstart, using the Python or 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. @@ -14,9 +21,7 @@ If you don't yet have an account, you'll only be able to pull public objects in **Note:** You likely need to upgrade even if they're already installed! -```bash -pip install --upgrade langchain langchainhub -``` + ## 2. Configuring environment variables @@ -26,32 +31,14 @@ Get an API key for your **Personal** organization if you have not yet. The hub w export LANGCHAIN_HUB_API_KEY="ls_..." ``` -## 3. Pull an object from the hub and use it - -```python -from langchain import hub +If you already have `LANGCHAIN_API_KEY` set to a personal organization’s api key from LangSmith, you can skip this. -# 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() +## 3. Pull an object from the hub and use it -# 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("/my-first-prompt", prompt) -``` + diff --git a/docs/hub/faq.mdx b/docs/hub/faq.mdx index 907f09abec2ad..1db439aae2bc6 100644 --- a/docs/hub/faq.mdx +++ b/docs/hub/faq.mdx @@ -1,6 +1,6 @@ --- sidebar_label: FAQs -sidebar_position: 4 +sidebar_position: 3 --- # Frequently Asked Questions diff --git a/docs/hub/quickstart.mdx b/docs/hub/quickstart.mdx index 57282126a0401..dc3c0a5a3bf8b 100644 --- a/docs/hub/quickstart.mdx +++ b/docs/hub/quickstart.mdx @@ -91,3 +91,4 @@ Once you've run it, we can commit it directly to a new prompt under your user. C ![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. + diff --git a/src/components/Hub.js b/src/components/Hub.js new file mode 100644 index 0000000000000..01bdf52fd25d4 --- /dev/null +++ b/src/components/Hub.js @@ -0,0 +1,120 @@ +import React from 'react'; +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; +import CodeBlock from '@theme/CodeBlock'; + +import { + CodeTabs, + PythonBlock, + TypeScriptBlock, + ShellBlock, +} from './InstructionsWithCode'; + +export const HubInstallationCodeTabs = () => ( + +); + +export const HubPullCodeTabs = ({}) => { + const pyBlock = `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?", +})`; + +const jsBlock = `// 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);` + + return ( + + + + {pyBlock} + + + + + {jsBlock} + + + + ); +}; + +export const HubPushCodeTabs = ({}) => { + const pyBlock = `from langchain import hub + +hub.push("/my-first-prompt", prompt)`; + +const jsBlock = `import * as hub from "langchain/hub"; + +await hub.push("/my-first-prompt", prompt);` + + return ( + + + + {pyBlock} + + + + + {jsBlock} + + + + ); +}; \ No newline at end of file From 420c0a29e7745492495536b3a49b647b3204f790 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Sun, 3 Sep 2023 20:58:21 -0700 Subject: [PATCH 2/4] separate example --- docs/hub/dev-setup.mdx | 4 ++-- src/components/Hub.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/hub/dev-setup.mdx b/docs/hub/dev-setup.mdx index d80393097f36c..56b44885c4d2a 100644 --- a/docs/hub/dev-setup.mdx +++ b/docs/hub/dev-setup.mdx @@ -15,7 +15,7 @@ This guide will continue from the hub quickstart, using the Python or TypeScript 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. +If you don't yet have an account, you'll only be able to pull public objects. ## 1. Install/upgrade packages @@ -37,7 +37,7 @@ If you already have `LANGCHAIN_API_KEY` set to a personal organization’s api k -## 4. Push it back to your personal organization as a private prompt +## 4. Push a prompt to your personal organization as a private prompt For this step, you'll need the `handle` for your account! diff --git a/src/components/Hub.js b/src/components/Hub.js index 01bdf52fd25d4..903f461c07dcc 100644 --- a/src/components/Hub.js +++ b/src/components/Hub.js @@ -96,10 +96,22 @@ console.log(result);` export const HubPushCodeTabs = ({}) => { const pyBlock = `from langchain import hub +from langchain.prompts.chat import ChatPromptTemplate -hub.push("/my-first-prompt", prompt)`; +prompt = ChatPromptTemplate.from_template("tell me a joke about {topic}") + +hub.push("/topic-joke-generator", prompt)`; const jsBlock = `import * as hub from "langchain/hub"; +import { + ChatPromptTemplate, + HumanMessagePromptTemplate, +} from 'langchain/prompts'; + +const message = HumanMessagePromptTemplate.fromTemplate( + 'tell me a joke about {topic}' +); +const prompt = ChatPromptTemplate.fromPromptMessages([message]); await hub.push("/my-first-prompt", prompt);` From 9434a7f41e89721a957374d0ab72076fc0eb8c84 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Sun, 3 Sep 2023 21:02:38 -0700 Subject: [PATCH 3/4] fix broken link --- docs/hub/quickstart.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hub/quickstart.mdx b/docs/hub/quickstart.mdx index dc3c0a5a3bf8b..ee7005a1d7cff 100644 --- a/docs/hub/quickstart.mdx +++ b/docs/hub/quickstart.mdx @@ -44,7 +44,7 @@ For this example, we'll use the following prompt: [https://smith.langchain.com/h 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). +using hub prompts from code, finish this guide and check out the [developer guide](dev-setup). 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. From ab8c8d06677ae31a41a0c981bb441489c2e481e1 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Mon, 4 Sep 2023 11:58:19 -0700 Subject: [PATCH 4/4] harrison review --- docs/hub/dev-setup.mdx | 2 +- docs/hub/faq.mdx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/hub/dev-setup.mdx b/docs/hub/dev-setup.mdx index 56b44885c4d2a..503c03801ff47 100644 --- a/docs/hub/dev-setup.mdx +++ b/docs/hub/dev-setup.mdx @@ -37,7 +37,7 @@ If you already have `LANGCHAIN_API_KEY` set to a personal organization’s api k -## 4. Push a prompt to your personal organization as a private prompt +## 4. Push a prompt to your personal organization For this step, you'll need the `handle` for your account! diff --git a/docs/hub/faq.mdx b/docs/hub/faq.mdx index 1db439aae2bc6..e464f09939ad7 100644 --- a/docs/hub/faq.mdx +++ b/docs/hub/faq.mdx @@ -8,9 +8,11 @@ sidebar_position: 3 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? +### Why can't I push anything other than prompts? -Hub currently only supports these two types of LangChain objects. We are working on adding support for more! +Hub currently only supports LangChain prompt objects. We are working on adding support for more! + +If you have a specific request, please join the `hub-feedback` [discord](https://discord.gg/6adMQxSpJS) channel and let us know! ### Can I upload a prompt to the hub from a LangSmith Trace?