File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 14
14
# limitations under the License.
15
15
import asyncio
16
16
import dataclasses
17
+ import importlib .resources as pkg_resources
17
18
import json
19
+ import os
18
20
import uuid
19
21
from collections import namedtuple
20
22
from datetime import datetime , timezone
@@ -218,3 +220,31 @@ def get_or_create_event_loop():
218
220
asyncio .set_event_loop (loop )
219
221
220
222
return loop
223
+
224
+
225
+ def get_data_path (package_name : str , file_path : str ) -> str :
226
+ """Helper to get the path to the data directory."""
227
+ try :
228
+ # Try to get the path from the package resources
229
+ path = pkg_resources .files (package_name ).joinpath (file_path )
230
+ if path .exists ():
231
+ return str (path )
232
+ except FileNotFoundError :
233
+ pass
234
+
235
+ # If that fails, try to get the path from the local file system
236
+ path = os .path .normpath (os .path .join (os .path .dirname (__file__ ), ".." , file_path ))
237
+ if os .path .exists (path ):
238
+ return path
239
+
240
+ raise FileNotFoundError (f"File not found: { file_path } " )
241
+
242
+
243
+ def get_examples_data_path (file_path : str ) -> str :
244
+ """Helper to get the path to the examples data directory."""
245
+ return get_data_path ("nemoguardrails" , f"examples/{ file_path } " )
246
+
247
+
248
+ def get_chat_ui_data_path (file_path : str ) -> str :
249
+ """Helper to get the path to the chat-ui data directory."""
250
+ return get_data_path ("nemoguardrails" , f"chat-ui/{ file_path } " )
You can’t perform that action at this time.
0 commit comments