├── .env.example ├── .eslintrc.cjs ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── src └── index.ts ├── tsconfig.json ├── tsup.config.js └── turbo.json /.env.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY= -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | "airbnb-base", 4 | "eslint:recommended", 5 | "prettier", 6 | "plugin:@typescript-eslint/recommended", 7 | ], 8 | parserOptions: { 9 | ecmaVersion: 12, 10 | parser: "@typescript-eslint/parser", 11 | sourceType: "module", 12 | }, 13 | plugins: ["@typescript-eslint"], 14 | rules: { 15 | "@typescript-eslint/explicit-module-boundary-types": 0, 16 | "@typescript-eslint/no-empty-function": 0, 17 | "@typescript-eslint/no-shadow": 0, 18 | "@typescript-eslint/no-use-before-define": ["error", "nofunc"], 19 | "@typescript-eslint/no-unused-vars": ["warn", { args: "none" }], 20 | camelcase: 0, 21 | "class-methods-use-this": 0, 22 | "import/extensions": 0, 23 | "import/no-extraneous-dependencies": [ 24 | "error", 25 | { devDependencies: ["**/*.test.ts"] }, 26 | ], 27 | "import/no-unresolved": 0, 28 | "import/prefer-default-export": 0, 29 | "keyword-spacing": "error", 30 | "max-classes-per-file": 0, 31 | "max-len": 0, 32 | "no-await-in-loop": 0, 33 | "no-bitwise": 0, 34 | "no-console": 0, 35 | "no-restricted-syntax": 0, 36 | "no-shadow": 0, 37 | "no-underscore-dangle": 0, 38 | "no-use-before-define": 0, 39 | "no-useless-constructor": 0, 40 | semi: ["error", "always"], 41 | }, 42 | }; 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | dist 4 | .turbo -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # langchain-ts-starter 2 | 3 | Boilerplate to get started quickly with the [Langchain Typescript SDK](https://github.com/hwchase17/langchainjs). 4 | 5 | This uses the same tsconfig and build setup as the [examples repo](https://github.com/hwchase17/langchainjs/tree/main/examples), to ensure it's in sync with the official docs. 6 | 7 | # What's included 8 | 9 | - Typescript 10 | - .env file configuration 11 | - ESLint and Prettier for formatting 12 | - Turborepo to quickly run build scripts 13 | - `tsup` to bundle Typescript code 14 | - `tsx` to quickly run compiled code 15 | 16 | # How to use 17 | 18 | - Clone this repository 19 | - `npm install` 20 | - Write your code in `src` 21 | - `npx turbo run build lint format` to run build scripts quickly in parallel 22 | - `npm start` to run your program 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "langchain-ts-starter", 3 | "version": "1.0.0", 4 | "description": "", 5 | "type": "module", 6 | "main": "./dist/index.js", 7 | "files": [ 8 | "dist" 9 | ], 10 | "scripts": { 11 | "tsup": "tsup", 12 | "build": "tsup", 13 | "start": "tsx -r dotenv/config src/index.ts", 14 | "lint": "eslint src", 15 | "lint:fix": "npm run lint --fix", 16 | "format": "prettier --write \"**/*.ts\"", 17 | "format:check": "prettier --list-different \"**/*.ts\"" 18 | }, 19 | "keywords": [ 20 | "langchain", 21 | "starter", 22 | "template", 23 | "node", 24 | "typescript", 25 | "llm" 26 | ], 27 | "author": "", 28 | "license": "MIT", 29 | "dependencies": { 30 | "dotenv": "^16.0.3", 31 | "langchain": "^0.0.39", 32 | "tsup": "^6.7.0" 33 | }, 34 | "devDependencies": { 35 | "@tsconfig/recommended": "^1.0.2", 36 | "@types/js-yaml": "^4", 37 | "@types/node": "^18.15.5", 38 | "@typescript-eslint/eslint-plugin": "^5.51.0", 39 | "@typescript-eslint/parser": "^5.51.0", 40 | "eslint": "^8.33.0", 41 | "eslint-config-airbnb-base": "^15.0.0", 42 | "eslint-config-prettier": "^8.6.0", 43 | "eslint-plugin-import": "^2.27.5", 44 | "eslint-plugin-prettier": "^4.2.1", 45 | "prettier": "^2.8.3", 46 | "tsx": "^3.12.3", 47 | "typescript": "^5.0.4" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { OpenAI } from "langchain"; 3 | 4 | dotenv.config(); 5 | 6 | const model = new OpenAI({ 7 | modelName: "gpt-3.5-turbo", 8 | openAIApiKey: process.env.OPENAI_API_KEY, 9 | }); 10 | 11 | const res = await model.call( 12 | "What's a good idea for an application to build with GPT-3?" 13 | ); 14 | 15 | console.log(res); 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowImportingTsExtensions": true, 4 | "strict": true, 5 | "esModuleInterop": true, 6 | "skipLibCheck": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "outDir": "dist", 9 | "lib": ["ES2021", "ES2022.Object", "DOM"], 10 | "target": "es2017", 11 | "module": "nodenext", 12 | "sourceMap": true, 13 | "allowSyntheticDefaultImports": true, 14 | "baseUrl": "./src", 15 | "paths": { 16 | "@/*": ["./*"] 17 | }, 18 | "declaration": true, 19 | "experimentalDecorators": true, 20 | "noImplicitReturns": true, 21 | "noFallthroughCasesInSwitch": true, 22 | "noUnusedLocals": true, 23 | "noUnusedParameters": true, 24 | "useDefineForClassFields": true, 25 | "strictPropertyInitialization": false, 26 | "noEmit": true 27 | }, 28 | "exclude": ["node_modules/", "dist/", "tests/"], 29 | "include": ["./src"] 30 | } 31 | -------------------------------------------------------------------------------- /tsup.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "tsup"; 2 | 3 | export default defineConfig({ 4 | entry: ["src/index.ts"], 5 | format: ["cjs", "esm"], 6 | splitting: false, 7 | sourcemap: true, 8 | clean: true, 9 | bundle: true, 10 | dts: true, 11 | }); 12 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "pipeline": { 4 | "build": { 5 | "outputs": [".next/**", "!.next/cache/**"] 6 | }, 7 | "lint": {}, 8 | "format": {} 9 | } 10 | } 11 | --------------------------------------------------------------------------------