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 including login-required steps.
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!
- pip
- yarn
- npm
pip install -U langchain langchainhub langchain-openai
yarn add langchain
npm install -S langchain
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!
export LANGCHAIN_HUB_API_KEY="ls_..."
If you already have LANGCHAIN_API_KEY
set to a personal organization’s api key from LangSmith, you can skip this.
3. Pull an object from the hub and use it
- Python
- TypeScript
from langchain import hub
# pull a chat prompt
prompt = hub.pull("efriis/my-first-prompt")
# create a model to use it with
from langchain_openai import ChatOpenAI
model = ChatOpenAI()
# use it in a runnable
runnable = prompt | model
response = runnable.invoke({
"profession": "biologist",
"question": "What is special about parrots?",
})
print(response)
// import
import * as hub from "langchain/hub";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";
// pull a chat prompt
const prompt = await hub.pull<ChatPromptTemplate>("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 a prompt to your personal organization
For this step, you'll need the handle
for your account!
- Python
- TypeScript
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, new_repo_is_public=False)
import * as hub from "langchain/hub";
import {
ChatPromptTemplate,
HumanMessagePromptTemplate,
} from '@langchain/core/prompts';
const message = HumanMessagePromptTemplate.fromTemplate(
'tell me a joke about {topic}'
);
const prompt = ChatPromptTemplate.fromMessages([message]);
await hub.push("my-first-prompt", prompt, { newRepoIsPublic: false });