id stringlengths 6 6 | text stringlengths 20 17.2k | title stringclasses 1
value |
|---|---|---|
145588 | {
"cells": [
{
"cell_type": "raw",
"id": "38831021-76ed-48b3-9f62-d1241a68b6ad",
"metadata": {},
"source": [
"---\n",
"sidebar_position: 3\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "a745f98b-c495-44f6-a882-757c38992d76",
"metadata": {},
"source": [
"# How to use o... | |
145593 | "{ query: \u001b[32m\"books about aliens\"\u001b[39m, author: \u001b[32m\"jess knight\"\u001b[39m }"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"await queryAnalyzer.invoke(\"what are books ab... | |
145596 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How to stream from a question-answering chain\n",
"\n",
":::info Prerequisites\n",
"\n",
"This guide assumes familiarity with the following:\n",
"\n",
"- [Retrieval-augm... | |
145622 | {
"cells": [
{
"cell_type": "raw",
"id": "afaf8039",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Azure OpenAI\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "9a3d6f34",
"metadata": {},
"source": [
"# AzureOpen... | |
145678 | {
"cells": [
{
"cell_type": "raw",
"id": "afaf8039",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: HNSWLib\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "e49f1e0d",
"metadata": {},
"source": [
"# HNSWLib\n",
... | |
145700 | ---
keywords: [azure]
---
import CodeBlock from "@theme/CodeBlock";
# Microsoft
All functionality related to `Microsoft Azure` and other `Microsoft` products.
## Chat Models
### Azure OpenAI
See a [usage example](/docs/integrations/chat/azure)
import AzureChatOpenAI from "@examples/models/chat/integration_azure_... | |
145789 | {
"cells": [
{
"cell_type": "raw",
"id": "afaf8039",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Azure OpenAI\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "e49f1e0d",
"metadata": {},
"source": [
"# AzureChat... | |
145790 | "}\n"
]
}
],
"source": [
"const aiMsg = await llm.invoke([\n",
" [\n",
" \"system\",\n",
" \"You are a helpful assistant that translates English to French. Translate the user sentence.\",\n",
" ],\n",
" [\"human\", \"I love programming.\"],\n",
"])\n",
... | |
145791 | "cell_type": "markdown",
"id": "0ac0310c",
"metadata": {},
"source": [
"## Migration from Azure OpenAI SDK\n",
"\n",
"If you are using the deprecated Azure OpenAI SDK with the `@langchain/azure-openai` package, you can update your code to use the new Azure integration following these steps:\n",
... | |
145817 | "This property returns a list of \\`ToolCall\\`s. A \\`ToolCall\\` is an object with the following arguments:\n",
"\n",
"- \\`name\\`: The name of the tool that should be called.\n",
"- \\`args\\`: The arguments to that tool.\n",
"- \\`id\\`: The id of that tool call.\n",
"\n",
"#### SystemMessa... | |
145823 | "Generally, such models are better at tool calling than non-fine-tuned models, and are recommended for use cases that require tool calling.\n",
"Please see the [tool calling section](/docs/concepts/#functiontool-calling) for more information.\n",
":::\n",
"\n",
"For specifics on how to use chat models, ... | |
145856 | {
"cells": [
{
"cell_type": "raw",
"id": "1957f5cb",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Chroma\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "ef1f0986",
"metadata": {},
"source": [
"# Chroma\n",
... | |
145860 | {
"cells": [
{
"cell_type": "raw",
"id": "1957f5cb",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: HNSWLib\n",
"sidebar_class_name: node-only\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "ef1f0986",
"metadata": {... | |
145871 | # Typesense
Vector store that utilizes the Typesense search engine.
### Basic Usage
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";
<IntegrationInstallTooltip></IntegrationInstallTooltip>
```bash npm2yarn
npm install @langchain/openai @langchain/community @langchain/core
``... | |
145877 | ---
sidebar_class_name: node-only
---
import CodeBlock from "@theme/CodeBlock";
# Tigris
Tigris makes it easy to build AI applications with vector embeddings.
It is a fully managed cloud-native database that allows you store and
index documents and vector embeddings for fast and scalable vector search.
:::tip Compa... | |
145882 | # libSQL
[Turso](https://turso.tech) is a SQLite-compatible database built on [libSQL](https://docs.turso.tech/libsql), the Open Contribution fork of SQLite. Vector Similiarity Search is built into Turso and libSQL as a native datatype, enabling you to store and query vectors directly in the database.
LangChain.js su... | |
145892 | " pageContent: \"The powerhouse of the cell is the mitochondria\",\n",
" metadata: { source: \"https://example.com\" }\n",
"};\n",
"\n",
"const document2: Document = {\n",
" pageContent: \"Buildings are made out of brick\",\n",
" metadata: { source: \"https://example.com\" }\n",
"};\n",
... | |
145901 | You can specify the fields to return from the document using `fields` parameter in the filter during searches.
These fields are returned as part of the `metadata` object. You can fetch any field that is stored in the index.
The `textKey` of the document is returned as part of the document's `pageContent`.
If you do no... | |
145902 | {
"cells": [
{
"cell_type": "raw",
"id": "1957f5cb",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: MongoDB Atlas\n",
"sidebar_class_name: node-only\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "ef1f0986",
"metada... | |
145903 | "\n",
"You can now add documents to your vector store:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "17f5efc0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ '1', '2', '3', '4' ]\n"
]
}
],
"source": [
... | |
145906 | {
"cells": [
{
"cell_type": "raw",
"id": "1957f5cb",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Faiss\n",
"sidebar_class_name: node-only\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "ef1f0986",
"metadata": {},... | |
145910 | {
"cells": [
{
"cell_type": "raw",
"id": "1957f5cb",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Pinecone\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "ef1f0986",
"metadata": {},
"source": [
"# PineconeStore... | |
145913 | " pageContent: \"Buildings are made out of brick\",\n",
" metadata: { source: \"https://example.com\" }\n",
"};\n",
"\n",
"const document3: Document = {\n",
" pageContent: \"Mitochondria are made out of lipids\",\n",
" metadata: { source: \"https://example.com\" }\n",
"};\n",
"\n",
... | |
145925 | ---
hide_table_of_contents: true
---
# JSONLines files
This example goes over how to load data from JSONLines or JSONL files. The second argument is a JSONPointer to the property to extract from each JSON object in the file. One document will be created for each JSON object in the file.
Example JSONLines file:
```j... | |
145926 | # JSON files
The JSON loader use [JSON pointer](https://github.com/janl/node-jsonpointer) to target keys in your JSON files you want to target.
### No JSON pointer example
The most simple way of using it, is to specify no JSON pointer.
The loader will load all strings it finds in the JSON object.
Example JSON file:... | |
145931 | " {\n",
" \".pdf\": (path: string) => new PDFLoader(path),\n",
" }\n",
");\n",
"\n",
"const directoryDocs = await directoryLoader.load();\n",
"\n",
"console.log(directoryDocs[0]);\n",
"\n",
"/* Additional steps : Split text into chunks with any TextSplitter. You can then use it ... | |
146002 | ---
sidebar_class_name: hidden
---
# PromptLayer OpenAI
:::warning
This module has been deprecated and is no longer supported. The documentation below will not work in versions 0.2.0 or later.
:::
LangChain integrates with PromptLayer for logging and debugging prompts and responses. To add support for PromptLayer:
... | |
146003 | {
"cells": [
{
"cell_type": "raw",
"id": "67db2992",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_label: Azure OpenAI\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "9597802c",
"metadata": {},
"source": [
"# AzureOpen... | |
146019 | ---
sidebar_class_name: node-only
---
# Llama CPP
:::tip Compatibility
Only available on Node.js.
:::
This module is based on the [node-llama-cpp](https://github.com/withcatai/node-llama-cpp) Node.js bindings for [llama.cpp](https://github.com/ggerganov/llama.cpp), allowing you to work with a locally running LLM. Th... | |
146023 | {
"cells": [
{
"cell_type": "raw",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"keywords: [pdf, document loader]\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Build a PDF ingestion and Question/Answering s... | |
146025 | "import { createRetrievalChain } from \"langchain/chains/retrieval\";\n",
"import { createStuffDocumentsChain } from \"langchain/chains/combine_documents\";\n",
"import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n",
"\n",
"const systemTemplate = [\n",
" `You are an assistant for quest... | |
146027 | "My satire is more than just a joke, it's a call to action, and I've got the power\n",
"I'm the one who's really making a difference, and you're just a fleeting flower.\n",
"\n",
"[The crowd continues to cheer and chant as the two comedians continue their rap battle.]\n"
]
... | |
146042 | " [\"human\", \"{input}\"],\n",
"]);\n",
"\n",
"const questionAnswerChain = await createStuffDocumentsChain({\n",
" llm,\n",
" prompt,\n",
"});\n",
"\n",
"const ragChain = await createRetrievalChain({\n",
" retriever,\n",
" combineDocsChain: questionAnswerChain,\n",
"});... | |
146045 | "{ answer: ' using' }\n",
"----\n",
"{ answer: ' task' }\n",
"----\n",
"{ answer: '-specific' }\n",
"----\n",
"{ answer: ' instructions' }\n",
"----\n",
"{ answer: '.' }\n",
"----\n",
"{ answer: '' }\n",
"----\n",
"{ answer: '' }\n",
"----\n"... | |
146054 | {
"cells": [
{
"cell_type": "raw",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"sidebar_position: 1\n",
"keywords: [conversationchain]\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Build a Chatbot\n",
... | |
146055 | " \"usage_metadata\": {\n",
" \"input_tokens\": 10,\n",
" \"output_tokens\": 39,\n",
" \"total_tokens\": 49\n",
" }\n",
"}\n"
]
}
],
"source": [
"await llm.invoke([{ role: \"user\", content: \"Whats my name\" }])"
]
},
{
"cell_type": "markdown",
"... | |
146060 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Build a Retrieval Augmented Generation (RAG) App\n",
"\n",
"One of the most powerful applications enabled by LLMs is sophisticated question-answering (Q&A) chatbots. These are applications that can ans... | |
146062 | "Building agents with LLM (large language model) as its core controller is a cool concept. Several proof-of-concepts demos, such as AutoGPT, GPT-Engineer and BabyAGI, serve as inspiring examples. The potentiality of LLM extends beyond generating well-written copies, stories, essays and programs; it can be framed as a p... | |
146063 | A standard practice is to save the embedding representation of information into a vector store database that can support fast maximum inner-product search (MIPS). To optimize the retrieval speed, the common choice is the approximate nearest neighbors (ANN) algorithm to return approximately top k nearest neighbors to t... | |
146064 | "System message:Think step by step and reason yourself to the right decisions to make sure we get it right.\n",
"You will first lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose.Then you will output the content of each file includin... | |
146065 | "console.log(allSplits[0].pageContent.length);"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" source: 'https://lilianweng... | |
146068 | # Build a Question/Answering system over SQL data
:::info Prerequisites
This guide assumes familiarity with the following concepts:
- [Chaining runnables](/docs/how_to/sequence/)
- [Chat models](/docs/concepts/#chat-models)
- [Tools](/docs/concepts/#tools)
- [Agents](/docs/concepts/#agents)
:::
In this guide we'll... | |
146500 | import type * as tiktoken from "js-tiktoken";
import { Document, BaseDocumentTransformer } from "@langchain/core/documents";
import { getEncoding } from "@langchain/core/utils/tiktoken";
export interface TextSplitterParams {
chunkSize: number;
chunkOverlap: number;
keepSeparator: boolean;
lengthFunction?:
... | |
146501 | export class RecursiveCharacterTextSplitter
extends TextSplitter
implements RecursiveCharacterTextSplitterParams
{
static lc_name() {
return "RecursiveCharacterTextSplitter";
}
separators: string[] = ["\n\n", "\n", " ", ""];
constructor(fields?: Partial<RecursiveCharacterTextSplitterParams>) {
sup... | |
146506 | import { describe, expect, test } from "@jest/globals";
import { Document } from "@langchain/core/documents";
import {
CharacterTextSplitter,
LatexTextSplitter,
MarkdownTextSplitter,
RecursiveCharacterTextSplitter,
TokenTextSplitter,
} from "../text_splitter.js";
function textLineGenerator(char: string, leng... | |
146548 | // eslint-disable-next-line import/no-extraneous-dependencies
import { loadPyodide, type PyodideInterface } from "pyodide";
import { Tool, ToolParams } from "@langchain/core/tools";
export type PythonInterpreterToolParams = Parameters<typeof loadPyodide>[0] &
ToolParams & {
instance: PyodideInterface;
};
expo... | |
146556 | import { TextServiceClient, protos } from "@google-ai/generativelanguage";
import { GoogleAuth } from "google-auth-library";
import { type BaseLLMParams, LLM } from "@langchain/core/language_models/llms";
import { getEnvironmentVariable } from "@langchain/core/utils/env";
/**
* @deprecated - Deprecated by Google. Wil... | |
146566 | import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";
import { BaseLanguageModel } from "@langchain/core/language_models/base";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { Document } from "@langchain/core/documents";
import {
Node,
Relationship,
GraphDocument,
}... | |
146587 | import { test } from "@jest/globals";
import { Document } from "@langchain/core/documents";
import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";
import { AttributeInfo } from "langchain/chains/query_constructor";
import {
FunctionalTranslator,
SelfQueryRetriever,
} from "langchain/retrievers/self_query";
i... | |
146589 | import Metal from "@getmetal/metal-sdk";
import { BaseRetriever, BaseRetrieverInput } from "@langchain/core/retrievers";
import { Document } from "@langchain/core/documents";
/**
* Interface for the fields required during the initialization of a
* `MetalRetriever` instance. It extends the `BaseRetrieverInput`
* in... | |
146593 | import {
MemorySearchPayload,
MemorySearchResult,
NotFoundError,
ZepClient,
} from "@getzep/zep-js";
import { BaseRetriever, BaseRetrieverInput } from "@langchain/core/retrievers";
import { Document } from "@langchain/core/documents";
/**
* Configuration interface for the ZepRetriever class. Extends the
* Ba... | |
146595 | import {
BaseRetriever,
type BaseRetrieverInput,
} from "@langchain/core/retrievers";
import { Document } from "@langchain/core/documents";
import {
AsyncCaller,
AsyncCallerParams,
} from "@langchain/core/utils/async_caller";
/**
* Interface for the arguments required to create a new instance of
* DataberryR... | |
146596 | import {
BaseRetriever,
type BaseRetrieverInput,
} from "@langchain/core/retrievers";
import { Document } from "@langchain/core/documents";
import {
AsyncCaller,
type AsyncCallerParams,
} from "@langchain/core/utils/async_caller";
export interface ChaindeskRetrieverArgs
extends AsyncCallerParams,
BaseRet... | |
146600 | import { ZepClient } from "@getzep/zep-cloud";
import {
SearchScope,
SearchType,
MemorySearchResult,
NotFoundError,
} from "@getzep/zep-cloud/api";
import { BaseRetriever, BaseRetrieverInput } from "@langchain/core/retrievers";
import { Document } from "@langchain/core/documents";
/**
* Configuration interfac... | |
146611 | import {
BaseRetriever,
type BaseRetrieverInput,
} from "@langchain/core/retrievers";
import {
AsyncCaller,
type AsyncCallerParams,
} from "@langchain/core/utils/async_caller";
import type { DocumentInterface } from "@langchain/core/documents";
/**
* Type for the authentication method used by the RemoteRetrie... | |
146765 | import { Zep, ZepClient } from "@getzep/zep-cloud";
import { Memory, NotFoundError } from "@getzep/zep-cloud/api";
import {
InputValues,
OutputValues,
MemoryVariables,
getInputValue,
getOutputValue,
} from "@langchain/core/memory";
import {
AIMessage,
BaseMessage,
ChatMessage,
getBufferString,
Human... | |
146837 | import { test } from "@jest/globals";
import * as fs from "node:fs/promises";
import { fileURLToPath } from "node:url";
import * as path from "node:path";
import { AIMessage, HumanMessage } from "@langchain/core/messages";
import { PromptTemplate } from "@langchain/core/prompts";
import {
BytesOutputParser,
StringO... | |
146888 | import { Storage, File } from "@google-cloud/storage";
import { Document } from "@langchain/core/documents";
import { Docstore } from "langchain/stores/doc/base";
/**
* Interface that defines the configuration for the
* GoogleCloudStorageDocstore. It includes the bucket name and an optional
* prefix.
*/
export in... | |
146962 | function isVersionLessThan(v1: number[], v2: number[]): boolean {
for (let i = 0; i < Math.min(v1.length, v2.length); i += 1) {
if (v1[i] < v2[i]) {
return true;
} else if (v1[i] > v2[i]) {
return false;
}
}
// If all the corresponding parts are equal, the shorter version is less
return ... | |
146963 | import * as uuid from "uuid";
import type {
ChromaClient as ChromaClientT,
Collection,
ChromaClientParams,
CollectionMetadata,
Where,
} from "chromadb";
import type { EmbeddingsInterface } from "@langchain/core/embeddings";
import { VectorStore } from "@langchain/core/vectorstores";
import { Document } from ... | |
146964 | export class Chroma extends VectorStore {
declare FilterType: Where;
index?: ChromaClientT;
collection?: Collection;
collectionName: string;
collectionMetadata?: CollectionMetadata;
numDimensions?: number;
clientParams?: Omit<ChromaClientParams, "path">;
url: string;
filter?: object;
_vecto... | |
146965 | static async fromTexts(
texts: string[],
metadatas: object[] | object,
embeddings: EmbeddingsInterface,
dbConfig: ChromaLibArgs
): Promise<Chroma> {
const docs: Document[] = [];
for (let i = 0; i < texts.length; i += 1) {
const metadata = Array.isArray(metadatas) ? metadatas[i] : metadat... | |
146966 | import type {
HierarchicalNSW as HierarchicalNSWT,
SpaceName,
} from "hnswlib-node";
import type { EmbeddingsInterface } from "@langchain/core/embeddings";
import { SaveableVectorStore } from "@langchain/core/vectorstores";
import { Document } from "@langchain/core/documents";
import { SynchronousInMemoryDocstore }... | |
146967 | export class HNSWLib extends SaveableVectorStore {
declare FilterType: (doc: Document) => boolean;
_index?: HierarchicalNSWT;
docstore: SynchronousInMemoryDocstore;
args: HNSWLibBase;
_vectorstoreType(): string {
return "hnswlib";
}
constructor(embeddings: EmbeddingsInterface, args: HNSWLibArgs) ... | |
146968 | static async load(directory: string, embeddings: EmbeddingsInterface) {
const fs = await import("node:fs/promises");
const path = await import("node:path");
const args = JSON.parse(
await fs.readFile(path.join(directory, "args.json"), "utf8")
);
const index = await HNSWLib.getHierarchicalNSW(a... | |
146999 | export class MongoDBAtlasVectorSearch extends VectorStore {
declare FilterType: MongoDBAtlasFilter;
private readonly collection: Collection<MongoDBDocument>;
private readonly indexName: string;
private readonly textKey: string;
private readonly embeddingKey: string;
private readonly primaryKey: string;... | |
147007 | import * as uuid from "uuid";
import type { EmbeddingsInterface } from "@langchain/core/embeddings";
import { VectorStore } from "@langchain/core/vectorstores";
import { Document } from "@langchain/core/documents";
/**
* Type definition for the arguments required to initialize a
* TigrisVectorStore instance.
*/
ex... | |
147011 | protected async createSearchIndexDefinition(
indexName: string
): Promise<SearchIndex> {
// Embed a test query to get the embedding dimensions
const testEmbedding = await this.embeddings.embedQuery("test");
const embeddingDimensions = testEmbedding.length;
return {
name: indexName,
vec... | |
147018 | export class PineconeStore extends VectorStore {
declare FilterType: PineconeMetadata;
textKey: string;
namespace?: string;
pineconeIndex: PineconeIndex;
filter?: PineconeMetadata;
caller: AsyncCaller;
_vectorstoreType(): string {
return "pinecone";
}
constructor(embeddings: EmbeddingsInter... | |
147039 | export class Milvus extends VectorStore {
get lc_secrets(): { [key: string]: string } {
return {
ssl: "MILVUS_SSL",
username: "MILVUS_USERNAME",
password: "MILVUS_PASSWORD",
};
}
_vectorstoreType(): string {
return "milvus";
}
declare FilterType: string;
collectionName: stri... | |
147041 | static async fromTexts(
texts: string[],
metadatas: object[] | object,
embeddings: EmbeddingsInterface,
dbConfig?: MilvusLibArgs
): Promise<Milvus> {
const docs: Document[] = [];
for (let i = 0; i < texts.length; i += 1) {
const metadata = Array.isArray(metadatas) ? metadatas[i] : metada... | |
147045 | export class ElasticVectorSearch extends VectorStore {
declare FilterType: ElasticFilter;
private readonly client: Client;
private readonly indexName: string;
private readonly engine: ElasticKnnEngine;
private readonly similarity: ElasticSimilarity;
private readonly efConstruction: number;
private r... | |
147056 | import { test, expect } from "@jest/globals";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import * as os from "node:os";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";
import { HNSWLib } from "../hnswlib.js";
test("Test HNSWL... | |
147068 | /* eslint-disable no-process-env */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { beforeEach, describe, expect, test } from "@jest/globals";
import { ChromaClient } from "chromadb";
import { faker } from "@faker-js/faker";
import * as uuid from "uuid";
import { Document } from "@langchain/core/... | |
147089 | import { test, expect } from "@jest/globals";
import { Document } from "@langchain/core/documents";
import { OpenAIEmbeddings } from "@langchain/openai";
import { getEnvironmentVariable } from "@langchain/core/utils/env";
import { TurbopufferVectorStore } from "../turbopuffer.js";
beforeEach(async () => {
const emb... | |
147102 | import { Document } from "@langchain/core/documents";
interface Metadata {
name: string;
date: string;
count: number;
is_active: boolean;
tags: string[];
location: number[];
id: number;
height: number | null;
happiness: number | null;
sadness?: number;
}
const metadatas: Metadata[] = [
{
nam... | |
147106 | test.skip("Test metadata filters", async () => {
const url = process.env.NEO4J_URI as string;
const username = process.env.NEO4J_USERNAME as string;
const password = process.env.NEO4J_PASSWORD as string;
expect(url).toBeDefined();
expect(username).toBeDefined();
expect(password).toBeDefined();
... | |
147111 | /* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { Client, ClientOptions } from "@elastic/elasticsearch";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";
import { ElasticVectorSearch } from "../elasticsearch.js";
descri... | |
147125 | from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain_community.vectorstores import FAISS
from langchain_community.document_loaders import TextLoader
loader = TextLoader('../../../../../../examples/state_of_the_union.txt')
documents = loader.l... | |
147220 | import { test, expect } from "@jest/globals";
import * as url from "node:url";
import * as path from "node:path";
import { PDFLoader } from "../fs/pdf.js";
test("Test PDF loader from file", async () => {
const filePath = path.resolve(
path.dirname(url.fileURLToPath(import.meta.url)),
"./example_data/1706.037... | |
147270 | import { Document } from "@langchain/core/documents";
import { BufferLoader } from "langchain/document_loaders/fs/buffer";
/**
* A class that extends the `BufferLoader` class. It represents a document
* loader that loads documents from PDF files.
* @example
* ```typescript
* const loader = new PDFLoader("path/to/... | |
147317 | /* eslint-disable no-process-env */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect, test } from "@jest/globals";
import {
SageMakerEndpoint,
SageMakerLLMContentHandler,
} from "../sagemaker_endpoint.js";
// yarn test:single /{path_to}/langchain/src/llms/tests/sagemaker.int.test.ts
de... | |
147510 | const CACHED_TEXT = `## Components
LangChain provides standard, extendable interfaces and external integrations for various components useful for building with LLMs.
Some components LangChain implements, some components we rely on third-party integrations for, and others are a mix.
### Chat models
<span data-heading... | |
147724 | # @langchain/openai
This package contains the LangChain.js integrations for OpenAI through their SDK.
## Installation
```bash npm2yarn
npm install @langchain/openai @langchain/core
```
This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/).
If... | |
147732 | {
static lc_name() {
return "OpenAI";
}
get callKeys() {
return [...super.callKeys, "options"];
}
lc_serializable = true;
get lc_secrets(): { [key: string]: string } | undefined {
return {
openAIApiKey: "OPENAI_API_KEY",
apiKey: "OPENAI_API_KEY",
azureOpenAIApiKey: "AZURE_OP... | |
147735 | export class OpenAIEmbeddings
extends Embeddings
implements OpenAIEmbeddingsParams, AzureOpenAIInput
{
modelName = "text-embedding-ada-002";
model = "text-embedding-ada-002";
batchSize = 512;
// TODO: Update to `false` on next minor release (see: https://github.com/langchain-ai/langchainjs/pull/3612)
s... | |
147740 | export class OpenAIChat
extends LLM<OpenAIChatCallOptions>
implements OpenAIChatInput, AzureOpenAIInput
{
static lc_name() {
return "OpenAIChat";
}
get callKeys() {
return [...super.callKeys, "options", "promptIndex"];
}
lc_serializable = true;
get lc_secrets(): { [key: string]: string } | un... | |
147744 | /**
* OpenAI chat model integration.
*
* Setup:
* Install `@langchain/openai` and set an environment variable named `OPENAI_API_KEY`.
*
* ```bash
* npm install @langchain/openai
* export OPENAI_API_KEY="your-api-key"
* ```
*
* ## [Constructor args](https://api.js.langchain.com/classes/langchain_openai.ChatOp... | |
147746 | export class ChatOpenAI<
CallOptions extends ChatOpenAICallOptions = ChatOpenAICallOptions
>
extends BaseChatModel<CallOptions, AIMessageChunk>
implements OpenAIChatInput, AzureOpenAIInput
{
static lc_name() {
return "ChatOpenAI";
}
get callKeys() {
return [
...super.callKeys,
"opti... | |
147755 | import {
type ClientOptions,
AzureOpenAI as AzureOpenAIClient,
OpenAI as OpenAIClient,
} from "openai";
import { OpenAIEmbeddings, OpenAIEmbeddingsParams } from "../embeddings.js";
import {
AzureOpenAIInput,
OpenAICoreRequestOptions,
LegacyOpenAIInput,
} from "../types.js";
import { getEndpoint, OpenAIEndpo... | |
147757 | /**
* Azure OpenAI chat model integration.
*
* Setup:
* Install `@langchain/openai` and set the following environment variables:
*
* ```bash
* npm install @langchain/openai
* export AZURE_OPENAI_API_KEY="your-api-key"
* export AZURE_OPENAI_API_DEPLOYMENT_NAME="your-deployment-name"
* export AZURE_OPENAI_API_V... | |
147764 | /* eslint-disable no-process-env */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { test, jest, expect } from "@jest/globals";
import {
AIMessageChunk,
BaseMessage,
ChatMessage,
HumanMessage,
SystemMessage,
} from "@langchain/core/messages";
import { ChatGeneration, LLMResult } from "@langcha... | |
147765 | test("OpenAI Chat, docs, prompt templates", async () => {
const chat = new ChatOpenAI({ temperature: 0, maxTokens: 10 });
const systemPrompt = PromptTemplate.fromTemplate(
"You are a helpful assistant that translates {input_language} to {output_language}."
);
const chatPrompt = ChatPromptTemplate.fromMess... | |
147767 | test("Test ChatOpenAI token usage reporting for streaming function calls", async () => {
const humanMessage = "What a beautiful day!";
const extractionFunctionSchema = {
name: "extractor",
description: "Extracts fields from the input.",
parameters: {
type: "object",
properties: {
ton... | |
147770 | /* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { LLMResult } from "@langchain/core/outputs";
import { StringPromptValue } from "@langchain/core/prompt_values";
import { CallbackManager } from "@langchain/core/callbacks/manager";
import { NewTokenIndices } from "@langchain/core... | |
147771 | test("Test OpenAIChat in streaming mode with multiple prompts", async () => {
let nrNewTokens = 0;
const completions = [[""], [""]];
const model = new OpenAI({
maxTokens: 5,
modelName: "gpt-3.5-turbo",
streaming: true,
n: 1,
callbacks: CallbackManager.fromHandlers({
async handleLLMNewTo... | |
147775 | describe("response_format: json_schema", () => {
const weatherSchema = z.object({
city: z.string().describe("The city to get the weather for"),
state: z.string().describe("The state to get the weather for"),
zipCode: z.string().describe("The zip code to get the weather for"),
unit: z
.enum(["fah... | |
147778 | const CACHED_TEXT = `## Components
LangChain provides standard, extendable interfaces and external integrations for various components useful for building with LLMs.
Some components LangChain implements, some components we rely on third-party integrations for, and others are a mix.
### Chat models
<span data-heading... | |
147779 | This will produce an array of two messages, the first one being a system message, and the second one being the HumanMessage we passed in.
If we had passed in 5 messages, then it would have produced 6 messages in total (the system message plus the 5 passed in).
This is useful for letting an array of messages be slotted ... | |
147785 | test("Test Azure ChatOpenAI in streaming mode with n > 1 and multiple prompts", async () => {
// Running LangChain callbacks in the background will sometimes cause the callbackManager to execute
// after the test/llm call has already finished & returned. Set that environment variable to false
// to prevent that f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.