PDay edits
Browse files- kitt.py +45 -26
- skills/common.py +2 -2
- skills/poi.py +2 -2
- skills/routing.py +3 -0
kitt.py
CHANGED
@@ -72,15 +72,6 @@ def use_tool(func_name, kwargs, tools):
|
|
72 |
return tool.invoke(input=kwargs)
|
73 |
return None
|
74 |
|
75 |
-
tools = [
|
76 |
-
StructuredTool.from_function(get_weather),
|
77 |
-
StructuredTool.from_function(find_route),
|
78 |
-
# StructuredTool.from_function(vehicle_status),
|
79 |
-
StructuredTool.from_function(search_points_of_interests),
|
80 |
-
StructuredTool.from_function(search_along_route_w_coordinates),
|
81 |
-
StructuredTool.from_function(date_time_info),
|
82 |
-
StructuredTool.from_function(do_anything_else),
|
83 |
-
]
|
84 |
# llm = Ollama(model="nexusraven", stop=["\nReflection:", "\nThought:"], keep_alive=60*10)
|
85 |
|
86 |
|
@@ -88,6 +79,18 @@ tools = [
|
|
88 |
hour_options = [f"{i:02d}:00:00" for i in range(24)]
|
89 |
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
def set_time(time_picker):
|
92 |
vehicle.time = time_picker
|
93 |
return vehicle.model_dump_json()
|
@@ -97,10 +100,21 @@ def get_vehicle_status(state):
|
|
97 |
return state.value["vehicle"].model_dump_json()
|
98 |
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def run_generic_model(query):
|
101 |
print(f"Running the generic model with query: {query}")
|
102 |
data = {
|
103 |
-
"prompt": query,
|
104 |
"model": MODEL_GENERAL,
|
105 |
"options": {
|
106 |
# "temperature": 0.1,
|
@@ -112,6 +126,7 @@ def run_generic_model(query):
|
|
112 |
|
113 |
|
114 |
def run_model(query, voice_character):
|
|
|
115 |
print("Query: ", query)
|
116 |
global_context["query"] = query
|
117 |
global_context["prompt"] = get_prompt(RAVEN_PROMPT_FUNC, query, "", tools)
|
@@ -175,20 +190,24 @@ def save_audio_as_wav(data, sample_rate, file_path):
|
|
175 |
|
176 |
|
177 |
def save_and_transcribe_audio(audio):
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
192 |
return text
|
193 |
|
194 |
# to be able to use the microphone on chrome, you will have to go to chrome://flags/#unsafely-treat-insecure-origin-as-secure and enter http://10.186.115.21:7860/
|
@@ -228,10 +247,10 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
228 |
)
|
229 |
voice_character = gr.Radio(choices=voice_options, label='Choose a voice', value=voice_options[0], show_label=True)
|
230 |
origin = gr.Textbox(
|
231 |
-
value="
|
232 |
)
|
233 |
destination = gr.Textbox(
|
234 |
-
value="
|
235 |
label="Destination",
|
236 |
interactive=True,
|
237 |
)
|
|
|
72 |
return tool.invoke(input=kwargs)
|
73 |
return None
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# llm = Ollama(model="nexusraven", stop=["\nReflection:", "\nThought:"], keep_alive=60*10)
|
76 |
|
77 |
|
|
|
79 |
hour_options = [f"{i:02d}:00:00" for i in range(24)]
|
80 |
|
81 |
|
82 |
+
def search_along_route(query=""):
|
83 |
+
"""Search for points of interest along the route/way to the destination.
|
84 |
+
|
85 |
+
Args:
|
86 |
+
query (str, optional): The type of point of interest to search for. Defaults to "restaurant".
|
87 |
+
|
88 |
+
"""
|
89 |
+
points = global_context["route_points"]
|
90 |
+
# maybe reshape
|
91 |
+
return search_along_route_w_coordinates(points, query)
|
92 |
+
|
93 |
+
|
94 |
def set_time(time_picker):
|
95 |
vehicle.time = time_picker
|
96 |
return vehicle.model_dump_json()
|
|
|
100 |
return state.value["vehicle"].model_dump_json()
|
101 |
|
102 |
|
103 |
+
tools = [
|
104 |
+
StructuredTool.from_function(get_weather),
|
105 |
+
StructuredTool.from_function(find_route),
|
106 |
+
# StructuredTool.from_function(vehicle_status),
|
107 |
+
StructuredTool.from_function(search_points_of_interests),
|
108 |
+
StructuredTool.from_function(search_along_route),
|
109 |
+
StructuredTool.from_function(date_time_info),
|
110 |
+
StructuredTool.from_function(do_anything_else),
|
111 |
+
]
|
112 |
+
|
113 |
+
|
114 |
def run_generic_model(query):
|
115 |
print(f"Running the generic model with query: {query}")
|
116 |
data = {
|
117 |
+
"prompt": f"Answer the question below in a short and concise manner.\n{query}",
|
118 |
"model": MODEL_GENERAL,
|
119 |
"options": {
|
120 |
# "temperature": 0.1,
|
|
|
126 |
|
127 |
|
128 |
def run_model(query, voice_character):
|
129 |
+
query = query.strip().replace("'", "")
|
130 |
print("Query: ", query)
|
131 |
global_context["query"] = query
|
132 |
global_context["prompt"] = get_prompt(RAVEN_PROMPT_FUNC, query, "", tools)
|
|
|
190 |
|
191 |
|
192 |
def save_and_transcribe_audio(audio):
|
193 |
+
try:
|
194 |
+
# capture the audio and save it to a file as wav or mp3
|
195 |
+
# file_name = save("audioinput.wav")
|
196 |
+
sr, y = audio
|
197 |
+
# y = y.astype(np.float32)
|
198 |
+
# y /= np.max(np.abs(y))
|
199 |
+
|
200 |
+
# add timestamp to file name
|
201 |
+
filename = f"recordings/audio{time.time()}.wav"
|
202 |
+
save_audio_as_wav(y, sr, filename)
|
203 |
+
|
204 |
+
sr, y = audio
|
205 |
+
y = y.astype(np.float32)
|
206 |
+
y /= np.max(np.abs(y))
|
207 |
+
text = transcriber({"sampling_rate": sr, "raw":y})["text"]
|
208 |
+
except Exception as e:
|
209 |
+
print(f"Error: {e}")
|
210 |
+
return "Error transcribing audio"
|
211 |
return text
|
212 |
|
213 |
# to be able to use the microphone on chrome, you will have to go to chrome://flags/#unsafely-treat-insecure-origin-as-secure and enter http://10.186.115.21:7860/
|
|
|
247 |
)
|
248 |
voice_character = gr.Radio(choices=voice_options, label='Choose a voice', value=voice_options[0], show_label=True)
|
249 |
origin = gr.Textbox(
|
250 |
+
value="Mondorf-les-Bains, Luxembourg", label="Origin", interactive=True
|
251 |
)
|
252 |
destination = gr.Textbox(
|
253 |
+
value="Rue Alphonse Weicker, Luxembourg",
|
254 |
label="Destination",
|
255 |
interactive=True,
|
256 |
)
|
skills/common.py
CHANGED
@@ -55,8 +55,8 @@ config = Settings() # type: ignore
|
|
55 |
|
56 |
vehicle = VehicleStatus(
|
57 |
location="Rue Alphonse Weicker, Luxembourg",
|
58 |
-
location_coordinates=(49.
|
59 |
date="2025-05-06",
|
60 |
time="08:00:00",
|
61 |
-
destination="
|
62 |
)
|
|
|
55 |
|
56 |
vehicle = VehicleStatus(
|
57 |
location="Rue Alphonse Weicker, Luxembourg",
|
58 |
+
location_coordinates=(49.505, 6.28111),
|
59 |
date="2025-05-06",
|
60 |
time="08:00:00",
|
61 |
+
destination="Rue Alphonse Weicker, Luxembourg"
|
62 |
)
|
skills/poi.py
CHANGED
@@ -48,7 +48,7 @@ def search_points_of_interests(search_query="french restaurant"):
|
|
48 |
|
49 |
# Format and limit to top 5 results
|
50 |
formatted_results = [
|
51 |
-
f"{result['poi']['name']}
|
52 |
for result in results[:3]
|
53 |
]
|
54 |
|
@@ -95,7 +95,7 @@ def find_points_of_interest(lat="0", lon="0", type_of_poi="restaurant"):
|
|
95 |
|
96 |
def search_along_route_w_coordinates(points: list[tuple[float, float]], query: str):
|
97 |
"""
|
98 |
-
Return some of the closest points of interest along the route from the depart point, specified by its coordinates.
|
99 |
:param points (list[tuple(float, float)]): Required. List of tuples of latitude and longitude of the points along the route.
|
100 |
:param query (string): Required. type of point of interest depending on what the user wants to do.
|
101 |
"""
|
|
|
48 |
|
49 |
# Format and limit to top 5 results
|
50 |
formatted_results = [
|
51 |
+
f"{result['poi']['name']}, {int(result['dist'])} meters away"
|
52 |
for result in results[:3]
|
53 |
]
|
54 |
|
|
|
95 |
|
96 |
def search_along_route_w_coordinates(points: list[tuple[float, float]], query: str):
|
97 |
"""
|
98 |
+
Return some of the closest points of interest along the route/way from the depart point, specified by its coordinates.
|
99 |
:param points (list[tuple(float, float)]): Required. List of tuples of latitude and longitude of the points along the route.
|
100 |
:param query (string): Required. type of point of interest depending on what the user wants to do.
|
101 |
"""
|
skills/routing.py
CHANGED
@@ -120,6 +120,9 @@ def find_route(destination=""):
|
|
120 |
from the current location.
|
121 |
:param destination (string): Required. The destination
|
122 |
"""
|
|
|
|
|
|
|
123 |
# lat, lon, city = check_city_coordinates(lat_depart,lon_depart,city_depart)
|
124 |
lat_dest, lon_dest = find_coordinates(destination)
|
125 |
print(f"lat_dest: {lat_dest}, lon_dest: {lon_dest}")
|
|
|
120 |
from the current location.
|
121 |
:param destination (string): Required. The destination
|
122 |
"""
|
123 |
+
if not destination:
|
124 |
+
destination = vehicle.destination
|
125 |
+
|
126 |
# lat, lon, city = check_city_coordinates(lat_depart,lon_depart,city_depart)
|
127 |
lat_dest, lon_dest = find_coordinates(destination)
|
128 |
print(f"lat_dest: {lat_dest}, lon_dest: {lon_dest}")
|