Skip to content

Commit 0de457d

Browse files
authored
Harrison/docs (#23)
* stash * cr * cr
1 parent 76d5352 commit 0de457d

File tree

16 files changed

+213
-147
lines changed

16 files changed

+213
-147
lines changed

docs/docs/getting-started.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,16 @@ Now we can get started!
178178
179179
```typescript
180180
import { OpenAI } from "langchain";
181-
import { loadAgent, AgentExecutor } from "langchain/agents";
181+
import { initializeAgentExecutor } from "langchain/agents";
182182
import { SerpAPI, Calculator } from "langchain/tools";
183183
184-
const model = new OpenAI();
184+
const model = new OpenAI({temperature: 0});
185185
const tools = [new SerpAPI(), new Calculator()];
186186
187-
const agent = await loadAgent(
188-
"lc://agents/zero-shot-react-description/agent.json",
189-
{ llm: model, tools }
187+
const executor = await initializeAgentExecutor(
188+
tools, model, "zero-shot-react-description"
190189
);
191-
console.log("Loaded agent from Langchain hub");
192-
193-
const executor = AgentExecutor.fromAgentAndTools({
194-
agent,
195-
tools,
196-
returnIntermediateSteps: true,
197-
});
190+
console.log("Loaded agent.");
198191
199192
const input = "Who is Olivia Wilde's boyfriend?" +
200193
" What is his current age raised to the 0.23 power?";

docs/docs/modules/agents/getting_started.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Load from Hub
2+
3+
[LangChainHub](https://github.com/hwchase17/langchain-hub) contains a collection of chains which can be loaded directly via LangChain.
4+
5+
For this example, you will also need to install the SerpAPI Python package.
6+
7+
```bash
8+
npm i serpapi
9+
```
10+
11+
And set the appropriate environment variables in the `.env` file.
12+
13+
```
14+
SERPAPI_API_KEY="..."
15+
```
16+
17+
Now we can get started!
18+
19+
```typescript
20+
import { OpenAI } from "langchain";
21+
import { loadAgent, AgentExecutor } from "langchain/agents";
22+
import { SerpAPI, Calculator } from "langchain/tools";
23+
24+
const model = new OpenAI();
25+
const tools = [new SerpAPI(), new Calculator()];
26+
27+
const agent = await loadAgent(
28+
"lc://agents/zero-shot-react-description/agent.json",
29+
{ llm: model, tools }
30+
);
31+
console.log("Loaded agent from Langchain hub");
32+
33+
const executor = AgentExecutor.fromAgentAndTools({
34+
agent,
35+
tools,
36+
returnIntermediateSteps: true,
37+
});
38+
39+
const input = "Who is Olivia Wilde's boyfriend?" +
40+
" What is his current age raised to the 0.23 power?";
41+
console.log(`Executing with input "${input}"...`);
42+
43+
const result = await executor.call({ input });
44+
45+
console.log(`Got output ${result.output}`);
46+
```
47+
48+
```shell
49+
langchain-examples:start: Executing with input "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?"...
50+
langchain-examples:start: Got output Olivia Wilde's boyfriend is Jason Sudeikis, and his current age raised to the 0.23 power is 2.4242784855673896.
51+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Agent Overview
2+
3+
Agents use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning to the user.
4+
5+
When used correctly agents can be extremely powerful. In this tutorial, we show you how to easily use agents through the simplest, highest level API.
6+
7+
8+
In order to load agents, you should understand the following concepts:
9+
10+
- Tool: A function that performs a specific duty. This can be things like: Google Search, Database lookup, code REPL, other chains. The interface for a tool is currently a function that is expected to have a string as an input, with a string as an output.
11+
- LLM: The language model powering the agent.
12+
- Agent: The agent to use. This should be a string that references a support agent class. Because this notebook focuses on the simplest, highest level API, this only covers using the standard supported agents.
13+
14+
For this example, you will also need to install the SerpAPI Python package.
15+
16+
```bash
17+
npm i serpapi
18+
```
19+
20+
And set the appropriate environment variables in the `.env` file.
21+
22+
```
23+
SERPAPI_API_KEY="..."
24+
```
25+
26+
Now we can get started!
27+
28+
```typescript
29+
import { OpenAI } from "langchain";
30+
import { initializeAgentExecutor } from "langchain/agents";
31+
import { SerpAPI, Calculator } from "langchain/tools";
32+
33+
const model = new OpenAI({temperature: 0});
34+
const tools = [new SerpAPI(), new Calculator()];
35+
36+
const executor = await initializeAgentExecutor(
37+
tools, model, "zero-shot-react-description"
38+
);
39+
console.log("Loaded agent.");
40+
41+
const input = "Who is Olivia Wilde's boyfriend?" +
42+
" What is his current age raised to the 0.23 power?";
43+
console.log(`Executing with input "${input}"...`);
44+
45+
const result = await executor.call({ input });
46+
47+
console.log(`Got output ${result.output}`);
48+
```
49+
50+
```shell
51+
langchain-examples:start: Executing with input "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?"...
52+
langchain-examples:start: Got output Olivia Wilde's boyfriend is Jason Sudeikis, and his current age raised to the 0.23 power is 2.4242784855673896.
53+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Load from Hub
2+
3+
[LangChainHub](https://github.com/hwchase17/langchain-hub) contains a collection of chains which can be loaded directly via LangChain.
4+
5+
```typescript
6+
import { loadChain } from "langchain/chains";
7+
8+
const chain = await loadChain("lc://chains/hello-world/chain.json");
9+
const res = chain.call({topic: "foo"});
10+
console.log(res);
11+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Vectorstores
2+
3+
A vectorstore is a particular type of database optimized for storing documents, embeddings, and then allowing for fetching of the most relevant documents for a particular query.
4+
5+
```typescript
6+
import { HNSWLib } from "langchain/vectorstores";
7+
import { OpenAIEmbeddings } from "langchain/embeddings";
8+
9+
const vectorStore = await HNSWLib.fromTexts(
10+
["Hello world", "Bye bye", "hello nice world"],
11+
[{ id: 2 }, { id: 1 }, { id: 3 }],
12+
new OpenAIEmbeddings()
13+
);
14+
15+
const resultOne = await vectorStore.similaritySearch("hello world", 1);
16+
```

docs/docs/modules/memory/buffer_memory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Buffer Memory
1+
# Buffer Memory
22

33
BufferMemory is the simplest type of memory - it just remembers previous conversational back and forths directly.
44

docs/docs/modules/prompts/load_from_hub.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import { loadPrompt } from "langchain/prompt";
77
const prompt = await loadPrompt("lc://prompts/hello-world/prompt.yaml");
88
const res = prompt.format({});
99
console.log({ res });
10-
```
10+
```

docs/docs/modules/prompts/prompt_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Prompt Templates
1+
# Prompt Templates
22

33
This example walks through how to use PromptTemplates.
44
At their core, prompt templates are objects that are made up of a template with certain input variables.
@@ -19,4 +19,4 @@ console.log({ res });
1919

2020
```shell
2121
{ res: 'What is a good name for a company that makes colorful socks?' }
22-
```
22+
```

docs/docs/overview.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Welcome to LangChain
2+
3+
Large language models (LLMs) are emerging as a transformative technology, enabling
4+
developers to build applications that they previously could not.
5+
But using these LLMs in isolation is often not enough to
6+
create a truly powerful app - the real power comes when you are able to
7+
combine them with other sources of computation or knowledge.
8+
9+
This library is aimed at assisting in the development of those types of applications. Common examples of these types of applications include:
10+
11+
-[Question Answering over specific documents](./modules/chains/question_answering.md)
12+
- 💬 [Chatbots](./modules/memory/buffer_memory.md)
13+
- 🤖 [Agents](./modules/agents/overview.md)
14+
15+
## Getting Started
16+
17+
Checkout the below guide for a walkthrough of how to get started using LangChain to create an Language Model application.
18+
19+
- [Getting Started Documentation](./getting-started.md)
20+
21+
## Modules
22+
23+
There are several main modules that LangChain provides support for.
24+
For each module we provide some examples to get started and get familiar with some of the concepts.
25+
These modules are, in increasing order of complexity:
26+
27+
28+
- Prompts: This includes prompt management, prompt optimization, and prompt serialization.
29+
30+
- LLMs: This includes a generic interface for all LLMs, and common utilities for working with LLMs.
31+
32+
- Indexes: This includes patterns and functionality for structuring your own text data so it can interact with language models (including embeddings, vectorstores, text splitters, etc).
33+
34+
- Chains: Chains go beyond just a single LLM call, and are sequences of calls (whether to an LLM or a different utility). LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.
35+
36+
- Agents: Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end to end agents.
37+
38+
- Memory: Memory is the concept of persisting state between calls of a chain/agent. LangChain provides a standard interface for memory, a collection of memory implementations, and examples of chains/agents that use memory.
39+
40+
41+
## Reference Docs
42+
---------------
43+
44+
All of LangChain's reference documentation, in one place. Full documentation on all methods and classes.
45+
46+
47+
## Additional Resources
48+
---------------------
49+
50+
Additional collection of resources we think may be useful as you develop your application!
51+
52+
- [LangChainHub](https://github.com/hwchase17/langchain-hub): The LangChainHub is a place to share and explore other prompts, chains, and agents.
53+
54+
- [Discord](https://discord.gg/6adMQxSpJS): Join us on our Discord to discuss all things LangChain!
55+
56+
- [Production Support](https://forms.gle/57d8AmXBYp8PP8tZA): As you move your LangChains into production, we'd love to offer more comprehensive support. Please fill out this form and we'll set up a dedicated support Slack channel.

0 commit comments

Comments
 (0)