Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan committed Jan 20, 2025
2 parents ce08bfa + 98c9009 commit b2f6f87
Show file tree
Hide file tree
Showing 236 changed files with 7,020 additions and 2,955 deletions.
35 changes: 35 additions & 0 deletions .github/actions/js-vitest-eval-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "JS Vitest Eval Runner"
description: "Run JS Vitest Eval Runner"
inputs:
node-version:
description: "Node version"
required: true
langchain-api-key-beta:
description: "Langchain"
required: true
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
cache: "yarn"
cache-dependency-path: "js/yarn.lock"

- name: Install Yarn dependencies
run: yarn install
shell: bash
working-directory: js

- name: Run Vitest Eval Runner
run: yarn test:eval:vitest
shell: bash
working-directory: js
env:
LANGSMITH_TRACING_V2: "true"
LANGSMITH_ENDPOINT: https://beta.api.smith.langchain.com
LANGSMITH_API_KEY: ${{ inputs.langchain-api-key-beta }}
31 changes: 31 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,34 @@ jobs:
node-version: 20.x
langchain-api-key-beta: ${{ secrets.LANGSMITH_API_KEY_BETA }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}

js_vitest_eval_runner_test:
name: JS Vitest Runner Test
needs: changed_files
if: >
(github.event_name == 'push') ||
(github.event_name == 'pull_request' && (
contains(github.event.pull_request.labels.*.name, 'release') ||
needs.changed_files.outputs.js_changed == 'true'
)) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.run-js-tests == 'true')
runs-on: ubuntu-20.04
defaults:
run:
working-directory: js
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: "yarn"
cache-dependency-path: "js/yarn.lock"
- name: Install dependencies
run: yarn install --immutable
- name: Run JS Vitest eval runner test
uses: ./.github/actions/js-vitest-eval-test
with:
node-version: 20.x
langchain-api-key-beta: ${{ secrets.LANGSMITH_API_KEY_BETA }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ cython_debug/
.idea/
.DS_Store

# JS API refs
js/_build/

.envrc
16 changes: 16 additions & 0 deletions js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,26 @@ Chinook_Sqlite.sql
/langchain.js
/langchain.d.ts
/langchain.d.cts
/jest.cjs
/jest.js
/jest.d.ts
/jest.d.cts
/jest/reporter.cjs
/jest/reporter.js
/jest/reporter.d.ts
/jest/reporter.d.cts
/vercel.cjs
/vercel.js
/vercel.d.ts
/vercel.d.cts
/vitest.cjs
/vitest.js
/vitest.d.ts
/vitest.d.cts
/vitest/reporter.cjs
/vitest/reporter.js
/vitest/reporter.d.ts
/vitest/reporter.d.cts
/wrappers.cjs
/wrappers.js
/wrappers.d.ts
Expand Down
9 changes: 9 additions & 0 deletions js/ls.vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.vitesteval.?(c|m)[jt]s"],
reporters: ["./src/vitest/reporter.ts"],
setupFiles: ["dotenv/config"],
},
});
63 changes: 61 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.2.15",
"version": "0.3.0",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "yarn@1.22.19",
"files": [
Expand Down Expand Up @@ -33,10 +33,26 @@
"langchain.js",
"langchain.d.ts",
"langchain.d.cts",
"jest.cjs",
"jest.js",
"jest.d.ts",
"jest.d.cts",
"jest/reporter.cjs",
"jest/reporter.js",
"jest/reporter.d.ts",
"jest/reporter.d.cts",
"vercel.cjs",
"vercel.js",
"vercel.d.ts",
"vercel.d.cts",
"vitest.cjs",
"vitest.js",
"vitest.d.ts",
"vitest.d.cts",
"vitest/reporter.cjs",
"vitest/reporter.js",
"vitest/reporter.d.ts",
"vitest/reporter.d.cts",
"wrappers.cjs",
"wrappers.js",
"wrappers.d.ts",
Expand Down Expand Up @@ -67,6 +83,7 @@
"types": "./dist/index.d.ts",
"scripts": {
"build": "yarn clean && yarn build:esm && yarn build:cjs && node scripts/create-entrypoints.js",
"build:typedoc": "yarn build && rm -rf ./_build/api_refs && npx typedoc",
"bump-version": "node scripts/bump-version.js",
"check-version": "node scripts/check-version.js",
"check-npm-version": "node scripts/check-npm-version.js",
Expand All @@ -77,6 +94,7 @@
"test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000",
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
"watch:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --watch --config jest.config.cjs --testTimeout 100000",
"test:eval:vitest": "vitest run --config ls.vitest.config.ts",
"lint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
"lint:fix": "yarn lint --fix",
"format": "prettier --write 'src/**/*.{ts,tsx}'",
Expand All @@ -102,7 +120,8 @@
"homepage": "https://github.com/langchain-ai/langsmith-sdk#readme",
"dependencies": {
"@types/uuid": "^10.0.0",
"commander": "^10.0.1",
"chalk": "^4.1.2",
"console-table-printer": "^2.12.1",
"p-queue": "^6.6.2",
"p-retry": "4",
"semver": "^7.6.3",
Expand All @@ -113,6 +132,7 @@
"@babel/preset-env": "^7.22.4",
"@faker-js/faker": "^8.4.1",
"@jest/globals": "^29.5.0",
"@jest/reporters": "^29.7.0",
"@langchain/core": "^0.3.14",
"@langchain/langgraph": "^0.2.20",
"@langchain/openai": "^0.3.11",
Expand All @@ -139,7 +159,10 @@
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typedoc": "^0.27.6",
"typedoc-plugin-expand-object-like-types": "^0.1.2",
"typescript": "^5.4.5",
"vitest": "^2.1.8",
"zod": "^3.23.8"
},
"peerDependencies": {
Expand Down Expand Up @@ -229,6 +252,24 @@
"import": "./langchain.js",
"require": "./langchain.cjs"
},
"./jest": {
"types": {
"import": "./jest.d.ts",
"require": "./jest.d.cts",
"default": "./jest.d.ts"
},
"import": "./jest.js",
"require": "./jest.cjs"
},
"./jest/reporter": {
"types": {
"import": "./jest/reporter.d.ts",
"require": "./jest/reporter.d.cts",
"default": "./jest/reporter.d.ts"
},
"import": "./jest/reporter.js",
"require": "./jest/reporter.cjs"
},
"./vercel": {
"types": {
"import": "./vercel.d.ts",
Expand All @@ -238,6 +279,24 @@
"import": "./vercel.js",
"require": "./vercel.cjs"
},
"./vitest": {
"types": {
"import": "./vitest.d.ts",
"require": "./vitest.d.cts",
"default": "./vitest.d.ts"
},
"import": "./vitest.js",
"require": "./vitest.cjs"
},
"./vitest/reporter": {
"types": {
"import": "./vitest/reporter.d.ts",
"require": "./vitest/reporter.d.cts",
"default": "./vitest/reporter.d.ts"
},
"import": "./vitest/reporter.js",
"require": "./vitest/reporter.cjs"
},
"./wrappers": {
"types": {
"import": "./wrappers.d.ts",
Expand Down
19 changes: 19 additions & 0 deletions js/scripts/create-entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ const entrypoints = {
"evaluation/langchain": "evaluation/langchain",
schemas: "schemas",
langchain: "langchain",
jest: "jest/index",
"jest/reporter": "jest/reporter",
vercel: "vercel",
vitest: "vitest/index",
"vitest/reporter": "vitest/reporter",
wrappers: "wrappers/index",
anonymizer: "anonymizer/index",
"wrappers/openai": "wrappers/openai",
"wrappers/vercel": "wrappers/vercel",
"singletons/traceable": "singletons/traceable",
};

const defaultEntrypoints = [
"vitest/reporter"
];

const updateJsonFile = (relativePath, updateFunction) => {
const contents = fs.readFileSync(relativePath).toString();
const res = updateFunction(JSON.parse(contents));
Expand All @@ -34,6 +42,17 @@ const generateFiles = () => {
const nrOfDots = key.split("/").length - 1;
const relativePath = "../".repeat(nrOfDots) || "./";
const compiledPath = `${relativePath}dist/${value}.js`;
if (defaultEntrypoints.includes(key)) {
return [
[
`${key}.cjs`,
`module.exports = require('${relativePath}dist/${value}.cjs').default;`,
],
[`${key}.js`, `export { default } from '${compiledPath}'`],
[`${key}.d.ts`, `export { default } from '${compiledPath}'`],
[`${key}.d.cts`, `export { default } from '${compiledPath}'`],
];
}
return [
[
`${key}.cjs`,
Expand Down
105 changes: 105 additions & 0 deletions js/scripts/typedoc-plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const {
Application,
Converter,
Context,
ReflectionKind,
DeclarationReflection,
RendererEvent,
} = require("typedoc");
const fs = require("fs");
const path = require("path");

// Reflection types to check for methods that should not be documented.
// e.g methods prefixed with `_` or `lc_`
const REFLECTION_KINDS_TO_HIDE = [
ReflectionKind.Property,
ReflectionKind.Accessor,
ReflectionKind.Variable,
ReflectionKind.Method,
ReflectionKind.Function,
ReflectionKind.Class,
ReflectionKind.Interface,
ReflectionKind.Enum,
ReflectionKind.TypeAlias,
];

const BASE_OUTPUT_DIR = "./_build/api_refs";

// Script to inject into the HTML to add a CMD/CTRL + K 'hotkey' which focuses
// on the search input element.
const SCRIPT_HTML = `<script>
document.addEventListener('keydown', (e) => {
if ((e.metaKey || e.ctrlKey) && e.keyCode === 75) { // Check for CMD + K or CTRL + K
const input = document.getElementById('tsd-search-field'); // Get the search input element by ID
input.focus(); // Focus on the search input element
document.getElementById('tsd-search').style.display = 'block'; // Show the div wrapper with ID tsd-search
}
}, false); // Add event listener for keydown events
</script>`;

/**
* Takes in a reflection and an array of all chat model class names.
* Then performs checks to see if the given reflection should be removed
* from the documentation.
* E.g a class method on chat models which is
* not intended to be documented.
*
* @param {DeclarationReflection} reflection
* @returns {boolean} Whether or not the reflection should be removed
*/
function shouldRemoveReflection(reflection) {
const kind = reflection.kind;

if (REFLECTION_KINDS_TO_HIDE.find((kindToHide) => kindToHide === kind)) {
if (reflection.name.startsWith("_") || reflection.name.startsWith("ls_")) {
// Remove all reflections which start with an `_` or `ls_` as those are internal
return true;
}
}
return false;
}

/**
* @param {Application} application
* @returns {void}
*/
function load(application) {
application.converter.on(
Converter.EVENT_CREATE_DECLARATION,
resolveReflection
);

application.renderer.on(RendererEvent.END, onEndRenderEvent);

/**
* @param {Context} context
* @param {DeclarationReflection} reflection
* @returns {void}
*/
function resolveReflection(context, reflection) {
const { project } = context;

if (shouldRemoveReflection(reflection)) {
project.removeReflection(reflection);
}
}

/**
* @param {Context} context
*/
function onEndRenderEvent(context) {
const htmlToSplitAtSearchScript = `<div class="tsd-toolbar-contents container">`;

const { urls } = context;
for (const { url } of urls) {
const indexFilePath = path.join(BASE_OUTPUT_DIR, url);
const htmlFileContent = fs.readFileSync(indexFilePath, "utf-8");

const [part1, part2] = htmlFileContent.split(htmlToSplitAtSearchScript);
const htmlWithScript = part1 + SCRIPT_HTML + part2;
fs.writeFileSync(indexFilePath, htmlWithScript);
}
}
}

module.exports = { load };
Loading

0 comments on commit b2f6f87

Please sign in to comment.