Skip to content

Commit

Permalink
Add context
Browse files Browse the repository at this point in the history
  • Loading branch information
msveshnikov committed Mar 17, 2024
1 parent 62e83cc commit 375107e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
7 changes: 5 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })),
}),
}
);

Expand Down Expand Up @@ -53,7 +56,7 @@ function App() {
}, [chatHistory]);

return (
<Container maxWidth="md" style={{ display: "flex", flexDirection: "column", height: "95vh" }}>
<Container maxWidth="md" style={{ display: "flex", flexDirection: "column", height: "97vh" }}>
<Box flex={1} overflow="auto" padding={2} display="flex" flexDirection="column" ref={chatContainerRef}>
{chatHistory.map((chat, index) => (
<Box key={index} display="flex" flexDirection="column" marginBottom={2}>
Expand Down

0 comments on commit 375107e

Please sign in to comment.