@@ -632,6 +632,50 @@ pub fn transform_string(
632
632
}
633
633
}
634
634
635
+ #[ cfg( all( feature = "python" , not( feature = "use_as_lib" ) ) ) ]
636
+ #[ pg_extern( immutable, parallel_safe, name = "transform" ) ]
637
+ #[ allow( unused_variables) ] // cache is maintained for api compatibility
638
+ pub fn transform_conversational_json (
639
+ task : JsonB ,
640
+ args : default ! ( JsonB , "'{}'" ) ,
641
+ inputs : default ! ( Vec <JsonB >, "ARRAY[]::JSONB[]" ) ,
642
+ cache : default ! ( bool , false ) ,
643
+ ) -> JsonB {
644
+ if !task. 0 [ "task" ]
645
+ . as_str ( )
646
+ . is_some_and ( |v| v == "conversational" )
647
+ {
648
+ error ! (
649
+ "ARRAY[]::JSONB inputs for transform should only be used with a conversational task"
650
+ ) ;
651
+ }
652
+ match crate :: bindings:: transformers:: transform ( & task. 0 , & args. 0 , inputs) {
653
+ Ok ( output) => JsonB ( output) ,
654
+ Err ( e) => error ! ( "{e}" ) ,
655
+ }
656
+ }
657
+
658
+ #[ cfg( all( feature = "python" , not( feature = "use_as_lib" ) ) ) ]
659
+ #[ pg_extern( immutable, parallel_safe, name = "transform" ) ]
660
+ #[ allow( unused_variables) ] // cache is maintained for api compatibility
661
+ pub fn transform_conversational_string (
662
+ task : String ,
663
+ args : default ! ( JsonB , "'{}'" ) ,
664
+ inputs : default ! ( Vec <JsonB >, "ARRAY[]::JSONB[]" ) ,
665
+ cache : default ! ( bool , false ) ,
666
+ ) -> JsonB {
667
+ if task != "conversational" {
668
+ error ! (
669
+ "ARRAY[]::JSONB inputs for transform should only be used with a conversational task"
670
+ ) ;
671
+ }
672
+ let task_json = json ! ( { "task" : task } ) ;
673
+ match crate :: bindings:: transformers:: transform ( & task_json, & args. 0 , inputs) {
674
+ Ok ( output) => JsonB ( output) ,
675
+ Err ( e) => error ! ( "{e}" ) ,
676
+ }
677
+ }
678
+
635
679
#[ cfg( all( feature = "python" , not( feature = "use_as_lib" ) ) ) ]
636
680
#[ pg_extern( immutable, parallel_safe, name = "transform_stream" ) ]
637
681
#[ allow( unused_variables) ] // cache is maintained for api compatibility
@@ -640,7 +684,7 @@ pub fn transform_stream_json(
640
684
args : default ! ( JsonB , "'{}'" ) ,
641
685
input : default ! ( & str , "''" ) ,
642
686
cache : default ! ( bool , false ) ,
643
- ) -> SetOfIterator < ' static , String > {
687
+ ) -> SetOfIterator < ' static , JsonB > {
644
688
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
645
689
let python_iter =
646
690
crate :: bindings:: transformers:: transform_stream_iterator ( & task. 0 , & args. 0 , input)
@@ -657,7 +701,7 @@ pub fn transform_stream_string(
657
701
args : default ! ( JsonB , "'{}'" ) ,
658
702
input : default ! ( & str , "''" ) ,
659
703
cache : default ! ( bool , false ) ,
660
- ) -> SetOfIterator < ' static , String > {
704
+ ) -> SetOfIterator < ' static , JsonB > {
661
705
let task_json = json ! ( { "task" : task } ) ;
662
706
// We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
663
707
let python_iter =
@@ -667,6 +711,54 @@ pub fn transform_stream_string(
667
711
SetOfIterator :: new ( python_iter)
668
712
}
669
713
714
+ #[ cfg( all( feature = "python" , not( feature = "use_as_lib" ) ) ) ]
715
+ #[ pg_extern( immutable, parallel_safe, name = "transform_stream" ) ]
716
+ #[ allow( unused_variables) ] // cache is maintained for api compatibility
717
+ pub fn transform_stream_conversational_json (
718
+ task : JsonB ,
719
+ args : default ! ( JsonB , "'{}'" ) ,
720
+ inputs : default ! ( Vec <JsonB >, "ARRAY[]::JSONB[]" ) ,
721
+ cache : default ! ( bool , false ) ,
722
+ ) -> SetOfIterator < ' static , JsonB > {
723
+ if !task. 0 [ "task" ]
724
+ . as_str ( )
725
+ . is_some_and ( |v| v == "conversational" )
726
+ {
727
+ error ! (
728
+ "ARRAY[]::JSONB inputs for transform_stream should only be used with a conversational task"
729
+ ) ;
730
+ }
731
+ // We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
732
+ let python_iter =
733
+ crate :: bindings:: transformers:: transform_stream_iterator ( & task. 0 , & args. 0 , inputs)
734
+ . map_err ( |e| error ! ( "{e}" ) )
735
+ . unwrap ( ) ;
736
+ SetOfIterator :: new ( python_iter)
737
+ }
738
+
739
+ #[ cfg( all( feature = "python" , not( feature = "use_as_lib" ) ) ) ]
740
+ #[ pg_extern( immutable, parallel_safe, name = "transform_stream" ) ]
741
+ #[ allow( unused_variables) ] // cache is maintained for api compatibility
742
+ pub fn transform_stream_conversational_string (
743
+ task : String ,
744
+ args : default ! ( JsonB , "'{}'" ) ,
745
+ inputs : default ! ( Vec <JsonB >, "ARRAY[]::JSONB[]" ) ,
746
+ cache : default ! ( bool , false ) ,
747
+ ) -> SetOfIterator < ' static , JsonB > {
748
+ if task != "conversational" {
749
+ error ! (
750
+ "ARRAY::JSONB inputs for transform_stream should only be used with a conversational task"
751
+ ) ;
752
+ }
753
+ let task_json = json ! ( { "task" : task } ) ;
754
+ // We can unwrap this becuase if there is an error the current transaction is aborted in the map_err call
755
+ let python_iter =
756
+ crate :: bindings:: transformers:: transform_stream_iterator ( & task_json, & args. 0 , inputs)
757
+ . map_err ( |e| error ! ( "{e}" ) )
758
+ . unwrap ( ) ;
759
+ SetOfIterator :: new ( python_iter)
760
+ }
761
+
670
762
#[ cfg( feature = "python" ) ]
671
763
#[ pg_extern( immutable, parallel_safe, name = "generate" ) ]
672
764
fn generate ( project_name : & str , inputs : & str , config : default ! ( JsonB , "'{}'" ) ) -> String {
0 commit comments