├── backend ├── src │ ├── chain.ts │ ├── parser.ts │ ├── constants.ts │ ├── ingest.ts │ └── _index.ts ├── README.md ├── .gitignore ├── babel.config.cjs ├── tsup.config.js ├── .env.example ├── jest.env.cjs ├── .prettierrc ├── jest.config.cjs ├── tsconfig.json ├── LICENSE ├── .eslintrc.cjs └── package.json ├── frontend ├── .prettierrc ├── .eslintrc.json ├── public │ ├── favicon.ico │ └── images │ │ └── github-mark.svg ├── vercel.json ├── next.config.js ├── postcss.config.js ├── app │ ├── utils │ │ ├── constants.tsx │ │ └── sendFeedback.tsx │ ├── globals.css │ ├── page.tsx │ ├── components │ │ ├── InlineCitation.tsx │ │ ├── AutoResizeTextarea.tsx │ │ ├── SourceBubble.tsx │ │ ├── EmptyState.tsx │ │ ├── ChatWindow.tsx │ │ └── ChatMessageBubble.tsx │ ├── layout.tsx │ └── api │ │ ├── get_trace │ │ └── route.ts │ │ ├── feedback │ │ └── route.ts │ │ └── chat │ │ └── stream_log │ │ └── route.ts ├── .env.example ├── .gitignore ├── tailwind.config.ts ├── tsconfig.json └── package.json ├── .vscode └── settings.json ├── assets └── images │ ├── Chat_Your_Data.gif │ ├── langsmith_trace.png │ ├── langsmith_feedback.png │ ├── orbstack_running_chroma.png │ └── orbstack_running_chroma_pgsql.png ├── .yarnrc.yml ├── turbo.json ├── package.json ├── LICENSE ├── .github └── workflows │ ├── update-index.yml │ └── ci.yml ├── PRODUCTION.md ├── .gitignore ├── README.md ├── DEPLOYMENT.md ├── LANGSMITH.md ├── RUN_LOCALLY.md ├── CONCEPTS.md ├── MODIFY.md └── .yarn └── plugins └── @yarnpkg └── plugin-typescript.cjs /backend/src/chain.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/src/parser.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/README.md: -------------------------------------------------------------------------------- 1 | # Chat LangChainJS Backend -------------------------------------------------------------------------------- /frontend/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "endOfLine": "lf" 3 | } 4 | -------------------------------------------------------------------------------- /frontend/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "productionized" 4 | ] 5 | } -------------------------------------------------------------------------------- /backend/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const WEAVIATE_DOCS_INDEX_NAME = "LangChain_agent_docs"; 2 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | index.cjs 2 | index.js 3 | index.d.ts 4 | index.d.cts 5 | node_modules 6 | dist 7 | .yarn 8 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langchain-ai/chat-langchainjs/HEAD/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "git": { 3 | "deploymentEnabled": { 4 | "main": false 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /assets/images/Chat_Your_Data.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langchain-ai/chat-langchainjs/HEAD/assets/images/Chat_Your_Data.gif -------------------------------------------------------------------------------- /assets/images/langsmith_trace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langchain-ai/chat-langchainjs/HEAD/assets/images/langsmith_trace.png -------------------------------------------------------------------------------- /frontend/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = {}; 3 | 4 | module.exports = nextConfig; 5 | -------------------------------------------------------------------------------- /frontend/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /assets/images/langsmith_feedback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langchain-ai/chat-langchainjs/HEAD/assets/images/langsmith_feedback.png -------------------------------------------------------------------------------- /assets/images/orbstack_running_chroma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langchain-ai/chat-langchainjs/HEAD/assets/images/orbstack_running_chroma.png -------------------------------------------------------------------------------- /backend/babel.config.cjs: -------------------------------------------------------------------------------- 1 | // babel.config.js 2 | module.exports = { 3 | presets: [["@babel/preset-env", { targets: { node: true } }]], 4 | }; 5 | -------------------------------------------------------------------------------- /assets/images/orbstack_running_chroma_pgsql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/langchain-ai/chat-langchainjs/HEAD/assets/images/orbstack_running_chroma_pgsql.png -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | plugins: 4 | - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs 5 | spec: "@yarnpkg/plugin-typescript" 6 | 7 | yarnPath: .yarn/releases/yarn-3.4.1.cjs -------------------------------------------------------------------------------- /frontend/app/utils/constants.tsx: -------------------------------------------------------------------------------- 1 | const apiBasePath = process.env.VERCEL_URL 2 | ? `https://${process.env.VERCEL_URL}` 3 | : `http://localhost:3000`; 4 | export const apiBaseUrl = `${apiBasePath}/api`; 5 | -------------------------------------------------------------------------------- /backend/tsup.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "tsup"; 2 | 3 | export default defineConfig({ 4 | entry: ["src/*.ts"], 5 | format: ["esm"], 6 | dts: true, // Generate declaration file (.d.ts) 7 | splitting: false, 8 | sourcemap: true, 9 | clean: true, 10 | }); -------------------------------------------------------------------------------- /frontend/.env.example: -------------------------------------------------------------------------------- 1 | # ------------------LangSmith tracing------------------ 2 | LANGCHAIN_TRACING_V2=true 3 | LANGCHAIN_ENDPOINT="https://api.smith.langchain.com" 4 | LANGCHAIN_API_KEY= 5 | LANGCHAIN_PROJECT= 6 | # ----------------------------------------------------- 7 | 8 | WEAVIATE_API_KEY= 9 | WEAVIATE_URL= 10 | WEAVIATE_INDEX_NAME= 11 | 12 | FIREWORKS_API_KEY= 13 | 14 | OPENAI_API_KEY= 15 | -------------------------------------------------------------------------------- /backend/.env.example: -------------------------------------------------------------------------------- 1 | # ------------------LangSmith tracing------------------ 2 | LANGCHAIN_TRACING_V2=true 3 | LANGCHAIN_ENDPOINT="https://api.smith.langchain.com" 4 | LANGCHAIN_API_KEY= 5 | LANGCHAIN_PROJECT= 6 | # ----------------------------------------------------- 7 | 8 | WEAVIATE_API_KEY= 9 | WEAVIATE_URL= 10 | WEAVIATE_INDEX_NAME= 11 | FORCE_UPDATE=true 12 | RECORD_MANAGER_DB_URL= 13 | OPENAI_API_KEY= -------------------------------------------------------------------------------- /frontend/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body { 6 | color: #f8f8f8; 7 | background: #131318; 8 | } 9 | 10 | body input, 11 | body textarea { 12 | color: black; 13 | } 14 | 15 | a { 16 | color: #2d7bd4; 17 | } 18 | 19 | a:hover { 20 | border-bottom: 1px solid; 21 | } 22 | 23 | p { 24 | margin: 8px 0; 25 | } 26 | 27 | code { 28 | color: #ffa500; 29 | } 30 | 31 | li { 32 | padding: 4px; 33 | } 34 | -------------------------------------------------------------------------------- /frontend/app/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { v4 as uuidv4 } from "uuid"; 4 | import { ChatWindow } from "../app/components/ChatWindow"; 5 | import { ToastContainer } from "react-toastify"; 6 | 7 | import { ChakraProvider } from "@chakra-ui/react"; 8 | 9 | export default function Home() { 10 | return ( 11 | 12 | 13 | 14 | 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /backend/jest.env.cjs: -------------------------------------------------------------------------------- 1 | const { TestEnvironment } = require("jest-environment-node"); 2 | 3 | class AdjustedTestEnvironmentToSupportFloat32Array extends TestEnvironment { 4 | constructor(config, context) { 5 | // Make `instanceof Float32Array` return true in tests 6 | // to avoid https://github.com/xenova/transformers.js/issues/57 and https://github.com/jestjs/jest/issues/2549 7 | super(config, context); 8 | this.global.Float32Array = Float32Array; 9 | } 10 | } 11 | 12 | module.exports = AdjustedTestEnvironmentToSupportFloat32Array; 13 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | 37 | .yarn/ -------------------------------------------------------------------------------- /backend/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/prettierrc", 3 | "printWidth": 80, 4 | "tabWidth": 2, 5 | "useTabs": false, 6 | "semi": true, 7 | "singleQuote": false, 8 | "quoteProps": "as-needed", 9 | "jsxSingleQuote": false, 10 | "trailingComma": "es5", 11 | "bracketSpacing": true, 12 | "arrowParens": "always", 13 | "requirePragma": false, 14 | "insertPragma": false, 15 | "proseWrap": "preserve", 16 | "htmlWhitespaceSensitivity": "css", 17 | "vueIndentScriptAndStyle": false, 18 | "endOfLine": "lf" 19 | } 20 | -------------------------------------------------------------------------------- /frontend/tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from "tailwindcss"; 2 | 3 | const config: Config = { 4 | content: [ 5 | "./pages/**/*.{js,ts,jsx,tsx,mdx}", 6 | "./components/**/*.{js,ts,jsx,tsx,mdx}", 7 | "./app/**/*.{js,ts,jsx,tsx,mdx}", 8 | ], 9 | theme: { 10 | extend: { 11 | backgroundImage: { 12 | "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", 13 | "gradient-conic": 14 | "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", 15 | }, 16 | }, 17 | }, 18 | plugins: [], 19 | }; 20 | export default config; 21 | -------------------------------------------------------------------------------- /backend/jest.config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | module.exports = { 3 | preset: "ts-jest/presets/default-esm", 4 | testEnvironment: "./jest.env.cjs", 5 | modulePathIgnorePatterns: ["dist/", "docs/"], 6 | moduleNameMapper: { 7 | "^(\\.{1,2}/.*)\\.js$": "$1", 8 | }, 9 | transform: { 10 | '^.+\\.tsx?$': ['@swc/jest'], 11 | }, 12 | transformIgnorePatterns: [ 13 | "/node_modules/", 14 | "\\.pnp\\.[^\\/]+$", 15 | "./scripts/jest-setup-after-env.js", 16 | ], 17 | setupFiles: ["dotenv/config"], 18 | setupFilesAfterEnv: ["./scripts/jest-setup-after-env.js"], 19 | testTimeout: 20_000, 20 | passWithNoTests: true 21 | }; 22 | -------------------------------------------------------------------------------- /frontend/app/components/InlineCitation.tsx: -------------------------------------------------------------------------------- 1 | import { Source } from "./SourceBubble"; 2 | 3 | export function InlineCitation(props: { 4 | source: Source; 5 | sourceNumber: number; 6 | highlighted: boolean; 7 | onMouseEnter: () => any; 8 | onMouseLeave: () => any; 9 | }) { 10 | const { source, sourceNumber, highlighted, onMouseEnter, onMouseLeave } = 11 | props; 12 | return ( 13 | 22 | {sourceNumber} 23 | 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "bundler", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true, 17 | "plugins": [ 18 | { 19 | "name": "next" 20 | } 21 | ], 22 | "paths": { 23 | "@/*": ["./*"] 24 | } 25 | }, 26 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 27 | "exclude": ["node_modules"] 28 | } 29 | -------------------------------------------------------------------------------- /frontend/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import "./globals.css"; 2 | import type { Metadata } from "next"; 3 | import { Inter } from "next/font/google"; 4 | 5 | const inter = Inter({ subsets: ["latin"] }); 6 | 7 | export const metadata: Metadata = { 8 | title: "Chat LangChain", 9 | description: "Chatbot for LangChain", 10 | }; 11 | 12 | export default function RootLayout({ 13 | children, 14 | }: { 15 | children: React.ReactNode; 16 | }) { 17 | return ( 18 | 19 | 20 |
24 | {children} 25 |
26 | 27 | 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "globalDependencies": ["**/.env"], 4 | "pipeline": { 5 | "build": { 6 | "dependsOn": ["^build"], 7 | "outputs": ["**/dist/**"], 8 | "inputs": ["**/src/**"] 9 | }, 10 | "lint": { 11 | "dependsOn": ["^lint"], 12 | "inputs": ["**/src/**"] 13 | }, 14 | "format": { 15 | "dependsOn": ["^format"], 16 | "inputs": ["**/src/**"] 17 | }, 18 | "format:check": { 19 | "dependsOn": ["^format:check"], 20 | "inputs": ["**/src/**"] 21 | }, 22 | "start": { 23 | "dependsOn": ["^start"], 24 | "inputs": ["**/src/**"] 25 | }, 26 | "dev": { 27 | "dependsOn": ["^dev"], 28 | "inputs": ["**/src/**"] 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chat-langchainjs", 3 | "private": true, 4 | "version": "0.0.0", 5 | "author": "LangChainAI", 6 | "license": "MIT", 7 | "workspaces": [ 8 | "backend", 9 | "frontend" 10 | ], 11 | "scripts": { 12 | "build": "yarn run turbo:command build", 13 | "turbo:command": "yarn turbo", 14 | "lint": "yarn run turbo:command lint", 15 | "lint:fix": "yarn run turbo:command lint:fix", 16 | "format": "yarn run turbo:command format", 17 | "format:check": "yarn run turbo:command format:check" 18 | }, 19 | "devDependencies": { 20 | "turbo": "latest" 21 | }, 22 | "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" 23 | } 24 | -------------------------------------------------------------------------------- /backend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "../dist", 4 | "rootDir": "./src", 5 | "target": "ES2021", 6 | "lib": [ 7 | "ES2021", 8 | "ES2022.Object", 9 | "DOM" 10 | ], 11 | "module": "NodeNext", 12 | "moduleResolution": "NodeNext", 13 | "esModuleInterop": true, 14 | "declaration": true, 15 | "noImplicitReturns": true, 16 | "noFallthroughCasesInSwitch": true, 17 | "noUnusedLocals": true, 18 | "noUnusedParameters": true, 19 | "useDefineForClassFields": true, 20 | "strictPropertyInitialization": false, 21 | "allowJs": true, 22 | "strict": true 23 | }, 24 | "include": [ 25 | "./src/**/*" 26 | ], 27 | "exclude": [ 28 | "**/node_modules/**", 29 | "./node_modules/**", 30 | "dist", 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /frontend/public/images/github-mark.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/app/components/AutoResizeTextarea.tsx: -------------------------------------------------------------------------------- 1 | import { Textarea, TextareaProps } from "@chakra-ui/react"; 2 | import ResizeTextarea from "react-textarea-autosize"; 3 | import React from "react"; 4 | 5 | interface ResizeTextareaProps { 6 | maxRows?: number; 7 | } 8 | 9 | const ResizableTextarea: React.FC = ({ 10 | maxRows, 11 | ...props 12 | }) => { 13 | return ; 14 | }; 15 | 16 | interface AutoResizeTextareaProps extends TextareaProps { 17 | maxRows?: number; 18 | } 19 | 20 | export const AutoResizeTextarea = React.forwardRef< 21 | HTMLTextAreaElement, 22 | AutoResizeTextareaProps 23 | >((props, ref) => { 24 | return ( 25 |