diff --git a/src/App.css b/src/App.css
index f34bf09..6bc035c 100644
--- a/src/App.css
+++ b/src/App.css
@@ -3,10 +3,6 @@
@tailwind utilities;
-.map {
- height: 60vh;
-}
-
.loader-dots div {
animation-timing-function: cubic-bezier(0, 1, 1, 0);
}
diff --git a/src/App.jsx b/src/App.jsx
index f88af72..967e973 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,13 +1,15 @@
import { useState } from 'react'
import MapComponent from './components/Map.jsx'
+import Chat from './components/Chat.jsx';
const App = () => {
let [places, setPlaces] = useState([]);
return (
<>
-
-
+
+
+
>
);
diff --git a/src/components/Chat.jsx b/src/components/Chat.jsx
new file mode 100644
index 0000000..dd37f38
--- /dev/null
+++ b/src/components/Chat.jsx
@@ -0,0 +1,51 @@
+import { Textarea } from "@headlessui/react";
+import { useState } from "react";
+import generateAi from '../utils/modelConfig.js';
+
+const Chat = ({ setPlaces }) => {
+
+ const [prompt, setPrompt] = useState("");
+ const [messageSent, setMessageSent] = useState(false);
+
+ const handleChange = (e) => {
+ setPrompt(e.target.value);
+ setMessageSent(false);
+ };
+
+ const handleSubmit = async (e) => {
+ e.preventDefault();
+ console.log(prompt);
+ setPrompt("");
+ setMessageSent(true);
+ setPlaces(await generateAi(prompt))
+ }
+
+ const handleKeyPress = (e) => {
+ if (e.key === 'Enter' && !e.shiftKey) {
+ e.preventDefault();
+ handleSubmit(e)
+ }
+ }
+
+ return (
+
+
+
+ {/* {prompt} */}
+
+
+
+
+ );
+};
+
+export default Chat;
\ No newline at end of file
diff --git a/src/components/Map.jsx b/src/components/Map.jsx
index 91ee843..29b97e7 100644
--- a/src/components/Map.jsx
+++ b/src/components/Map.jsx
@@ -5,14 +5,16 @@ import { AdvancedMarker, APIProvider, Map, Pin, useMap } from '@vis.gl/react-goo
import { MarkerClusterer } from '@googlemaps/markerclusterer'
import { Circle } from './Circle.jsx'
+// import {main} from '../utils/modelConfig.js'
+
const center = {
- lat: -27.33056,
- lng: -55.86667,
+ lat: -27.33056,
+ lng: -55.86667,
};
const MapComponent = ({locations=[]}) => {
return (
-
+
console.log("Maps API has loaded.")}
@@ -37,74 +39,74 @@ const MapComponent = ({locations=[]}) => {
);
}
-const PoiMarkers = ({locations=[]}) => {
- const map = useMap()
- const [markers, setMarkers] = useState({})
- const clusterer = useRef(null)
- const [circleCenter, setCircleCenter] = useState(null)
- const handleClick = useCallback(ev => {
- if (!map) return
- if (!ev.latLng) return
- map.panTo(ev.latLng)
- setCircleCenter(ev.latLng)
- })
- // Initialize MarkerClusterer, if the map has changed
- useEffect(() => {
- if (!map) return
- if (!clusterer.current) {
- clusterer.current = new MarkerClusterer({ map })
- }
- }, [map])
+const PoiMarkers = ({ locations = [] }) => {
+ const map = useMap()
+ const [markers, setMarkers] = useState({})
+ const clusterer = useRef(null)
+ const [circleCenter, setCircleCenter] = useState(null)
+ const handleClick = useCallback(ev => {
+ if (!map) return
+ if (!ev.latLng) return
+ map.panTo(ev.latLng)
+ setCircleCenter(ev.latLng)
+ })
+ // Initialize MarkerClusterer, if the map has changed
+ useEffect(() => {
+ if (!map) return
+ if (!clusterer.current) {
+ clusterer.current = new MarkerClusterer({ map })
+ }
+ }, [map])
- // Update markers, if the markers array has changed
- useEffect(() => {
- clusterer.current?.clearMarkers()
- clusterer.current?.addMarkers(Object.values(markers))
- }, [markers])
+ // Update markers, if the markers array has changed
+ useEffect(() => {
+ clusterer.current?.clearMarkers()
+ clusterer.current?.addMarkers(Object.values(markers))
+ }, [markers])
- const setMarkerRef = (marker, key) => {
- if (marker && markers[key]) return
- if (!marker && !markers[key]) return
+ const setMarkerRef = (marker, key) => {
+ if (marker && markers[key]) return
+ if (!marker && !markers[key]) return
- setMarkers(prev => {
- if (marker) {
- return { ...prev, [key]: marker }
- } else {
- const newMarkers = { ...prev }
- delete newMarkers[key]
- return newMarkers
- }
- })
- }
+ setMarkers(prev => {
+ if (marker) {
+ return { ...prev, [key]: marker }
+ } else {
+ const newMarkers = { ...prev }
+ delete newMarkers[key]
+ return newMarkers
+ }
+ })
+ }
- return (
- <>
-
+
+ {locations.map(poi => (
+
+
- {locations.map(poi => (
-
-
-
- ))}
- >
- )
+
+ ))}
+ >
+ )
}
export default MapComponent;
\ No newline at end of file
diff --git a/src/utils/modelConfig.js b/src/utils/modelConfig.js
new file mode 100644
index 0000000..c65941b
--- /dev/null
+++ b/src/utils/modelConfig.js
@@ -0,0 +1,20 @@
+import OpenAI from "openai";
+
+const openai = new OpenAI({ apiKey: import.meta.env.VITE_OPENAI_API_KEY, dangerouslyAllowBrowser: true });
+
+async function generateAi(prompt) {
+ const completion = await openai.chat.completions.create({
+ messages: [{ "role": "system", "content": "You are a helpful assistant from a tourist webpage in the world." },
+ { "role": "user", "content": "please use this format always for your responses in a json format: [{'name':'Circuito Comercial','type':'Turístico','location':{'lat':-27.3593327,'lng':-55.8489188},'description':'Zona baja de Encarnación, conocida por ser un punto de encuentro para turismo de compras.','address':'Zona baja de Encarnación'}, another one] " },
+ { "role": "assistant", "content": "Sure i can do that" },
+ { "role": "user", "content": prompt }],
+ model: "gpt-4o-mini",
+ response_format: { type: "json_object" }
+ });
+ let respuesta = JSON.parse(completion.choices[0].message.content)
+ return (respuesta[Object.keys(respuesta)[0]]);
+}
+
+
+
+export default generateAi;
\ No newline at end of file