Skip to content

Commit

Permalink
#3 Updated LLM message.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaVidakovic committed Jun 8, 2024
1 parent e72d09e commit a11f869
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 1 addition & 5 deletions backend/src/test_gen/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def lambda_handler(event, context):
body = json.loads(event.get("body", "{}"))
user_id = body.get("UserID")
chat_id = body.get("ChatID")
question = body.get("Question")

if not user_id or not question or not chat_id:
if not user_id or not chat_id:
logger.error("Missing UserID, ChatID or Question in the request")
return {
"statusCode": 400,
Expand Down Expand Up @@ -81,9 +80,6 @@ def lambda_handler(event, context):
messages.append({"role": "user", "content": item["Question"]})
messages.append({"role": "assistant", "content": item["AIResponse"]})

# Add the current question to the messages
messages.append({"role": "user", "content": question})

ai_response = get_gpt_answer(messages)

# Generate UUID for QuestionID
Expand Down
34 changes: 33 additions & 1 deletion frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from 'react';
import { IonButtons, IonContent, IonHeader, IonMenuButton, IonPage, IonToolbar, IonFooter, IonItem, IonIcon, IonCard, IonCardContent } from '@ionic/react';
import { IonButtons, IonContent, IonHeader, IonMenuButton, IonPage, IonToolbar, IonFooter, IonItem, IonIcon, IonCard, IonCardContent, IonButton } from '@ionic/react';
import { sendOutline } from 'ionicons/icons';
import './Home.css';

Expand Down Expand Up @@ -101,6 +101,35 @@ const Home: React.FC<HomeProps> = ({ user, chatID }) => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};

const handleGenerateText = async () => {
try {
if (!user.username || !chatID) {
throw new Error('Missing user or chat ID');
}

const response = await fetch('https://225aetnmd3.execute-api.eu-central-1.amazonaws.com/Prod/gentest', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
UserID: user.username,
ChatID: chatID,
}),
});

if (!response.ok) {
throw new Error('Network response was not ok');
}

const data = await response.json();
const generatedMessage = { text: data.Response, sender: 'bot' as const };
setMessages((prevMessages) => [...prevMessages, generatedMessage]);
} catch (error) {
console.error('Error generating text:', error);
}
};

useEffect(() => {
scrollToBottom();
}, [messages]);
Expand Down Expand Up @@ -151,6 +180,9 @@ const Home: React.FC<HomeProps> = ({ user, chatID }) => {
onClick={handleSend}
style={{ pointerEvents: waitingForResponse ? 'none' : 'auto', cursor: waitingForResponse ? 'not-allowed' : 'pointer' }}
/>
<IonButton slot="end" onClick={handleGenerateText}>
Generate Test
</IonButton>
</IonItem>
</IonCard>
</IonFooter>
Expand Down
2 changes: 1 addition & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ Outputs:
Value:
Fn::Sub: "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/Prod/createChat"

GetChatsUrl:
GetChatsUrl:testgentestgen
Description: "API Gateway endpoint URL for getting user chats"
Value:
Fn::Sub: "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/Prod/getChats"
Expand Down

0 comments on commit a11f869

Please sign in to comment.