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 50% rename from docs/hub/dev-setup-py.mdx rename to docs/hub/dev-setup.mdx index e8fb681b99762..503c03801ff47 100644 --- a/docs/hub/dev-setup-py.mdx +++ b/docs/hub/dev-setup.mdx @@ -1,22 +1,27 @@ --- -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. -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 **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 +## 4. Push a prompt to your personal organization 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..e464f09939ad7 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 @@ -8,9 +8,11 @@ sidebar_position: 4 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? diff --git a/docs/hub/quickstart.mdx b/docs/hub/quickstart.mdx index 57282126a0401..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. @@ -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..903f461c07dcc --- /dev/null +++ b/src/components/Hub.js @@ -0,0 +1,132 @@ +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 +from langchain.prompts.chat import ChatPromptTemplate + +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);` + + return ( + + + + {pyBlock} + + + + + {jsBlock} + + + + ); +}; \ No newline at end of file