From e333115ecf5044b319150de8537826250eba035e Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Tue, 1 Oct 2024 21:10:49 -0300 Subject: [PATCH 1/2] Minor tour guide UI refactor --- .../js/components/TourGuide/TourGuide.tsx | 95 ++++++++++++------- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/example/assets/js/components/TourGuide/TourGuide.tsx b/example/assets/js/components/TourGuide/TourGuide.tsx index 1baecc1..a0a7225 100644 --- a/example/assets/js/components/TourGuide/TourGuide.tsx +++ b/example/assets/js/components/TourGuide/TourGuide.tsx @@ -1,21 +1,30 @@ -import "@mantine/core/styles.css"; +import { useEffect, useState } from "react"; +import { Link } from "react-router-dom"; import { - Container, - TextInput, Button, - LoadingOverlay, + Card, + Container, + Flex, Group, + LoadingOverlay, + Text, + TextInput, + Title, } from "@mantine/core"; -import { useEffect, useState } from "react"; import { notifications } from "@mantine/notifications"; -import { Link } from "react-router-dom"; + +interface Attraction { + attraction_name: string; + attraction_description: string; + attraction_url: string; +} export function TourGuide() { const [showLoginNotification, setShowLoginNotification] = useState(false); const [latitude, setLatitude] = useState(""); const [longitude, setLongitude] = useState(""); - const [attractions, setAttractions] = useState([]); + const [attractions, setAttractions] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { @@ -34,14 +43,16 @@ export function TourGuide() { } setLoading(true); - const response = await fetch(`/tour-guide/?coordinate=${latitude},${longitude}`); + const response = await fetch( + `/tour-guide/?coordinate=${latitude},${longitude}` + ); const data = await response.json(); if (data.error) { setShowLoginNotification(true); } else { setAttractions(data.nearby_attractions); } - setLoading(false) + setLoading(false); } useEffect(() => { @@ -67,7 +78,12 @@ export function TourGuide() { return ( - + + + Tour Guide + + + - {loading ?

Loading

: null} -
- {attractions.map((item, i) => ( -
-

- {item.attraction_url ? ( - - {item.attraction_name} - - ) : ( - item.attraction_name - )} -

- {item.attraction_description} - -
+ + + {attractions.map((attraction, index) => ( + + + {attraction.attraction_name} + + + {attraction.attraction_description} + + + ))} -
+
); } From c664dc18759dc52bc7ffc4246e5bdc6f5432d792 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Tue, 1 Oct 2024 22:15:28 -0300 Subject: [PATCH 2/2] Rename attributes --- .../js/components/TourGuide/TourGuide.tsx | 34 +++++++++---------- example/tour_guide/ai_assistants.py | 8 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/example/assets/js/components/TourGuide/TourGuide.tsx b/example/assets/js/components/TourGuide/TourGuide.tsx index a0a7225..5c2a096 100644 --- a/example/assets/js/components/TourGuide/TourGuide.tsx +++ b/example/assets/js/components/TourGuide/TourGuide.tsx @@ -12,11 +12,12 @@ import { Title, } from "@mantine/core"; import { notifications } from "@mantine/notifications"; +import { IconLocation, IconMap2 } from "@tabler/icons-react"; interface Attraction { - attraction_name: string; - attraction_description: string; - attraction_url: string; + name: string; + description: string; + url: string; } export function TourGuide() { @@ -83,7 +84,7 @@ export function TourGuide() { Tour Guide - + setLongitude(e.target.value)} /> - + - + {attractions.map((attraction, index) => ( - - {attraction.attraction_name} + + {attraction.name} - {attraction.attraction_description} + {attraction.description} diff --git a/example/tour_guide/ai_assistants.py b/example/tour_guide/ai_assistants.py index c91dd85..a1802e8 100644 --- a/example/tour_guide/ai_assistants.py +++ b/example/tour_guide/ai_assistants.py @@ -9,11 +9,11 @@ class Attraction(BaseModel): - attraction_name: str = Field(description="The name of the attraction in english") - attraction_description: str = Field( + name: str = Field(description="The name of the attraction in english") + description: str = Field( description="The description of the attraction, provide information in an entertaining way" ) - attraction_url: str = Field( + url: str = Field( description="The URL of the attraction, keep empty if you don't have this information" ) @@ -31,7 +31,7 @@ class TourGuideAIAssistant(AIAssistant): "Only include in your response the items that are relevant to a tourist visiting the area. " "Only call the find_nearby_attractions tool once. " ) - model = "gpt-4o-2024-08-06" + model = "gpt-4o-mini" structured_output = TourGuide def get_instructions(self):