-
Notifications
You must be signed in to change notification settings - Fork 69
✨ Add chatbot-server #2840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TheSonOfThomp
wants to merge
15
commits into
main
Choose a base branch
from
integration/chat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
✨ Add chatbot-server #2840
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eb699fe
rm
bruugey a675222
Refactor package dependencies and clean up unused code (#2847)
tsck f0fb59a
chat/pnpm (#2848)
TheSonOfThomp 2fe6217
Update `ingest` for Azure (#2843)
TheSonOfThomp 9bfde58
Ingest with recursive crawler (#2849)
TheSonOfThomp 8ac1b05
Chat bot server to Azure (#2850)
TheSonOfThomp bfe2fc2
fixes bad merge conflict
TheSonOfThomp 01f3921
Refactor Azure OpenAI integration: replace direct usage with new embe…
TheSonOfThomp 2acd83e
A/better rag (#2852)
TheSonOfThomp f7e1587
Squashed commit of the following:
TheSonOfThomp 36e1f23
rm chatbot ui
TheSonOfThomp 0b73660
rm crawler lambda
TheSonOfThomp 47b22ee
fix builds
TheSonOfThomp 4929f29
Update pnpm-lock.yaml
TheSonOfThomp c6c3d48
Merge branch 'main' into integration/chat
TheSonOfThomp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@lg-tools/codemods': patch | ||
--- | ||
|
||
[LG-5015](https://jira.mongodb.org/browse/LG-5015): bump `jscodeshift` to 17.3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@leafygreen-ui/icon': minor | ||
--- | ||
|
||
Adds `'Streaming'` glyph to the set |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
PORT=3030 | ||
|
||
# MongoDB config | ||
MONGODB_USER=<YOUR_MONGODB_USER> | ||
MONGODB_PASSWORD=<YOUR_MONGODB_PASSWORD> | ||
MONGODB_PROJECT_URL=<YOUR_PROJECT_URL> | ||
MONGODB_APP_NAME=LeafyGreenAI | ||
|
||
VECTOR_SEARCH_INDEX_NAME="vector_index" # or whatever your index name is | ||
MONGODB_DATABASE_NAME="mongodb-chatbot-framework-chatbot" # or whatever your database name is. must contain vector search index. | ||
|
||
# Azure OpenAI config | ||
AZURE_OPENAI_API_KEY=<YOUR_AZURE_API_KEY1> | ||
AZURE_OPENAI_API_KEY=<YOUR_AZURE_API_KEY2> | ||
AZURE_OPENAI_ENDPOINT=https://<your-instance>.openai.azure.com/ | ||
|
||
AZURE_OPENAI_EMBEDDING_MODEL=text-embedding-ada-002 | ||
AZURE_OPENAI_API_EMBEDDING_DEPLOYMENT_NAME=text-embedding-ada-002 | ||
AZURE_OPENAI_API_EMBEDDING_DEPLOYMENT_URL=https://<your-instance>.openai.azure.com/openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-05-15 | ||
|
||
AZURE_OPENAI_CHAT_COMPLETION_MODEL=gpt-4.1 | ||
AZURE_OPENAI_API_CHAT_COMPLETION_DEPLOYMENT_NAME=gpt-4.1 | ||
AZURE_OPENAI_API_CHAT_COMPLETION_DEPLOYMENT_URL=https://<your-instance>.openai.azure.com/openai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# ts build | ||
build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "lg-chatbot-server", | ||
"version": "0.0.1", | ||
"description": "", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"module": "dist/esm/index.js", | ||
"publishConfig": { | ||
"access": "restricted" | ||
}, | ||
"scripts": { | ||
"build": "lg build-package", | ||
"tsc": "lg build-ts", | ||
"ingest": "pnpm build && ingest all --config ./dist/esm/ingest.config.js", | ||
"dev": "tsx src/index.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@emotion/css": "^11.13.5", | ||
TheSonOfThomp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@lg-tools/crawler": "workspace:^", | ||
"dotenv": "^16.5.0", | ||
"express": "^4.18.2", | ||
"jsdom": "^26.1.0", | ||
"lodash-es": "^4.17.21", | ||
"mongodb-chatbot-server": "^0.11.0", | ||
"mongodb-rag-core": "^0.7.0" | ||
}, | ||
"devDependencies": { | ||
"mongodb-rag-ingest": "^0.3.1", | ||
"nodemon": "^3.0.1", | ||
"tsx": "^4.19.4", | ||
"typescript": "^5.8.0" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { esmConfig, umdConfig } from '@lg-tools/build/config/rollup.config.mjs'; | ||
|
||
const ingestESMConfig = { | ||
...esmConfig, | ||
input: './src/ingest/ingest.config.ts', | ||
}; | ||
|
||
export default [esmConfig, umdConfig, ingestESMConfig]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
AppConfig, | ||
logger, | ||
makeApp, | ||
SystemPrompt, | ||
} from 'mongodb-chatbot-server'; | ||
|
||
import { initChatBot } from './init'; | ||
|
||
// System prompt for chatbot | ||
const systemPrompt: SystemPrompt = { | ||
role: 'system', | ||
content: `You are an assistant to engineers and product designers using the LeafyGreen design system. | ||
Answer their questions about the framework in a friendly conversational tone. | ||
|
||
For questions regarding engineering, and react components, provide code examples. | ||
For questions regarding design and UX guidelines, provide sources. | ||
|
||
Format your answers in Markdown. | ||
Be concise in your answers. | ||
`, | ||
}; | ||
|
||
// Start the server and clean up resources on SIGINT. | ||
const PORT = process.env.PORT || 3030; | ||
|
||
const startServer = async () => { | ||
const { | ||
llm, | ||
embeddedContentStore, | ||
generateUserPrompt, | ||
mongodbClient, | ||
conversations, | ||
} = await initChatBot(); | ||
|
||
// Create the MongoDB Chatbot Server Express.js app configuration | ||
const config: AppConfig = { | ||
conversationsRouterConfig: { | ||
llm, | ||
conversations, | ||
generateUserPrompt, | ||
systemPrompt, | ||
}, | ||
maxRequestTimeoutMs: 30000, | ||
}; | ||
|
||
logger.info('Starting server...'); | ||
const app = await makeApp(config); | ||
const server = app.listen(PORT, () => { | ||
logger.info(`Server listening on port: ${PORT}`); | ||
}); | ||
|
||
process.on('SIGINT', async args => { | ||
logger.info('SIGINT signal received', args); | ||
await mongodbClient.close(); | ||
await embeddedContentStore.close(); | ||
await new Promise<void>((resolve, reject) => { | ||
server.close((error: any) => { | ||
error ? reject(error) : resolve(); | ||
}); | ||
}); | ||
process.exit(1); | ||
}); | ||
}; | ||
|
||
try { | ||
startServer(); | ||
} catch (e) { | ||
logger.error(`Fatal error: ${e}`); | ||
process.exit(1); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
makeMongoDbEmbeddedContentStore, | ||
makeMongoDbPageStore, | ||
} from 'mongodb-rag-core'; | ||
import { Config, makeIngestMetaStore } from 'mongodb-rag-ingest'; | ||
|
||
import { loadEnvVars } from '../utils/loadEnv'; | ||
import { makeEmbedder } from '../utils/makeEmbedder'; | ||
|
||
import { leafygreenGithubSourceConstructor } from './sources/github-leafygreen-ui'; | ||
import { webSourceConstructor } from './utils/webSourceConstructor'; | ||
|
||
// Load project environment variables | ||
const { | ||
MONGODB_CONNECTION_URI, | ||
MONGODB_DATABASE_NAME, | ||
AZURE_OPENAI_EMBEDDING_MODEL, | ||
} = loadEnvVars(); | ||
|
||
export default { | ||
embedder: () => makeEmbedder(), | ||
embeddedContentStore: () => | ||
makeMongoDbEmbeddedContentStore({ | ||
connectionUri: MONGODB_CONNECTION_URI, | ||
databaseName: MONGODB_DATABASE_NAME, | ||
searchIndex: { | ||
embeddingName: AZURE_OPENAI_EMBEDDING_MODEL, | ||
}, | ||
}), | ||
pageStore: () => | ||
makeMongoDbPageStore({ | ||
connectionUri: MONGODB_CONNECTION_URI, | ||
databaseName: MONGODB_DATABASE_NAME, | ||
}), | ||
ingestMetaStore: () => | ||
makeIngestMetaStore({ | ||
connectionUri: MONGODB_CONNECTION_URI, | ||
databaseName: MONGODB_DATABASE_NAME, | ||
entryId: 'all', | ||
}), | ||
chunkOptions: () => ({ | ||
minChunkSize: 15, | ||
maxChunkSize: 1000, | ||
overlap: 100, | ||
}), | ||
// Add data sources here | ||
dataSources: async () => { | ||
return Promise.all([ | ||
...[ | ||
'https://mongodb.design', | ||
'https://react.dev/reference/react', | ||
'https://developer.mozilla.org/en-US/docs/Web', | ||
'https://css-tricks.com/category/articles', | ||
'https://www.nngroup.com/articles', | ||
'https://www.w3.org/WAI/standards-guidelines/wcag', | ||
'https://atomicdesign.bradfrost.com/table-of-contents', | ||
].map(source => webSourceConstructor(source, {})), | ||
leafygreenGithubSourceConstructor(), | ||
]); | ||
}, | ||
} satisfies Config; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.