Skip to content

Commit

Permalink
adds a frontend to use the tour guide assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeximenes committed Aug 23, 2024
1 parent 4f36860 commit 078132a
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 45 deletions.
4 changes: 2 additions & 2 deletions example/assets/js/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
IconMovie,
IconChecklist,
} from "@tabler/icons-react";
import { Chat, ResultsPage } from "@/components";
import { Chat, TourGuide } from "@/components";
import { createBrowserRouter, Link, RouterProvider } from "react-router-dom";
import {
ApiError,
Expand Down Expand Up @@ -203,7 +203,7 @@ const router = createBrowserRouter([
},
{
path: "/tour-guide",
element: (<PageWrapper><ResultsPage assistantId="tour_guide_assistant" /></PageWrapper>),
element: (<PageWrapper><TourGuide assistantId="tour_guide_assistant" /></PageWrapper>),
},
{
path: "/admin",
Expand Down
1 change: 0 additions & 1 deletion example/assets/js/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ActionIcon,
Avatar,
Box,
Button,
Container,
Group,
Expand Down
36 changes: 0 additions & 36 deletions example/assets/js/components/ResultsPage/ResultsPage.tsx

This file was deleted.

53 changes: 53 additions & 0 deletions example/assets/js/components/TourGuide/TourGuide.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import "@mantine/core/styles.css";
import { Container } from "@mantine/core";
import axios from 'axios';
import { useEffect, useState } from "react";


export function TourGuide() {
const [latitude, setLatitude] = useState("");
const [longitude, setLongitude] = useState("");
const [attractions, setAttractions] = useState([]);
const [loading, setLoading] = useState(false);

navigator.geolocation.getCurrentPosition((position: any) => {
if (latitude && longitude) {
return;
}
setLatitude(position.coords.latitude);
setLongitude(position.coords.longitude);
}, (error) => console.log(error));

function findAttractions() {
if (!latitude || !longitude) {
return;
}

setLoading(true)
axios.get(`/tour-guide/?coordinate=${latitude},${longitude}`)
.then((response: any) => {
setAttractions(response.data.nearby_attractions)
}).finally(() => setLoading(false))
}

console.log(attractions)

return (
<Container>
Latitude: <input type="text" value={latitude} onChange={(e) => setLatitude(e.target.value)} />
Longitude: <input type="text" value={longitude} onChange={(e) => setLongitude(e.target.value)} />
<button onClick={findAttractions}>Guide Me!</button>
{loading ? <h3>Loading</h3> : null}
<div>
{attractions.map((item, i) =>
<div key={i}>
<h2>{item.attraction_url ? <a href={item.attraction_url}>{item.attraction_name}</a> : item.attraction_name }</h2>
<span>{item.attraction_description}</span>

</div>
)}
</div>
</Container>
);
};

2 changes: 1 addition & 1 deletion example/assets/js/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ThreadsNav } from "./ThreadsNav/ThreadsNav";
export { Chat } from "./Chat/Chat";
export { ResultsPage } from "./ResultsPage/ResultsPage";
export { TourGuide } from "./TourGuide/TourGuide";
1 change: 0 additions & 1 deletion example/demo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,5 @@ def get(self, request, *args, **kwargs):

a = TourGuideAIAssistant()
data = a.run(f"My coordinates are: ({coordinates})", thread.id)
print(data)

return JsonResponse(json.loads(data))
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@mantine/hooks": "^7.11.0",
"@mantine/notifications": "^7.11.0",
"@tabler/icons-react": "^3.7.0",
"axios": "^1.7.5",
"cookie": "^0.6.0",
"django-ai-assistant-client": "0.0.1",
"modern-normalize": "^2.0.0",
Expand Down
11 changes: 7 additions & 4 deletions example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 078132a

Please sign in to comment.