Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed May 2, 2024
2 parents 015e3c9 + 3a79ec0 commit 038998a
Show file tree
Hide file tree
Showing 46 changed files with 2,107 additions and 250 deletions.
383 changes: 224 additions & 159 deletions docs/core_docs/data/people.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ sidebar_label: Cloudflare Workers AI

# ChatCloudflareWorkersAI

:::info
Workers AI is currently in Open Beta and is not recommended for production data and traffic, and limits + access are subject to change
:::

Workers AI allows you to run machine learning models, on the Cloudflare network, from your own code.

## Usage
Expand Down
38 changes: 31 additions & 7 deletions docs/core_docs/docs/integrations/chat_memory/zep_memory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,39 @@ hide_table_of_contents: true

# Zep Memory

[Zep](https://github.com/getzep/zep) is a memory server that stores, summarizes, embeds, indexes, and enriches conversational AI chat histories, autonomous agent histories, document Q&A histories and exposes them via simple, low-latency APIs.
> Recall, understand, and extract data from chat histories. Power personalized AI experiences.
Key Features:
> [Zep](https://www.getzep.com) is a long-term memory service for AI Assistant apps.
> With Zep, you can provide AI assistants with the ability to recall past conversations, no matter how distant,
> while also reducing hallucinations, latency, and cost.
- Long-term memory persistence, with access to historical messages irrespective of your summarization strategy.
- Auto-summarization of memory messages based on a configurable message window. A series of summaries are stored, providing flexibility for future summarization strategies.
- Vector search over memories, with messages automatically embedded on creation.
- Auto-token counting of memories and summaries, allowing finer-grained control over prompt assembly.
- [Python](https://github.com/getzep/zep-python) and [JavaScript](https://github.com/getzep/zep-js) SDKs.
## How Zep works

Zep persists and recalls chat histories, and automatically generates summaries and other artifacts from these chat histories.
It also embeds messages and summaries, enabling you to search Zep for relevant context from past conversations.
Zep does all of this asynchronously, ensuring these operations don't impact your user's chat experience.
Data is persisted to database, allowing you to scale out when growth demands.

Zep also provides a simple, easy to use abstraction for document vector search called Document Collections.
This is designed to complement Zep's core memory features, but is not designed to be a general purpose vector database.

Zep allows you to be more intentional about constructing your prompt:

- automatically adding a few recent messages, with the number customized for your app;
- a summary of recent conversations prior to the messages above;
- and/or contextually relevant summaries or messages surfaced from the entire chat session.
- and/or relevant Business data from Zep Document Collections.

## What is Zep Cloud?

[Zep Cloud](http://www.getzep.com) is a managed service with Zep Open Source at its core.
In addition to Zep Open Source's memory management features, Zep Cloud offers:

- **Fact Extraction**: Automatically build fact tables from conversations, without having to define a data schema upfront.
- **Dialog Classification**: Instantly and accurately classify chat dialog. Understand user intent and emotion, segment users, and more. Route chains based on semantic context, and trigger events.
- **Structured Data Extraction**: Quickly extract business data from chat conversations using a schema you define. Understand what your Assistant should ask for next in order to complete its task.

> Interested in Zep Cloud? See [Zep Cloud Installation Guide](https://help.getzep.com/sdks), [Zep Cloud Message History Example](https://help.getzep.com/langchain/examples/messagehistory-example)
## Setup

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Browserbase Loader

## Description

[Browserbase](https://browserbase.com) is a serverless platform for running headless browsers, it offers advanced debugging, session recordings, stealth mode, integrated proxies and captcha solving.

## Installation

- Get an API key from [browserbase.com](https://browserbase.com) and set it in environment variables (`BROWSERBASE_API_KEY`).
- Install the [Browserbase SDK](http://github.com/browserbase/js-sdk):

```bash npm2yarn
npm i @browserbasehq/sdk
```

## Example

Utilize the `BrowserbaseLoader` as follows to allow your agent to load websites:

import CodeBlock from "@theme/CodeBlock";
import Example from "@examples/document_loaders/browserbase.ts";

<CodeBlock language="typescript">{Example}</CodeBlock>

## Arguments

- `urls`: Required. List of URLs to load.

## Options

- `api_key`: Optional. Specifies Browserbase API key. Defaults is the `BROWSERBASE_API_KEY` environment variable.
- `text_content`: Optional. Load pages as readable text. Default is `False`.
6 changes: 6 additions & 0 deletions docs/core_docs/docs/integrations/retrievers/zep-retriever.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ hide_table_of_contents: true

# Zep Retriever

> [Zep](https://www.getzep.com) is a long-term memory service for AI Assistant apps.
> With Zep, you can provide AI assistants with the ability to recall past conversations, no matter how distant,
> while also reducing hallucinations, latency, and cost.
> Interested in Zep Cloud? See [Zep Cloud Installation Guide](https://help.getzep.com/sdks), [Zep Cloud Retriever Example](https://help.getzep.com/langchain/examples/rag-message-history-example)
This example shows how to use the Zep Retriever in a retrieval chain to retrieve documents from Zep memory store.

## Setup
Expand Down
9 changes: 6 additions & 3 deletions docs/core_docs/docs/integrations/vectorstores/zep.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Zep

import CodeBlock from "@theme/CodeBlock";
> [Zep](https://www.getzep.com) is a long-term memory service for AI Assistant apps.
> With Zep, you can provide AI assistants with the ability to recall past conversations, no matter how distant,
> while also reducing hallucinations, latency, and cost.
> Interested in Zep Cloud? See [Zep Cloud Installation Guide](https://help.getzep.com/sdks), [Zep Cloud Vector Store Example](https://help.getzep.com/langchain/examples/vectorstore-example)
Zep is an open source long-term memory store for LLM applications. Zep makes it easy to add relevant documents,
chat history memory & rich user data to your LLM app's prompts.
import CodeBlock from "@theme/CodeBlock";

**Note:** The `ZepVectorStore` works with `Documents` and is intended to be used as a `Retriever`.
It offers separate functionality to Zep's `ZepMemory` class, which is designed for persisting, enriching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const docs = await textSplitter.createDocuments([text]);
const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings());

// Initialize a retriever wrapper around the vector store
const vectorStoreRetriever = vectorStore.asRetriever();
const retriever = vectorStore.asRetriever();

const docs = await retriever.getRelevantDocuments(
"what did he say about ketanji brown jackson"
Expand Down
6 changes: 6 additions & 0 deletions examples/src/document_loaders/browserbase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BrowserbaseLoader } from "langchain/document_loaders/web/browserbase";

const loader = new BrowserbaseLoader(["https://example.com"], {
textContent: true,
});
const docs = await loader.load();
2 changes: 1 addition & 1 deletion langchain-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/core",
"version": "0.1.60",
"version": "0.1.61",
"description": "Core LangChain.js abstractions and schemas",
"type": "module",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions langchain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ document_loaders/web/azure_blob_storage_file.cjs
document_loaders/web/azure_blob_storage_file.js
document_loaders/web/azure_blob_storage_file.d.ts
document_loaders/web/azure_blob_storage_file.d.cts
document_loaders/web/browserbase.cjs
document_loaders/web/browserbase.js
document_loaders/web/browserbase.d.ts
document_loaders/web/browserbase.d.cts
document_loaders/web/cheerio.cjs
document_loaders/web/cheerio.js
document_loaders/web/cheerio.d.ts
Expand Down
3 changes: 3 additions & 0 deletions langchain/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export const config = {
"document_loaders/web/azure_blob_storage_container",
"document_loaders/web/azure_blob_storage_file":
"document_loaders/web/azure_blob_storage_file",
"document_loaders/web/browserbase":
"document_loaders/web/browserbase",
"document_loaders/web/cheerio": "document_loaders/web/cheerio",
"document_loaders/web/puppeteer": "document_loaders/web/puppeteer",
"document_loaders/web/playwright": "document_loaders/web/playwright",
Expand Down Expand Up @@ -219,6 +221,7 @@ export const config = {
"document_loaders/web/assemblyai",
"document_loaders/web/azure_blob_storage_container",
"document_loaders/web/azure_blob_storage_file",
"document_loaders/web/browserbase",
"document_loaders/web/cheerio",
"document_loaders/web/puppeteer",
"document_loaders/web/playwright",
Expand Down
18 changes: 18 additions & 0 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@
"document_loaders/web/azure_blob_storage_file.js",
"document_loaders/web/azure_blob_storage_file.d.ts",
"document_loaders/web/azure_blob_storage_file.d.cts",
"document_loaders/web/browserbase.cjs",
"document_loaders/web/browserbase.js",
"document_loaders/web/browserbase.d.ts",
"document_loaders/web/browserbase.d.cts",
"document_loaders/web/cheerio.cjs",
"document_loaders/web/cheerio.js",
"document_loaders/web/cheerio.d.ts",
Expand Down Expand Up @@ -578,6 +582,7 @@
"@aws-sdk/credential-provider-node": "^3.388.0",
"@aws-sdk/types": "^3.357.0",
"@azure/storage-blob": "^12.15.0",
"@browserbasehq/sdk": "^1.0.0",
"@cloudflare/workers-types": "^4.20230922.0",
"@faker-js/faker": "^7.6.0",
"@gomomento/sdk": "^1.51.1",
Expand Down Expand Up @@ -665,6 +670,7 @@
"@aws-sdk/client-sfn": "^3.310.0",
"@aws-sdk/credential-provider-node": "^3.388.0",
"@azure/storage-blob": "^12.15.0",
"@browserbasehq/sdk": "*",
"@gomomento/sdk": "^1.51.1",
"@gomomento/sdk-core": "^1.51.1",
"@gomomento/sdk-web": "^1.51.1",
Expand Down Expand Up @@ -726,6 +732,9 @@
"@azure/storage-blob": {
"optional": true
},
"@browserbasehq/sdk": {
"optional": true
},
"@gomomento/sdk": {
"optional": true
},
Expand Down Expand Up @@ -1285,6 +1294,15 @@
"import": "./document_loaders/web/azure_blob_storage_file.js",
"require": "./document_loaders/web/azure_blob_storage_file.cjs"
},
"./document_loaders/web/browserbase": {
"types": {
"import": "./document_loaders/web/browserbase.d.ts",
"require": "./document_loaders/web/browserbase.d.cts",
"default": "./document_loaders/web/browserbase.d.ts"
},
"import": "./document_loaders/web/browserbase.js",
"require": "./document_loaders/web/browserbase.cjs"
},
"./document_loaders/web/cheerio": {
"types": {
"import": "./document_loaders/web/cheerio.d.ts",
Expand Down
82 changes: 82 additions & 0 deletions langchain/src/document_loaders/web/browserbase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Document, type DocumentInterface } from "@langchain/core/documents";
import Browserbase, { BrowserbaseLoadOptions } from "@browserbasehq/sdk";
import { BaseDocumentLoader } from "../base.js";
import type { DocumentLoader } from "../base.js";

interface BrowserbaseLoaderOptions extends BrowserbaseLoadOptions {
apiKey?: string;
}

/**
* Load pre-rendered web pages using a headless browser hosted on Browserbase.
*
* Depends on `@browserbasehq/sdk` package.
* Get your API key from https://browserbase.com
*
* @example
* ```typescript
* import { BrowserbaseLoader } from "langchain/document_loaders/web/browserbase";
*
* const loader = new BrowserbaseLoader(["https://example.com"], {
* apiKey: process.env.BROWSERBASE_API_KEY,
* textContent: true,
* });
*
* const docs = await loader.load();
* ```
*
* @param {string[]} urls - The URLs of the web pages to load.
* @param {BrowserbaseLoaderOptions} [options] - Browserbase client options.
*/
export class BrowserbaseLoader
extends BaseDocumentLoader
implements DocumentLoader
{
urls: string[];

options: BrowserbaseLoaderOptions;

browserbase: Browserbase;

constructor(urls: string[], options: BrowserbaseLoaderOptions = {}) {
super();
this.urls = urls;
this.options = options;
this.browserbase = new Browserbase(options.apiKey);
}

/**
* Load pages from URLs.
*
* @returns {Promise<DocumentInterface[]>} - A promise which resolves to a list of documents.
*/
async load(): Promise<DocumentInterface[]> {
const documents: DocumentInterface[] = [];
for await (const doc of this.lazyLoad()) {
documents.push(doc);
}

return documents;
}

/**
* Load pages from URLs.
*
* @returns {Generator<DocumentInterface>} - A generator that yields documents.
*/
async *lazyLoad() {
const pages = await this.browserbase.loadURLs(this.urls, this.options);

let index = 0;
for await (const page of pages) {
yield new Document({
pageContent: page,
metadata: {
url: this.urls[index],
},
});

index += index + 1;
}
}
}
4 changes: 2 additions & 2 deletions langchain/src/document_loaders/web/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ export class S3Loader extends BaseDocumentLoader {
const docs = await unstructuredLoader.load();

return docs;
} catch {
} catch (e: any) {
throw new Error(
`Failed to load file ${filePath} using unstructured loader.`
`Failed to load file ${filePath} using unstructured loader: ${e.message}`
);
}
}
Expand Down
1 change: 1 addition & 0 deletions langchain/src/load/import_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const optionalImportEntrypoints: string[] = [
"langchain/document_loaders/web/assemblyai",
"langchain/document_loaders/web/azure_blob_storage_container",
"langchain/document_loaders/web/azure_blob_storage_file",
"langchain/document_loaders/web/browserbase",
"langchain/document_loaders/web/cheerio",
"langchain/document_loaders/web/puppeteer",
"langchain/document_loaders/web/playwright",
Expand Down
12 changes: 8 additions & 4 deletions langchain/src/smith/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export type EvaluatorInputFormatter = ({
run: Run;
}) => EvaluatorInputs;

export type DynamicRunEvaluatorParams = {
input: Record<string, unknown>;
prediction?: Record<string, unknown>;
reference?: Record<string, unknown>;
export type DynamicRunEvaluatorParams<
Input extends Record<string, any> = Record<string, unknown>,
Prediction extends Record<string, any> = Record<string, unknown>,
Reference extends Record<string, any> = Record<string, unknown>
> = {
input: Input;
prediction?: Prediction;
reference?: Reference;
run: Run;
example?: Example;
};
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-azure-openai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/azure-openai",
"version": "0.0.7",
"version": "0.0.8",
"description": "Azure SDK for OpenAI integrations for LangChain.js",
"type": "module",
"engines": {
Expand Down
10 changes: 5 additions & 5 deletions libs/langchain-azure-openai/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ export class AzureOpenAIEmbeddings

const batchRequests = batches.map((batch) => this.getEmbeddings(batch));
const embeddings = await Promise.all(batchRequests);

return embeddings;
return embeddings.flat();
}

async embedQuery(document: string): Promise<number[]> {
const input = [
this.stripNewLines ? document.replace(/\n/g, " ") : document,
];
return this.getEmbeddings(input);
const embeddings = await this.getEmbeddings(input);
return embeddings.flat();
}

private async getEmbeddings(input: string[]) {
private async getEmbeddings(input: string[]): Promise<number[][]> {
const deploymentName = this.azureOpenAIApiDeploymentName || this.model;

const res = await this.caller.call(() =>
Expand All @@ -159,6 +159,6 @@ export class AzureOpenAIEmbeddings
})
);

return res.data[0].embedding;
return res.data.map((data) => data.embedding);
}
}
Loading

0 comments on commit 038998a

Please sign in to comment.