diff --git a/example/assets/js/App.tsx b/example/assets/js/App.tsx index 03983df..6afe750 100644 --- a/example/assets/js/App.tsx +++ b/example/assets/js/App.tsx @@ -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, @@ -203,7 +203,7 @@ const router = createBrowserRouter([ }, { path: "/tour-guide", - element: (), + element: (), }, { path: "/admin", diff --git a/example/assets/js/components/Chat/Chat.tsx b/example/assets/js/components/Chat/Chat.tsx index a871912..1ab333f 100644 --- a/example/assets/js/components/Chat/Chat.tsx +++ b/example/assets/js/components/Chat/Chat.tsx @@ -1,7 +1,6 @@ import { ActionIcon, Avatar, - Box, Button, Container, Group, diff --git a/example/assets/js/components/ResultsPage/ResultsPage.tsx b/example/assets/js/components/ResultsPage/ResultsPage.tsx deleted file mode 100644 index 0d2e345..0000000 --- a/example/assets/js/components/ResultsPage/ResultsPage.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import "@mantine/core/styles.css"; - -import { - Container, - createTheme, - List, - MantineProvider, - Title, -} from "@mantine/core"; -import { useState } from "react"; - -const theme = createTheme({}); - -export function ResultsPage({ assistantId }: { assistantId: string }) { - const [lat, setLat] = useState(0); - const [lon, setLon] = useState(0); - const successCallback = (position) => { - console.log(position); - setLat(position.coords.latitude); - setLon(position.coords.longitude); - }; - - const errorCallback = (error) => { - console.log(error); - }; - - navigator.geolocation.getCurrentPosition(successCallback, errorCallback); - return ( - - hi - lat: {lat} - lon: {lon} - - ); -}; - diff --git a/example/assets/js/components/TourGuide/TourGuide.tsx b/example/assets/js/components/TourGuide/TourGuide.tsx new file mode 100644 index 0000000..a5bef1d --- /dev/null +++ b/example/assets/js/components/TourGuide/TourGuide.tsx @@ -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 ( + + Latitude: setLatitude(e.target.value)} /> + Longitude: setLongitude(e.target.value)} /> + Guide Me! + {loading ? Loading : null} + + {attractions.map((item, i) => + + {item.attraction_url ? {item.attraction_name} : item.attraction_name } + {item.attraction_description} + + + )} + + + ); +}; + diff --git a/example/assets/js/components/index.ts b/example/assets/js/components/index.ts index c386cf4..c50b84e 100644 --- a/example/assets/js/components/index.ts +++ b/example/assets/js/components/index.ts @@ -1,3 +1,3 @@ export { ThreadsNav } from "./ThreadsNav/ThreadsNav"; export { Chat } from "./Chat/Chat"; -export { ResultsPage } from "./ResultsPage/ResultsPage"; +export { TourGuide } from "./TourGuide/TourGuide"; diff --git a/example/demo/views.py b/example/demo/views.py index 1d8a9f8..adb5417 100644 --- a/example/demo/views.py +++ b/example/demo/views.py @@ -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)) diff --git a/example/package.json b/example/package.json index 381fa9e..484c709 100644 --- a/example/package.json +++ b/example/package.json @@ -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", diff --git a/example/pnpm-lock.yaml b/example/pnpm-lock.yaml index d390fd4..57ad579 100644 --- a/example/pnpm-lock.yaml +++ b/example/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: '@tabler/icons-react': specifier: ^3.7.0 version: 3.7.0(react@18.3.1) + axios: + specifier: ^1.7.5 + version: 1.7.5 cookie: specifier: ^0.6.0 version: 0.6.0 @@ -1361,8 +1364,8 @@ packages: peerDependencies: postcss: ^8.1.0 - axios@1.7.2: - resolution: {integrity: sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==} + axios@1.7.5: + resolution: {integrity: sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==} babel-loader@9.1.3: resolution: {integrity: sha512-xG3ST4DglodGf8qSwv0MdeWLhrDsw/32QMdTO5T1ZIp9gQur0HkCyFs7Awskr10JKXFXwpAhiCuYX5oGXnRGbw==} @@ -4944,7 +4947,7 @@ snapshots: postcss: 8.4.38 postcss-value-parser: 4.2.0 - axios@1.7.2: + axios@1.7.5: dependencies: follow-redirects: 1.15.6 form-data: 4.0.0 @@ -5253,7 +5256,7 @@ snapshots: django-ai-assistant-client@0.0.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: - axios: 1.7.2 + axios: 1.7.5 cookie: 0.6.0 react: 18.3.1 react-dom: 18.3.1(react@18.3.1)