forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request langchain-ai#16 from langchain-ai/erick/hub-docs-u…
…pdates Hub Docs Updates
- Loading branch information
Showing
5 changed files
with
156 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = () => ( | ||
<CodeTabs | ||
groupId="client-language" | ||
tabs={[ | ||
{ | ||
value: 'python', | ||
label: 'pip', | ||
language: 'bash', | ||
content: `pip install -U langchain langchainhub`, | ||
}, | ||
{ | ||
value: 'typescript', | ||
label: 'yarn', | ||
language: 'bash', | ||
content: `yarn add langchain langchainhub`, | ||
}, | ||
{ | ||
value: 'npm', | ||
label: 'npm', | ||
language: 'bash', | ||
content: `npm install -S langchain langchainhub`, | ||
}, | ||
{ | ||
value: 'pnpm', | ||
label: 'pnpm', | ||
language: 'bash', | ||
content: `pnpm add langchain langchainhub`, | ||
}, | ||
]} | ||
/> | ||
); | ||
|
||
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 ( | ||
<Tabs groupId="client-language"> | ||
<TabItem key="python" value="python" label="Python"> | ||
<CodeBlock className="python" language="python"> | ||
{pyBlock} | ||
</CodeBlock> | ||
</TabItem> | ||
<TabItem key="typescript" value="typescript" label="TypeScript"> | ||
<CodeBlock className="typescript" language="typescript"> | ||
{jsBlock} | ||
</CodeBlock> | ||
</TabItem> | ||
</Tabs> | ||
); | ||
}; | ||
|
||
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("<handle>/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("<handle>/my-first-prompt", prompt);` | ||
|
||
return ( | ||
<Tabs groupId="client-language"> | ||
<TabItem key="python" value="python" label="Python"> | ||
<CodeBlock className="python" language="python"> | ||
{pyBlock} | ||
</CodeBlock> | ||
</TabItem> | ||
<TabItem key="typescript" value="typescript" label="TypeScript"> | ||
<CodeBlock className="typescript" language="typescript"> | ||
{jsBlock} | ||
</CodeBlock> | ||
</TabItem> | ||
</Tabs> | ||
); | ||
}; |