Skip to content

Commit

Permalink
Merge branch 'main' into brace/loosen-peer-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored May 29, 2024
2 parents 9b5c655 + 0cc732e commit 5762786
Show file tree
Hide file tree
Showing 33 changed files with 418 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/test-exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ env:
jobs:
exports-esbuild:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand All @@ -43,6 +45,8 @@ jobs:

exports-esm:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand All @@ -62,6 +66,8 @@ jobs:

exports-cjs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand All @@ -81,6 +87,8 @@ jobs:

exports-cf:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand All @@ -100,6 +108,8 @@ jobs:

exports-vercel:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand All @@ -119,6 +129,8 @@ jobs:

exports-vite:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand All @@ -138,6 +150,8 @@ jobs:

exports-tsc:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
Expand Down
7 changes: 7 additions & 0 deletions docs/core_docs/docs/integrations/vectorstores/upstash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CreateClientExample from "@examples/indexes/vector_stores/upstash/create_
import IndexQueryExample from "@examples/indexes/vector_stores/upstash/index_and_query_docs.ts";
import DeleteExample from "@examples/indexes/vector_stores/upstash/delete_docs.ts";
import UpstashEmbeddingsExample from "@examples/indexes/vector_stores/upstash/upstash_embeddings.ts";
import NamespaceExample from "@examples/indexes/vector_stores/upstash/namespaces.ts";
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

# Upstash Vector
Expand Down Expand Up @@ -42,6 +43,12 @@ You can index the LangChain documents with any model of your choice, and perform

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

## Namespaces

You can use namespaces to partition your data in the index. Namespaces are useful when you want to query over huge amount of data, and you want to partition the data to make the queries faster. When you use namespaces, there won't be post-filtering on the results which will make the query results more precise.

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

## Upstash embeddings

It's possible to use the embeddings service of Upstash, which is based on the embedding model of choice when creating the vector database. You don't need to create the embeddings manually, as the Upstash Vector service will handle this for you.
Expand Down
2 changes: 1 addition & 1 deletion docs/core_docs/docs/tutorials/llm_chain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
"id": "fedf6f13",
"metadata": {},
"source": [
"Next, we can create the PromptTemplate. This will be a combination of the `systemTemplate` as well as a simpler template for where the put the text"
"Next, we can create the PromptTemplate. This will be a combination of the `systemTemplate` as well as a simpler template for where to put the text"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/core_docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"glob": "^10.3.10",
"prettier": "^2.7.1",
"prettier": "^2.8.3",
"rimraf": "^5.0.1",
"supabase": "^1.148.6",
"swc-loader": "^0.2.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@supabase/supabase-js": "^2.10.0",
"@tensorflow/tfjs-backend-cpu": "^4.4.0",
"@upstash/redis": "^1.20.6",
"@upstash/vector": "^1.0.7",
"@upstash/vector": "^1.1.1",
"@vercel/kv": "^0.2.3",
"@xata.io/client": "^0.28.0",
"@zilliz/milvus2-sdk-node": "^2.2.7",
Expand Down
50 changes: 50 additions & 0 deletions examples/src/indexes/vector_stores/upstash/namespaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Index } from "@upstash/vector";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";
import { UpstashVectorStore } from "@langchain/community/vectorstores/upstash";

const index = new Index({
url: process.env.UPSTASH_VECTOR_REST_URL as string,
token: process.env.UPSTASH_VECTOR_REST_TOKEN as string,
});

const embeddings = new OpenAIEmbeddings({});

const UpstashVector = new UpstashVectorStore(embeddings, {
index,
namespace: "test-namespace",
});

// Creating the docs to be indexed.
const id = new Date().getTime();
const documents = [
new Document({
metadata: { name: id },
pageContent: "Vector databases are great!",
}),
];

// Creating embeddings from the provided documents, and adding them to target namespace in Upstash Vector database.
await UpstashVector.addDocuments(documents);

// Waiting vectors to be indexed in the vector store.
// eslint-disable-next-line no-promise-executor-return
await new Promise((resolve) => setTimeout(resolve, 1000));

const queryResult = await UpstashVector.similaritySearchWithScore(
"Vector database",
1
);

console.log(queryResult);
/**
[
[
Document {
pageContent: 'Vector databases are great!',
metadata: [Object]
},
0.9016147
],
]
*/
5 changes: 4 additions & 1 deletion langchain/src/util/sql_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export const getTableAndColumnsName = async (
return formatToSqlTable(rep);
}

if (appDataSource.options.type === "sqlite") {
if (
appDataSource.options.type === "sqlite" ||
appDataSource.options.type === "sqljs"
) {
sql =
"SELECT \n" +
" m.name AS table_name,\n" +
Expand Down
1 change: 1 addition & 0 deletions libs/create-langchain-integration/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
"no-process-env": 2,
"no-instanceof/no-instanceof": 2,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-shadow": 0,
"@typescript-eslint/no-empty-interface": 0,
Expand Down
19 changes: 19 additions & 0 deletions libs/create-langchain-integration/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf"
}
16 changes: 12 additions & 4 deletions libs/create-langchain-integration/helpers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ function isInGitRepository(): boolean {
try {
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
return true;
} catch (_) {}
} catch (_) {
// no-op
}
return false;
}

function isInMercurialRepository(): boolean {
try {
execSync("hg --cwd . root", { stdio: "ignore" });
return true;
} catch (_) {}
} catch (_) {
// no-op
}
return false;
}

function isDefaultBranchSet(): boolean {
try {
execSync("git config init.defaultBranch", { stdio: "ignore" });
return true;
} catch (_) {}
} catch (_) {
// no-op
}
return false;
}

Expand Down Expand Up @@ -54,7 +60,9 @@ export function tryGitInit(root: string): boolean {
if (didInit) {
try {
fs.rmSync(path.join(root, ".git"), { recursive: true, force: true });
} catch (_) {}
} catch (_) {
// no-op
}
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/create-langchain-integration/helpers/is-url.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function isUrl(url: string): boolean {
try {
new URL(url);
return true;
const newUrl = new URL(url);
return Boolean(newUrl);
} catch (error) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/create-langchain-integration/helpers/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path";
import fs from "fs/promises";
import os from "os";

import { copy } from "./copy";
import { copy } from "./copy.js";

/**
* Install a internal template to a given `root` directory.
Expand Down
14 changes: 12 additions & 2 deletions libs/create-langchain-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"scripts": {
"dev": "ncc build ./index.ts -w -o dist/",
"build": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register && cp ./template/.eslintrc.cjs ./template/.prettierrc ./template/.release-it.json ./dist/template",
"format": "prettier --write \"./\"",
"format:check": "prettier --check \"./\""
"format": "prettier --config .prettierrc --write \"./helpers\"",
"format:check": "prettier --config .prettierrc --check \"./helpers\"",
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js ./helpers",
"lint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js ./helpers",
"lint:fix": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --fix --ext .ts,.js ./helpers"
},
"devDependencies": {
"@types/prompts": "^2",
Expand All @@ -20,6 +23,13 @@
"commander": "^2.20.0",
"conf": "^10.2.0",
"dotenv": "^16.3.1",
"eslint": "^8.33.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-no-instanceof": "^1.0.1",
"eslint-plugin-prettier": "^4.2.1",
"fast-glob": "^3.3.2",
"picocolors": "^1.0.0",
"prettier": "^2.8.3",
Expand Down
4 changes: 2 additions & 2 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"@typescript-eslint/parser": "^5.58.0",
"@upstash/ratelimit": "^1.1.3",
"@upstash/redis": "^1.20.6",
"@upstash/vector": "^1.0.7",
"@upstash/vector": "^1.1.1",
"@vercel/kv": "^0.2.3",
"@vercel/postgres": "^0.5.0",
"@writerai/writer-sdk": "^0.40.2",
Expand Down Expand Up @@ -266,7 +266,7 @@
"@tensorflow/tfjs-core": "*",
"@upstash/ratelimit": "^1.1.3",
"@upstash/redis": "^1.20.6",
"@upstash/vector": "^1.0.7",
"@upstash/vector": "^1.1.1",
"@vercel/kv": "^0.2.3",
"@vercel/postgres": "^0.5.0",
"@writerai/writer-sdk": "^0.40.2",
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/chat_models/moonshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export class ChatMoonshot extends BaseChatModel implements ChatMoonshotParams {
prompt_tokens = 0,
completion_tokens = 0,
total_tokens = 0,
} = data.usage;
} = data.usage ?? {};

const { text } = data.output;

Expand Down
Loading

0 comments on commit 5762786

Please sign in to comment.