forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mass/discord-api-integration
- Loading branch information
Showing
152 changed files
with
5,940 additions
and
1,019 deletions.
There are no files selected for viewing
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,21 @@ | ||
# Contributing third-party Text Embeddings | ||
|
||
This page contains some specific guidelines and examples for contributing integrations with third-party Text Embedding providers. | ||
|
||
**Make sure you read the [general guidelines page](https://github.com/langchain-ai/langchainjs/blob/main/.github/contributing/INTEGRATIONS.md) first!** | ||
|
||
## Example PR | ||
|
||
We'll be referencing this PR adding Gradient Embeddings as an example: https://github.com/langchain-ai/langchainjs/pull/3475 | ||
|
||
## General ideas | ||
|
||
The general idea for adding new third-party Text Embeddings is to subclass the `Embeddings` class and implement the `embedDocuments` and `embedQuery` methods. | ||
|
||
The `embedDocuments` method should take a list of documents and return a list of embeddings for each document. The `embedQuery` method should take a query and return an embedding for that query. | ||
|
||
`embedQuery` can typically be implemented by calling `embedDocuments` with a list containing only the query. | ||
|
||
## Wrap Text Embeddings requests in this.caller | ||
|
||
The base Embeddings class contains an instance property called `caller` that will automatically handle retries, errors, timeouts, and more. You should wrap calls to the LLM in `this.caller.call` [as shown here](https://github.com/langchain-ai/langchainjs/blob/f469ec00d945a3f8421b32f4be78bce3f66a74bb/langchain/src/embeddings/gradient_ai.ts#L72) |
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 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
39 changes: 39 additions & 0 deletions
39
docs/core_docs/docs/integrations/text_embedding/gradient_ai.mdx
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,39 @@ | ||
--- | ||
sidebar_class_name: node-only | ||
--- | ||
|
||
# Gradient AI | ||
|
||
The `GradientEmbeddings` class uses the Gradient AI API to generate embeddings for a given text. | ||
|
||
## Setup | ||
|
||
You'll need to install the official Gradient Node SDK as a peer dependency: | ||
|
||
```bash npm2yarn | ||
npm i @gradientai/nodejs-sdk | ||
``` | ||
|
||
You will need to set the following environment variables for using the Gradient AI API. | ||
|
||
``` | ||
export GRADIENT_ACCESS_TOKEN=<YOUR_ACCESS_TOKEN> | ||
export GRADIENT_WORKSPACE_ID=<YOUR_WORKSPACE_ID> | ||
``` | ||
|
||
Alternatively, these can be set during the GradientAI Class instantiation as `gradientAccessKey` and `workspaceId` respectively. | ||
For example: | ||
|
||
```typescript | ||
const model = new GradientEmbeddings({ | ||
gradientAccessKey: "My secret Access Token" | ||
workspaceId: "My secret workspace id" | ||
}); | ||
``` | ||
|
||
## Usage | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
import GradientEmbeddingsExample from "@examples/embeddings/gradient_ai.ts"; | ||
|
||
<CodeBlock language="typescript">{GradientEmbeddingsExample}</CodeBlock> |
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,25 @@ | ||
import CodeBlock from "@theme/CodeBlock"; | ||
import Example from "@examples/agents/connery_mrkl.ts"; | ||
|
||
# Connery Actions Toolkit | ||
|
||
Using this toolkit, you can integrate Connery actions into your LangChain agents and chains. | ||
|
||
## What is Connery? | ||
|
||
Connery is an open-source plugin infrastructure for AI. | ||
|
||
With Connery, you can easily create a custom plugin, which is essentially a set of actions, and use them in your LangChain agents and chains. | ||
Connery will handle the rest: runtime, authorization, secret management, access management, audit logs, and other vital features. | ||
Also, you can find a lot of ready-to-use plugins from our community. | ||
|
||
Learn more about Connery: | ||
|
||
- GitHub repository: https://github.com/connery-io/connery-platform | ||
- Documentation: https://docs.connery.io | ||
|
||
## Usage | ||
|
||
This example shows how to create an agent with Connery actions using the Connery Actions Toolkit. | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
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,25 @@ | ||
import CodeBlock from "@theme/CodeBlock"; | ||
import Example from "@examples/tools/connery.ts"; | ||
|
||
# Connery Actions Tool | ||
|
||
Using this tool, you can integrate individual Connery actions into your LangChain agents and chains. | ||
|
||
## What is Connery? | ||
|
||
Connery is an open-source plugin infrastructure for AI. | ||
|
||
With Connery, you can easily create a custom plugin, which is essentially a set of actions, and use them in your LangChain agents and chains. | ||
Connery will handle the rest: runtime, authorization, secret management, access management, audit logs, and other vital features. | ||
Also, you can find a lot of ready-to-use plugins from our community. | ||
|
||
Learn more about Connery: | ||
|
||
- GitHub repository: https://github.com/connery-io/connery-platform | ||
- Documentation: https://docs.connery.io | ||
|
||
## Usage | ||
|
||
This example shows how to create a tool for one specific Connery action and call it. | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
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,27 @@ | ||
--- | ||
hide_table_of_contents: true | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# Gmail Tool | ||
|
||
The Gmail Tool allows your agent to create and view messages from a linked email account. | ||
|
||
## Setup | ||
|
||
You will need to get an API key from [Google here](https://developers.google.com/gmail/api/guides) | ||
and [enable the new Gmail API](https://console.cloud.google.com/apis/library/gmail.googleapis.com). | ||
Then, set the environment variables for `GMAIL_CLIENT_EMAIL`, and either `GMAIL_PRIVATE_KEY`, or `GMAIL_KEYFILE`. | ||
|
||
To use the Gmail Tool you need to install the following official peer dependency: | ||
|
||
```bash npm2yarn | ||
npm install googleapis | ||
``` | ||
|
||
## Usage | ||
|
||
import ToolExample from "@examples/tools/gmail.ts"; | ||
|
||
<CodeBlock language="typescript">{ToolExample}</CodeBlock> |
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
5 changes: 5 additions & 0 deletions
5
docs/core_docs/docs/modules/agents/agent_types/structured_chat.mdx
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,15 @@ | ||
import CodeBlock from "@theme/CodeBlock"; | ||
import StreamingExample from "@examples/agents/stream.ts"; | ||
|
||
# Streaming | ||
|
||
Agents have the ability to stream iterations and actions back while they're still working. | ||
This can be very useful for any realtime application where you have users who need insights on the agent's progress while is has yet to finish. | ||
|
||
Setting up streaming with agents is very simple, even with existing agents. The only change required is switching your `executor.invoke({})` to be `executor.stream({})`. | ||
|
||
Below is a simple example of streaming with an agent. | ||
|
||
You can find the [LangSmith](https://smith.langchain.com/) trace for this example by clicking [here](https://smith.langchain.com/public/08978fa7-bb99-427b-850e-35773cae1453/r). | ||
|
||
<CodeBlock language="typescript">{StreamingExample}</CodeBlock> |
19 changes: 19 additions & 0 deletions
19
docs/core_docs/docs/modules/callbacks/how_to/with_listeners.mdx
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,19 @@ | ||
import CodeBlock from "@theme/CodeBlock"; | ||
import Example from "@examples/guides/expression_language/with_listeners.ts"; | ||
|
||
# Listeners | ||
|
||
LangChain callbacks offer a method `withListeners` which allow you to add event listeners to the following events: | ||
|
||
- `onStart` - called when the chain starts | ||
- `onEnd` - called when the chain ends | ||
- `onError` - called when an error occurs | ||
|
||
These methods accept a callback function which will be called when the event occurs. The callback function can accept two arguments: | ||
|
||
- `input` - the input value, for example it would be `RunInput` if used with a Runnable. | ||
- `config` - an optional config object. This can contain metadata, callbacks or any other values passed in as a config object when the chain is started. | ||
|
||
Below is an example which demonstrates how to use the `withListeners` method: | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
Oops, something went wrong.