diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index a0dceed1..613f8879 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -18,17 +18,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@master - name: Build and Push Backend Image run: | - docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} ./backend + docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} ./server docker login -u ${{ env.DOCKER_USERNAME }} -p ${{ env.DOCKER_PASSWORD }} docker push ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} - name: Build and Push Frontend Image run: | - docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} ./frontend + docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} . docker push ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} deploy: diff --git a/server/index.js b/server/index.js index bdc3619d..da2fc0fb 100644 --- a/server/index.js +++ b/server/index.js @@ -11,28 +11,27 @@ const port = 5000; app.use(cors()); app.use(express.json()); -// Custom Morgan format to log request bodies morgan.token("body", (req) => JSON.stringify(req.body)); - const loggerFormat = ":method :url :status :response-time ms - :res[content-length] :body"; - app.use(morgan(loggerFormat)); const limiter = rateLimit({ - windowMs: 60 * 1000, // 1 minute - max: 10, // Limit each IP to 10 requests per windowMs + windowMs: 60 * 1000, + max: 10, message: "Too many requests from this IP, please try again after a minute", }); -// Apply the rate limiter to all requests app.use(limiter); - app.post("/interact", async (req, res) => { let userInput = req.body.input; + const chatHistory = req.body.chatHistory || []; const temperature = req.body.temperature || 0.5; try { - const textResponse = await getTextGemini(userInput, temperature); + const contextPrompt = `${chatHistory + .map((chat) => `${chat.user}\n${chat.assistant}`) + .join("\n")}\n\nHuman: ${userInput}\nAssistant:`; + const textResponse = await getTextGemini(contextPrompt, temperature); userInput = userInput?.toLowerCase(); let imageResponse; if (userInput.includes("paint") || userInput.includes("draw") || userInput.includes("generate")) { diff --git a/src/App.js b/src/App.js index 5bc0689b..3e66b3b3 100644 --- a/src/App.js +++ b/src/App.js @@ -23,7 +23,10 @@ function App() { headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ input }), + body: JSON.stringify({ + input, + chatHistory: chatHistory.map((h) => ({ user: h.user, assistant: h.assistant })), + }), } ); @@ -53,7 +56,7 @@ function App() { }, [chatHistory]); return ( - + {chatHistory.map((chat, index) => (