@@ -19,7 +19,6 @@ use ollama_rs::{
1919
2020use serde_json:: { from_str, to_string, Map , Value } ;
2121use serde_norway:: from_reader;
22- use tokio:: runtime:: Runtime ;
2322
2423use crate :: pdl:: ast:: {
2524 PdlBlock , PdlCallBlock , PdlModelBlock , PdlParser , PdlPythonCodeBlock , PdlRepeatBlock ,
@@ -36,7 +35,7 @@ struct Interpreter<'a> {
3635 // cwd: Box<PathBuf>,
3736 // id_stack: Vec<String>,
3837 jinja_env : Environment < ' a > ,
39- rt : Runtime ,
38+ // rt: Runtime,
4039 scope : Vec < Scope > ,
4140 debug : bool ,
4241 emit : bool ,
@@ -59,7 +58,7 @@ impl<'a> Interpreter<'a> {
5958 // cwd: Box::new(current_dir().unwrap_or(PathBuf::from("/"))),
6059 // id_stack: vec![],
6160 jinja_env : jinja_env,
62- rt : Runtime :: new ( ) . unwrap ( ) ,
61+ // rt: Runtime::new().unwrap(),
6362 scope : vec ! [ Scope :: new( ) ] ,
6463 debug : false ,
6564 emit : true ,
@@ -90,7 +89,7 @@ impl<'a> Interpreter<'a> {
9089 _ => self . emit ,
9190 } {
9291 // eprintln!("{:?}", program);
93- pretty_print ( & messages) ;
92+ println ! ( "{}" , pretty_print( & messages) ) ;
9493 }
9594 self . emit = prior_emit;
9695
@@ -320,7 +319,7 @@ impl<'a> Interpreter<'a> {
320319 let req = ChatMessageRequest :: new ( model. into ( ) , vec ! [ prompt. clone( ) ] )
321320 . options ( options)
322321 . tools ( tools) ;
323- let res = self . rt . block_on ( ollama. send_chat_messages_with_history (
322+ let res = /* self.rt.*/ tauri :: async_runtime :: block_on ( ollama. send_chat_messages_with_history (
324323 & mut history,
325324 req,
326325 //ollama.generate(GenerationRequest::new(model.into(), prompt),
@@ -474,23 +473,27 @@ pub fn run_json(source: Value, debug: bool) -> Interpretation {
474473 run_string ( & to_string ( & source) ?, debug)
475474}
476475
477- fn pretty_print ( messages : & Vec < ChatMessage > ) {
478- messages. into_iter ( ) . for_each (
479- |ChatMessage {
480- role : r,
481- content : c,
482- ..
483- } | {
484- println ! (
485- "{:?}: {}" ,
486- r. bold( ) ,
487- match r {
488- MessageRole :: Assistant => c. green( ) . to_string( ) ,
489- MessageRole :: System => c. cyan( ) . to_string( ) ,
490- MessageRole :: Tool => c. magenta( ) . to_string( ) ,
491- _ => c. to_string( ) ,
492- }
493- )
494- } ,
495- )
476+ pub fn pretty_print ( messages : & Vec < ChatMessage > ) -> String {
477+ messages
478+ . into_iter ( )
479+ . map (
480+ |ChatMessage {
481+ role : r,
482+ content : c,
483+ ..
484+ } | {
485+ format ! (
486+ "{:?}: {}" ,
487+ r. bold( ) ,
488+ match r {
489+ MessageRole :: Assistant => c. green( ) . to_string( ) ,
490+ MessageRole :: System => c. cyan( ) . to_string( ) ,
491+ MessageRole :: Tool => c. magenta( ) . to_string( ) ,
492+ _ => c. to_string( ) ,
493+ }
494+ )
495+ } ,
496+ )
497+ . collect :: < Vec < _ > > ( )
498+ . join ( "\n " )
496499}
0 commit comments