Skip to content

Commit

Permalink
Clean up puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
msveshnikov committed Mar 25, 2024
1 parent b70466d commit 1816a1b
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 1,443 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- name: Install dependencies
run: npm ci

# - name: Run tests
# run: npm run test
- name: Run tests
run: npm run test

- name: Build and Push Backend Image
if: success()
Expand Down
7 changes: 2 additions & 5 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
FROM node:20.9.0-bullseye

RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update && apt-get install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils -y

# Use the official Node.js image as the base image
FROM node:20-slim

# Set the working directory in the container
WORKDIR /app
Expand Down
9 changes: 6 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import promBundle from "express-prom-bundle";
import { authenticateUser, registerUser, verifyToken } from "./auth.js";
import mongoose from "mongoose";
import { countCharacters, countTokens, storeUsageStats } from "./model/User.js";
import { fetchSearchResults } from "./search.js";
import { fetchPageContent, fetchSearchResults } from "./search.js";

const MAX_CONTEXT_LENGTH = 8000;
const systemPrompt = `You are an AI assistant that interacts with the Gemini Pro and Claude Haiku language models. Your capabilities include:
Expand Down Expand Up @@ -112,15 +112,18 @@ app.post("/interact", verifyToken, async (req, res) => {
}

let searchResults = [];
let topResultContent = "";
if (userInput?.toLowerCase()?.includes("search") || userInput?.toLowerCase()?.includes("google")) {
const searchQuery = userInput.replace("search", "").trim();
searchResults = await fetchSearchResults(searchQuery);
console.log(searchResults);
if (searchResults.length > 0) {
topResultContent = await fetchPageContent(searchResults[0].link);
}
}

const contextPrompt = `System: ${systemPrompt} ${chatHistory
.map((chat) => `Human: ${chat.user}\nAssistant:${chat.assistant}`)
.join("\n")}\n\nHuman: ${userInput}\nAssistant:`.slice(-MAX_CONTEXT_LENGTH);
.join("\n")}\n\n${topResultContent}\nHuman: ${userInput}\nAssistant:`.slice(-MAX_CONTEXT_LENGTH);

let textResponse;
let inputTokens = 0;
Expand Down
Loading

0 comments on commit 1816a1b

Please sign in to comment.