Skip to content

Commit

Permalink
separate chat server package and implementation + update drone file
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodben committed Oct 30, 2023
1 parent 5559403 commit 4441cbf
Show file tree
Hide file tree
Showing 51 changed files with 1,068 additions and 134 deletions.
56 changes: 30 additions & 26 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trigger:
- ingest/**/*
- scripts/**/*
- ingest-mongodb-public/**/*
- chatbot-server-mongodb-public/**/*

steps:
- name: test
Expand Down Expand Up @@ -71,12 +72,13 @@ trigger:
paths:
include:
- chat-server/**/*
- chatbot-server-mongodb-public/**/*
- chat-core/**/*
- chat-ui/**/*

steps:
# Builds and publishes Docker image for staging
- name: publish-staging-chat-server
- name: publish-staging-chatbot-server-mongodb-public
image: plugins/kaniko-ecr
environment:
LG_ARTIFACTORY_PASSWORD:
Expand Down Expand Up @@ -116,7 +118,7 @@ steps:
---
kind: pipeline
type: kubernetes
name: staging-deploy-chat-server
name: staging-deploy-chatbot-server-mongodb-public

trigger:
event:
Expand All @@ -126,6 +128,7 @@ trigger:
paths:
include:
- chat-server/**/*
- chatbot-server-mongodb-public/**/*
- chat-core/**/*
- chat-ui/**/*
branch:
Expand All @@ -142,26 +145,26 @@ steps:
namespace: docs
release: chat-server-staging
values: image.tag=git-${DRONE_COMMIT_SHA:0:7}-staging,image.repository=795250896452.dkr.ecr.us-east-1.amazonaws.com/docs/${DRONE_REPO_NAME}-chat-server,ingress.enabled=true,ingress.hosts[0]=chat-server.docs.staging.corp.mongodb.com
values_files: ["chat-server/environments/staging.yml"]
values_files: ["chatbot-server-mongodb-public/environments/staging.yml"]
api_server: https://api.staging.corp.mongodb.com
kubernetes_token:
from_secret: staging_kubernetes_token
---
depends_on: ["test-all"]
kind: pipeline
type: kubernetes
name: qa-build-chat-server
name: qa-build-chatbot-server-mongodb-public

trigger:
event:
- tag
ref:
include:
- refs/tags/chat-server-qa-*
- refs/tags/chatbot-server-mongodb-public-qa-*

steps:
# Builds and publishes Docker image for qa
- name: publish-qa-chat-server
- name: publish-qa-chatbot-server-mongodb-public
image: plugins/kaniko-ecr
environment:
ENVIRONMENT: qa
Expand Down Expand Up @@ -190,7 +193,7 @@ steps:
from_secret: ecr_secret_key

# Promotes current drone build to staging environment (QA server is in staging namespace)
- name: promote-qa-chat-server
- name: promote-qa-chatbot-server-mongodb-public
image: drone/cli:1.4.0-alpine
commands:
- drone build promote mongodb/chatbot ${DRONE_BUILD_NUMBER} staging
Expand All @@ -202,19 +205,19 @@ steps:
---
kind: pipeline
type: kubernetes
name: qa-deploy-chat-server
name: qa-deploy-chatbot-server-mongodb-public

trigger:
event:
- promote
target:
- staging
ref:
- refs/tags/chat-server-qa-*
- refs/tags/chatbot-server-mongodb-public-qa-*

steps:
# Deploys docker image associated with staging build that triggered promotion
- name: deploy-qa-chat-server
- name: deploy-qa-chatbot-server-mongodb-public
image: quay.io/mongodb/drone-helm:v3
settings:
chart: mongodb/web-app
Expand All @@ -232,18 +235,18 @@ steps:
depends_on: ["test-all"]
kind: pipeline
type: kubernetes
name: production-build-chat-server
name: production-build-chatbot-server-mongodb-public

trigger:
event:
- tag
ref:
include:
- refs/tags/chat-server-v*
- refs/tags/chatbot-server-mongodb-public-v*

steps:
# Builds and publishes Docker image for production
- name: publish-production-chat-server
- name: publish-production-chatbot-server-mongodb-public
image: plugins/kaniko-ecr
environment:
LG_ARTIFACTORY_PASSWORD:
Expand Down Expand Up @@ -282,7 +285,7 @@ steps:
---
kind: pipeline
type: kubernetes
name: production-deploy-chat-server
name: production-deploy-chatbot-server-mongodb-public

trigger:
event:
Expand All @@ -295,7 +298,7 @@ trigger:

steps:
# Deploys Docker image associated with production build that triggered promotion
- name: deploy-production-chat-server
- name: deploy-production-chatbot-server-mongodb-public
image: quay.io/mongodb/drone-helm:v3
settings:
chart: mongodb/web-app
Expand All @@ -304,7 +307,8 @@ steps:
namespace: docs
release: docs-chat
values: image.tag=git-${DRONE_COMMIT_SHA:0:7}-production,image.repository=795250896452.dkr.ecr.us-east-1.amazonaws.com/docs/${DRONE_REPO_NAME}-chat-server,ingress.enabled=true,ingress.hosts[0]=chat-server.docs.prod.corp.mongodb.com
values_files: ["chat-server/environments/production.yml"]
values_files:
["chatbot-server-mongodb-public/environments/production.yml"]
api_server: https://api.prod.corp.mongodb.com
kubernetes_token:
from_secret: prod_kubernetes_token
Expand All @@ -316,12 +320,11 @@ steps:
depends_on: ["test-all"]
kind: pipeline
type: kubernetes
name: staging-build-ingest-service
name: staging-build-mongodb-rag-ingest

trigger:
branch:
- main
- ingest-plugins # REMOVE ME
event:
- push
paths:
Expand All @@ -332,7 +335,7 @@ trigger:

steps:
# Builds and publishes Docker image for staging
- name: publish-staging-ingest-service
- name: publish-staging-mongodb-rag-ingest
image: plugins/kaniko-ecr
environment:
LG_ARTIFACTORY_PASSWORD:
Expand All @@ -359,7 +362,7 @@ steps:
from_secret: ecr_secret_key

# Promotes current drone build to staging environment
- name: promote-staging-ingest-service
- name: promote-staging-mongodb-rag-ingest
image: drone/cli:1.4.0-alpine
commands:
- drone build promote mongodb/chatbot ${DRONE_BUILD_NUMBER} staging
Expand All @@ -371,7 +374,7 @@ steps:
---
kind: pipeline
type: kubernetes
name: staging-deploy-ingest-service
name: staging-deploy-mongodb-rag-ingest

trigger:
event:
Expand All @@ -381,6 +384,7 @@ trigger:
paths:
include:
- ingest/**/*
- ingest-mongodb-public/**/*
- chat-core/**/*
branch:
- main
Expand All @@ -406,7 +410,7 @@ steps:
depends_on: ["test-all"]
kind: pipeline
type: kubernetes
name: production-build-ingest-service
name: production-build-mongodb-rag-ingest

trigger:
event:
Expand All @@ -417,7 +421,7 @@ trigger:

steps:
# Builds and publishes Docker image for production
- name: publish-production-ingest-service
- name: publish-production-mongodb-rag-ingest
image: plugins/kaniko-ecr
environment:
LG_ARTIFACTORY_PASSWORD:
Expand All @@ -444,7 +448,7 @@ steps:
from_secret: ecr_secret_key

# Promotes current drone build to production environment
- name: promote-production-ingest-service
- name: promote-production-mongodb-rag-ingest
image: drone/cli:1.4.0-alpine
commands:
- drone build promote mongodb/chatbot ${DRONE_BUILD_NUMBER} production
Expand All @@ -456,7 +460,7 @@ steps:
---
kind: pipeline
type: kubernetes
name: production-deploy-ingest-service
name: production-deploy-mongodb-rag-ingest

trigger:
event:
Expand All @@ -465,7 +469,7 @@ trigger:
- production
ref:
include:
- refs/tags/ingest-v*
- refs/tags/mongodb-rag-ingest-v*

steps:
- name: deploy-production-ingest-service
Expand Down
13 changes: 8 additions & 5 deletions chat-server.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ RUN npm install lerna && npm run bootstrap && npm run build
FROM node:18-alpine as main
WORKDIR /app

# OSS_REFACTOR_TODO: this will probably need work
# need to do something to ready up mongodb-chatbot-server
COPY --from=builder /app/chat-core ./chat-core/
COPY --from=builder /app/chat-server ./chat-server/
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/chat-server/package*.json ./chat-server/
COPY --from=builder /app/chat-server/static ./chat-server/static
COPY --from=builder /app/chat-server/dist ./chat-server/dist
COPY --from=builder /app/chat-server/node_modules ./chat-server/node_modules
COPY --from=builder /app/chatbot-server-mongodb-public/package*.json ./chatbot-server-mongodb-public/
COPY --from=builder /app/chatbot-server-mongodb-public/static ./chatbot-server-mongodb-public/static
COPY --from=builder /app/chatbot-server-mongodb-public/dist ./chatbot-server-mongodb-public/dist
COPY --from=builder /app/chatbot-server-mongodb-public/node_modules ./chatbot-server-mongodb-public/node_modules

EXPOSE 3000
WORKDIR /app/chat-server
WORKDIR /app/chatbot-server-mongodb-public
CMD ["npm", "start"]
14 changes: 4 additions & 10 deletions chat-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
"name": "mongodb-chatbot-server",
"version": "0.1.7",
"license": "Apache-2.0",
"description": "Q&A server for the MongoDB Docs AI chatbot.",
"description": "A chatbot server for retrieval augmented generation (RAG).",
"author": "MongoDB, Inc.",
"keywords": [],
"engines": {
"node": ">=18",
"npm": ">=8"
},
"main": "./dist/lib.js",
"main": "./dist/index.js",
"scripts": {
"build": "rm -rf ./dist/ && tsc",
"postbuild": "cp ./src/processors/MongoDbUserQueryPreprocessorResponse.ts ./dist/processors/",
"dev": "nodemon src/index.ts",
"format": "prettier ./src --write",
"format:check": "prettier ./src --check",
"lint": "eslint ./src --ext js,jsx,ts,tsx --report-unused-disable-directives",
"start": "pm2-runtime ./dist/index.js",
"test": "jest --forceExit",
"test:llmQualitative": "jest --config jest.config.llmQualitative.js --forceExit src/llmQualitativeTests/qualitative.test.ts",
"test:llmQualitative:top": "RUN_TOP=true npm run test:llmQualitative",
"test:llmQualitative:utils": "RUN_TOP=true jest --config jest.config.llmQualitative.js --forceExit --testPathIgnorePatterns src/llmQualitativeTests/qualitative.test.ts",
"release": "release-it"
},
"dependencies": {
Expand All @@ -45,8 +39,8 @@
"winston": "^3.9.0",
"zod-error": "^1.5.0"
},
"bundleDependencies": [
"chat-core"
"bundledDependencies": [
"mongodb-rag-core"
],
"devDependencies": {
"@babel/core": "^7.22.5",
Expand Down
13 changes: 0 additions & 13 deletions chat-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { stripIndents } from "common-tags";
import { AppConfig } from "./app";
import { makeBoostOnAtlasSearchFilter } from "./processors/makeBoostOnAtlasSearchFilter";
import { CORE_ENV_VARS, assertEnvVars } from "mongodb-rag-core";
import { makePreprocessMongoDbUserQuery } from "./processors/makePreprocessMongoDbUserQuery";
import { AzureKeyCredential, OpenAIClient } from "@azure/openai";
import { OpenAiChatMessage, SystemPrompt } from "./services/ChatLlm";
import { makeDefaultFindContentFunc } from "./routes/conversations/FindContentFunc";
Expand Down Expand Up @@ -119,17 +118,6 @@ export const llm = makeOpenAiChatLlm({
generateUserPrompt,
});

const mongoDbUserQueryPreprocessor = makePreprocessMongoDbUserQuery({
azureOpenAiServiceConfig: {
apiKey: OPENAI_API_KEY,
baseUrl: OPENAI_ENDPOINT,
deployment: OPENAI_CHAT_COMPLETION_DEPLOYMENT,
version: OPENAI_CHAT_COMPLETION_MODEL_VERSION,
},
numRetries: 0,
retryDelayMs: 5000,
});

export const dataStreamer = makeDataStreamer();

export const embeddedContentStore = makeMongoDbEmbeddedContentStore({
Expand Down Expand Up @@ -192,7 +180,6 @@ export const config: AppConfig = {
dataStreamer,
llm,
findContent,
userQueryPreprocessor: mongoDbUserQueryPreprocessor,
maxChunkContextTokens: 1500,
conversations,
makeReferenceLinks: makeMongoDbReferences,
Expand Down
Loading

0 comments on commit 4441cbf

Please sign in to comment.