@@ -3,9 +3,11 @@ use ::std::error::Error;
33use :: std:: fs:: File ;
44use :: std:: io:: BufReader ;
55
6- use serde:: { Deserialize , Serialize } ;
6+ use serde:: Deserialize ;
77use serde_json:: { from_reader, json, to_string, Value } ;
88
9+ use crate :: interpreter:: ast:: { PdlBaseType , PdlBlock , PdlOptionalType , PdlParser , PdlType } ;
10+
911macro_rules! zip {
1012 ( $x: expr) => ( $x) ;
1113 ( $x: expr, $( $y: expr) , +) => (
@@ -116,132 +118,6 @@ struct BeeAiProgram {
116118 workflow : BeeAiWorkflow ,
117119}
118120
119- #[ derive( Serialize , Debug ) ]
120- enum Parser {
121- #[ serde( rename = "json" ) ]
122- Json ,
123- /*#[serde(rename = "jsonl")]
124- Jsonl,
125- #[serde(rename = "yaml")]
126- Yaml,*/
127- }
128-
129- #[ derive( Serialize , Debug , Clone ) ]
130- enum PdlBaseType {
131- #[ serde( rename = "str" ) ]
132- Str ,
133- #[ serde( rename = "bool" ) ]
134- Bool ,
135- #[ serde( rename = "int" ) ]
136- Int ,
137- #[ serde( rename = "null" ) ]
138- Null ,
139- }
140-
141- #[ derive( Serialize , Debug ) ]
142- struct PdlOptionalType {
143- optional : PdlBaseType ,
144- }
145-
146- #[ derive( Serialize , Debug ) ]
147- #[ serde( untagged) ]
148- enum PdlType {
149- Base ( PdlBaseType ) ,
150- Optional ( PdlOptionalType ) ,
151- Object ( HashMap < String , PdlType > ) ,
152- }
153-
154- #[ derive( Serialize , Debug ) ]
155- #[ serde( untagged) ]
156- enum PdlBlock {
157- String ( String ) ,
158- /*If {
159- #[serde(rename = "if")]
160- condition: String,
161- then: Box<PdlBlock>,
162- },*/
163- Object {
164- object : HashMap < String , PdlBlock > ,
165- } ,
166- Call {
167- call : String ,
168- #[ serde( skip_serializing_if = "Option::is_none" ) ]
169- args : Option < String > ,
170- #[ serde( skip_serializing_if = "Option::is_none" ) ]
171- defs : Option < HashMap < String , PdlBlock > > ,
172- } ,
173- Array {
174- array : Vec < PdlBlock > ,
175- } ,
176- Message {
177- role : String ,
178- content : Box < PdlBlock > ,
179- #[ serde( skip_serializing_if = "Option::is_none" ) ]
180- description : Option < String > ,
181- #[ serde( skip_serializing_if = "Option::is_none" ) ]
182- name : Option < String > ,
183- #[ serde( skip_serializing_if = "Option::is_none" ) ]
184- tool_call_id : Option < String > ,
185- } ,
186- Repeat {
187- #[ serde( rename = "for" ) ]
188- for_ : HashMap < String , String > ,
189- repeat : Box < PdlBlock > ,
190- } ,
191- Text {
192- #[ serde( skip_serializing_if = "Option::is_none" ) ]
193- description : Option < String > ,
194- #[ serde( skip_serializing_if = "Option::is_none" ) ]
195- role : Option < String > ,
196- text : Vec < PdlBlock > ,
197- #[ serde( skip_serializing_if = "Option::is_none" ) ]
198- defs : Option < HashMap < String , PdlBlock > > ,
199- #[ serde( skip_serializing_if = "Option::is_none" ) ]
200- parser : Option < Parser > ,
201- } ,
202- Model {
203- #[ serde( skip_serializing_if = "Option::is_none" ) ]
204- description : Option < String > ,
205- model : String ,
206- #[ serde( skip_serializing_if = "Option::is_none" ) ]
207- def : Option < String > ,
208- parameters : HashMap < String , Value > ,
209- #[ serde( skip_serializing_if = "Option::is_none" ) ]
210- input : Option < Box < PdlBlock > > , // really this should be restricted to be PdlBlock::Array; how do we do this in rust?
211- #[ serde( rename = "modelResponse" ) ]
212- #[ serde( skip_serializing_if = "Option::is_none" ) ]
213- model_response : Option < String > ,
214- } ,
215- Function {
216- function : HashMap < String , PdlType > ,
217- #[ serde( rename = "return" ) ]
218- return_ : Box < PdlBlock > ,
219- } ,
220- PythonCode {
221- lang : String ,
222- code : String ,
223- } ,
224- }
225- /*#[derive(Serialize, Debug)]
226- struct PdlFunctionJsonSchemaParameters {
227- #[serde(rename = "type")]
228- schema_type: String, // TODO constant "object"
229- properties: Option<HashMap<String, Value>>,
230- }
231- #[derive(Serialize, Debug)]
232- struct PdlFunctionJsonSchema {
233- name: String,
234- #[serde(skip_serializing_if = "Option::is_none")]
235- description: Option<String>,
236- parameters: PdlFunctionJsonSchemaParameters,
237- }
238- #[derive(Serialize, Debug)]
239- struct PdlFunctionDeclaration {
240- #[serde(rename = "type")]
241- declaration_type: String, // TODO constant "function"
242- function: PdlFunctionJsonSchema,
243- }*/
244-
245121fn a_tool ( tool : & BeeAiToolState ) -> Value {
246122 json ! ( {
247123 "type" : "function" ,
@@ -338,7 +214,7 @@ fn json_loads(
338214 "{{\" {}\" : {}}}" ,
339215 inner_name, value
340216 ) ) ] ,
341- parser : Some ( Parser :: Json ) ,
217+ parser : Some ( PdlParser :: Json ) ,
342218 } ,
343219 ) ;
344220 Some ( m)
@@ -422,20 +298,6 @@ pub fn compile(
422298 . map ( |prompt| PdlBlock :: String ( format ! ( "{}\n " , prompt) ) )
423299 . collect :: < Vec < _ > > ( ) ;
424300
425- /*let system_prompts = bee
426- .workflow
427- .workflow
428- .steps
429- .values()
430- .filter_map(|step| step.state.dict.agent_metadata.state.dict.instructions.clone())
431- .map(|instructions| PdlBlock::Text {
432- role: Some(String::from("system")),
433- text: vec![PdlBlock::String(instructions)],
434- defs: None,
435- description: None,
436- })
437- .collect::<Vec<_>>();*/
438-
439301 let tool_declarations = bee
440302 . workflow
441303 . workflow
@@ -480,17 +342,6 @@ asyncio.run(invoke())
480342 "" . to_string( )
481343 } ,
482344 import_fn,
483- /*schema
484- .iter()
485- .filter_map(|(arg, arg_type)| match arg_type {
486- PdlType::Base(PdlBaseType::Str) =>
487- Some(format!("\"{}\":\"${{ {} }}\"", arg, arg)),
488- PdlType::Base(_) =>
489- Some(format!("\"{}\":${{ {} }}", arg, arg)),
490- _ => None,
491- })
492- .collect::<Vec<_>>()
493- .join(" "),*/
494345 if * debug {
495346 format!(
496347 "print(f'Response from tool {}: {{result}}')" ,
0 commit comments