11// use ::std::cell::LazyCell;
22use :: std:: collections:: HashMap ;
3- use :: std:: env:: current_dir;
43use :: std:: error:: Error ;
5- use :: std:: fs:: { read_to_string as read_file_to_string, File } ;
64use :: std:: path:: PathBuf ;
7- use std:: sync:: { Arc , Mutex } ;
85
96use async_recursion:: async_recursion;
107use minijinja:: { syntax:: SyntaxConfig , Environment } ;
@@ -32,7 +29,8 @@ use crate::pdl::ast::{
3229} ;
3330
3431type Context = Vec < ChatMessage > ;
35- type PdlError = Box < dyn Error + Send + Sync > ;
32+ type ThreadSafeError = dyn Error + Send + Sync ;
33+ type PdlError = Box < ThreadSafeError > ;
3634type Interpretation = Result < ( PdlResult , Context , PdlBlock ) , PdlError > ;
3735type InterpretationSync = Result < ( PdlResult , Context , PdlBlock ) , Box < dyn Error > > ;
3836
@@ -62,7 +60,7 @@ impl<'a> Interpreter<'a> {
6260 Self {
6361 // batch: 0,
6462 // role: Role::User,
65- cwd : current_dir ( ) . unwrap_or ( PathBuf :: from ( "/" ) ) ,
63+ cwd : :: std :: env :: current_dir ( ) . unwrap_or ( PathBuf :: from ( "/" ) ) ,
6664 // id_stack: vec![],
6765 jinja_env : jinja_env,
6866 scope : vec ! [ Scope :: new( ) ] ,
@@ -289,7 +287,7 @@ impl<'a> Interpreter<'a> {
289287 ) ;
290288
291289 let buffer = match & block. read {
292- StringOrNull :: String ( file_path) => read_file_to_string ( self . path_to ( file_path) ) ?,
290+ StringOrNull :: String ( file_path) => :: std :: fs :: read_to_string ( self . path_to ( file_path) ) ?,
293291 StringOrNull :: Null => {
294292 let mut buffer = String :: new ( ) ;
295293 let mut bytes_read = :: std:: io:: stdin ( ) . read_line ( & mut buffer) ?;
@@ -326,7 +324,7 @@ impl<'a> Interpreter<'a> {
326324 self . push_and_extend_scope_with ( m, c. scope ) ;
327325 Ok ( ( ) )
328326 }
329- x => Err ( Box :: < dyn Error + Send + Sync > :: from ( format ! (
327+ x => Err ( PdlError :: from ( format ! (
330328 "Call arguments not a map: {:?}" ,
331329 x
332330 ) ) ) ,
@@ -504,7 +502,7 @@ impl<'a> Interpreter<'a> {
504502 "<embedded>" . to_owned ( ) ,
505503 ) {
506504 Ok ( x) => Ok ( x) ,
507- Err ( exc) => Err ( Box :: < dyn Error + Send + Sync > :: from ( format ! (
505+ Err ( exc) => Err ( PdlError :: from ( format ! (
508506 "Syntax error in Python code {:?}" ,
509507 exc
510508 ) ) ) ,
@@ -515,7 +513,7 @@ impl<'a> Interpreter<'a> {
515513 Ok ( _) => Ok ( ( ) ) ,
516514 Err ( exc) => {
517515 vm. print_exception ( exc) ;
518- Err ( Box :: < dyn Error + Send + Sync > :: from (
516+ Err ( PdlError :: from (
519517 "Error executing Python code" ,
520518 ) )
521519 }
@@ -527,7 +525,7 @@ impl<'a> Interpreter<'a> {
527525 Ok ( x) => Ok ( x) ,
528526 Err ( exc) => {
529527 vm. print_exception ( exc) ;
530- Err ( Box :: < dyn Error + Send + Sync > :: from (
528+ Err ( PdlError :: from (
531529 "Unable to stringify Python 'result' value" ,
532530 ) )
533531 }
@@ -604,7 +602,7 @@ impl<'a> Interpreter<'a> {
604602 } else {
605603 let mut stream = ollama
606604 . send_chat_messages_with_history_stream (
607- Arc :: new ( Mutex :: new ( history) ) ,
605+ :: std :: sync :: Arc :: new ( :: std :: sync :: Mutex :: new ( history) ) ,
608606 req,
609607 //ollama.generate(GenerationRequest::new(model.into(), prompt),
610608 )
@@ -998,8 +996,8 @@ pub fn run_sync(
998996
999997/// Read in a file from disk and parse it as a PDL program
1000998pub fn parse_file ( path : & PathBuf ) -> Result < PdlBlock , PdlError > {
1001- from_reader ( File :: open ( path) ?)
1002- . map_err ( |err| Box :: < dyn Error + Send + Sync > :: from ( err. to_string ( ) ) )
999+ from_reader ( :: std :: fs :: File :: open ( path) ?)
1000+ . map_err ( |err| PdlError :: from ( err. to_string ( ) ) )
10031001}
10041002
10051003pub async fn run_file ( source_file_path : & str , debug : bool , stream : bool ) -> Interpretation {
0 commit comments