Skip to content

Commit

Permalink
feat: add examples, workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivan-sean committed Feb 14, 2023
1 parent 6312a7d commit 5ccb681
Show file tree
Hide file tree
Showing 58 changed files with 8,023 additions and 4,631 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ lib/
.turbo
.eslintcache
.env
yarn-error.log

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn precommit
npx turbo run precommit
9 changes: 9 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-typescript.cjs

Large diffs are not rendered by default.

873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"

yarnPath: .yarn/releases/yarn-3.4.1.cjs
2 changes: 0 additions & 2 deletions babel.config.js

This file was deleted.

2 changes: 2 additions & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=ADD_YOUR_API_KEY_HERE
SERPAPI_API_KEY=ADD_YOUR_API_KEY_HERE
File renamed without changes.
Binary file added examples/.yarn/install-state.gz
Binary file not shown.
36 changes: 36 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "langchain-examples",
"version": "0.0.0",
"private": true,
"description": "Langchain examples",
"main": "./dist/index.js",
"files": [
"dist/"
],
"scripts": {
"build": "tsc --declaration --outDir dist/",
"start": "yarn build && node -r dotenv/config dist/index.js",
"lint": "eslint src",
"lint:fix": "yarn lint --fix"
},
"author": "Langchain",
"license": "MIT",
"dependencies": {
"langchain": "workspace:*",
"openai": "^3.1.0",
"serpapi": "^1.1.0"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"dotenv": "^16.0.3",
"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-prettier": "^4.2.1",
"prettier": "^2.8.3",
"typescript": "^4.9.5"
}
}
28 changes: 28 additions & 0 deletions examples/src/agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { OpenAI } from "langchain";
import { loadAgent, AgentExecutor } from "langchain/agents";
import { SerpAPI } from "langchain/tools";

export const run = async () => {
const model = new OpenAI();
const tools = [SerpAPI()];

const agent = await loadAgent(
"lc://agents/zero-shot-react-description/agent.json",
{ llm: model, tools }
);
console.log("Loaded agent from Langchain hub");

const executor = AgentExecutor.fromAgentAndTools({
agent,
tools,
returnIntermediateSteps: true,
});

const input = "Who is Olivia Wilde's boyfriend?" +
" What is his current age raised to the 0.23 power?";
console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });

console.log(`Got output ${result.output}`);
};
12 changes: 12 additions & 0 deletions examples/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from "path";

const [exampleName, ...args] = process.argv.slice(2);
let runExample;
try {
// eslint-disable-next-line import/no-dynamic-require,global-require
({ run: runExample } = require(path.join(__dirname, exampleName)));
} catch {
throw new Error(`Could not load example ${exampleName}`);
}

runExample(args);
2 changes: 1 addition & 1 deletion tsconfig.json → examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"moduleResolution": "node",
"moduleResolution": "nodenext",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",
Expand Down
2 changes: 2 additions & 0 deletions langchain/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=ADD_YOUR_API_KEY_HERE
SERPAPI_API_KEY=ADD_YOUR_API_KEY_HERE
40 changes: 40 additions & 0 deletions langchain/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
extends: [
"airbnb-base",
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/recommended",
],
parserOptions: {
ecmaVersion: 12,
parser: "@typescript-eslint/parser",
sourceType: "module",
},
plugins: ["@typescript-eslint"],
ignorePatterns: ["dist", "node_modules"],
rules: {
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-shadow": 0,
"@typescript-eslint/no-use-before-define": ["error", "nofunc"],
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
"camelcase": 0,
"class-methods-use-this": 0,
"import/extensions": 0,
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts"]}],
"import/no-unresolved": 0,
"import/prefer-default-export": 0,
"keyword-spacing": "error",
"max-classes-per-file": 0,
"max-len": ["error", { code: 100, tabWidth: 2, ignoreComments: true }],
"no-await-in-loop": 0,
"no-bitwise": 0,
"no-console": 0,
"no-restricted-syntax": 0,
"no-shadow": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"no-useless-constructor": 0,
"semi": ["error", "always"],
},
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions langchain/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// babel.config.js
module.exports = {presets: ['@babel/preset-env']};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions jest.config.js → langchain/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
modulePathIgnorePatterns: ["dist/"],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
"^.+\\.(js)$": "babel-jest",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
97 changes: 97 additions & 0 deletions langchain/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"name": "langchain",
"version": "0.0.4",
"description": "Typescript bindings for langchain",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/"
],
"exports": {
".": {
"types": "./dist/cjs/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
},
"./agents": {
"types": "./dist/cjs/agents/index.d.ts",
"require": "./dist/cjs/agents/index.js",
"import": "./dist/esm/agents/index.js"
},
"./tools": {
"types": "./dist/cjs/agents/tools/index.d.ts",
"require": "./dist/cjs/agents/tools/index.js",
"import": "./dist/esm/agents/tools/index.js"
},
"./prompt": {
"types": "./dist/cjs/prompt/index.d.ts",
"require": "./dist/cjs/prompt/index.js",
"import": "./dist/esm/prompt/index.js"
},
"./chains": {
"types": "./dist/cjs/chains/index.d.ts",
"require": "./dist/cjs/chains/index.js",
"import": "./dist/esm/chains/index.js"
},
"./llms": {
"types": "./dist/cjs/llms/index.d.ts",
"require": "./dist/cjs/llms/index.js",
"import": "./dist/esm/llms/index.js"
}
},
"scripts": {
"build": "tsc --declaration --outDir dist/esm --module esnext && tsc --declaration --outDir dist/cjs",
"lint": "eslint .",
"lint:fix": "yarn lint --fix",
"precommit": "tsc --noEmit && lint-staged",
"clean": "rm -rf dist/",
"prepack": "yarn build",
"test": "jest",
"prepare": "husky install"
},
"author": "Langchain",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@jest/globals": "^29.4.2",
"@tsconfig/recommended": "^1.0.2",
"@types/node-fetch": "2",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"babel-jest": "^29.4.2",
"dotenv": "^16.0.3",
"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-prettier": "^4.2.1",
"husky": "^8.0.3",
"jest": "^29.4.2",
"lint-staged": "^13.1.1",
"openai": "^3.1.0",
"prettier": "^2.8.3",
"serpapi": "^1.1.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
},
"dependencies": {
"exponential-backoff": "^3.1.0",
"node-fetch": "2",
"yaml": "^2.2.1"
},
"optionalDependencies": {
"openai": "^3.1.0",
"serpapi": "^1.1.0"
},
"lint-staged": {
"**/*.{ts,tsx}": [
"prettier --write --ignore-unknown",
"eslint --cache --fix"
]
},
"publishConfig": {
"access": "public"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions langchain/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "@tsconfig/recommended",
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"moduleResolution": "node",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"declaration": true,
"experimentalDecorators": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"useDefineForClassFields": true,
"strictPropertyInitialization": false
},
"exclude": ["node_modules/", "dist/", "tests/"],
"include": ["./"]
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5ccb681

Please sign in to comment.