Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor of the Tour Guide UI #176

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 62 additions & 35 deletions example/assets/js/components/TourGuide/TourGuide.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
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";
import { IconLocation, IconMap2 } from "@tabler/icons-react";

interface Attraction {
name: string;
description: string;
url: string;
}

export function TourGuide() {
const [showLoginNotification, setShowLoginNotification] =
useState<boolean>(false);
const [latitude, setLatitude] = useState("");
const [longitude, setLongitude] = useState("");
const [attractions, setAttractions] = useState([]);
const [attractions, setAttractions] = useState<Attraction[]>([]);
const [loading, setLoading] = useState(false);

useEffect(() => {
Expand All @@ -34,14 +44,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(() => {
Expand All @@ -67,7 +79,12 @@ export function TourGuide() {
return (
<Container>
<LoadingOverlay visible={loading} />
<Group justify="left" align="flex-end">

<Title mt="md" order={2}>
Tour Guide
</Title>

<Group justify="left" align="flex-end" mb="xl">
<TextInput
required
label="Latitude"
Expand All @@ -80,33 +97,43 @@ export function TourGuide() {
value={longitude}
onChange={(e) => setLongitude(e.target.value)}
/>
<Button onClick={findAttractions}>Guide Me!</Button>
<Button
leftSection={<IconMap2 size={18} stroke={1.5} />}
onClick={findAttractions}
>
Guide Me!
</Button>
</Group>
{loading ? <h3>Loading</h3> : null}
<div>
{attractions.map((item, i) => (
<div key={i}>
<h2>
{item.attraction_url ? (
<a href={item.attraction_url} target="_blank">
{item.attraction_name}
</a>
) : (
item.attraction_name
)}
</h2>
<span>{item.attraction_description}</span>
<div>
<a
href={`https://www.google.com/maps?q=${item.attraction_name}`}
target="_blank"
>
Open in Google Maps
</a>
</div>
</div>

<Flex gap="md" align="flex-start" direction="row" wrap="wrap" miw={460}>
{attractions.map((attraction, index) => (
<Card
key={index}
w={280}
shadow="sm"
padding="lg"
radius="md"
withBorder
>
<Text fw={500} size="lg" mt="md" mb="xs">
{attraction.name}
</Text>
<Text size="sm" c="dimmed" mb="md">
{attraction.description}
</Text>
<Button
component="a"
href={`https://www.google.com/maps/search/?api=1&query=${attraction.name}`}
target="_blank"
rel="noopener noreferrer"
variant="light"
leftSection={<IconLocation size={18} stroke={1.5} />}
>
View on Google Maps
</Button>
</Card>
))}
</div>
</Flex>
</Container>
);
}
8 changes: 4 additions & 4 deletions example/tour_guide/ai_assistants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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):
Expand Down