@@ -409,6 +409,67 @@ public static class PlugIns
409409 new Parameter ( "Options" , ParameterTypeKind . DynamicBag , minOccurring : 0 ) ,
410410 new Parameter ( "IncludeErrorMessages" , ScalarTypes . Bool , minOccurring : 0 ) ) ;
411411
412+ public static readonly FunctionSymbol AIChatCompletion =
413+ new FunctionSymbol ( "ai_chat_completion" ,
414+ context =>
415+ {
416+ var sourceColumns = context . RowScope . Columns ;
417+ var columnPrefix = context . GetResultName ( context . GetArgument ( "Prompt" ) ) ;
418+
419+ var completionColumnName = MakeColumnName ( columnPrefix , "completion" ) ;
420+ var addedColumns = new List < ColumnSymbol > { new ColumnSymbol ( completionColumnName , ScalarTypes . String ) } ;
421+
422+ if ( context . GetArgument ( "IncludeErrorMessages" ) != null &&
423+ bool . TryParse ( GetConstantValue ( context . GetArgument ( "IncludeErrorMessages" ) ) , out var includeErrorMessages ) )
424+ {
425+ if ( includeErrorMessages )
426+ {
427+ var errorColumnName = MakeColumnName ( columnPrefix , "completion" , "error" ) ;
428+ addedColumns . Add ( new ColumnSymbol ( errorColumnName , ScalarTypes . String ) ) ;
429+ }
430+ }
431+
432+ var resultColumns = sourceColumns . Concat ( addedColumns ) ;
433+
434+ return new TableSymbol ( resultColumns ) ;
435+ } ,
436+ Tabularity . Tabular ,
437+ new Parameter ( "Prompt" , ParameterTypeKind . DynamicArray , ArgumentKind . Column | ArgumentKind . Literal ) ,
438+ new Parameter ( "ConnectionString" , ScalarTypes . String ) ,
439+ new Parameter ( "Options" , ParameterTypeKind . DynamicBag , minOccurring : 0 ) ,
440+ new Parameter ( "IncludeErrorMessages" , ScalarTypes . Bool , minOccurring : 0 ) ) ;
441+
442+ public static readonly FunctionSymbol AIChatCompletionPrompt =
443+ new FunctionSymbol ( "ai_chat_completion_prompt" ,
444+ context =>
445+ {
446+ var sourceColumns = context . RowScope . Columns ;
447+ var columnPrefix = context . GetResultName ( context . GetArgument ( "Prompt" ) ) ;
448+
449+ var completionColumnName = MakeColumnName ( columnPrefix , "completion" ) ;
450+ var addedColumns = new List < ColumnSymbol > { new ColumnSymbol ( completionColumnName , ScalarTypes . String ) } ;
451+
452+ if ( context . GetArgument ( "IncludeErrorMessages" ) != null &&
453+ bool . TryParse ( GetConstantValue ( context . GetArgument ( "IncludeErrorMessages" ) ) , out var includeErrorMessages ) )
454+ {
455+ if ( includeErrorMessages )
456+ {
457+ var errorColumnName = MakeColumnName ( columnPrefix , "completion" , "error" ) ;
458+ addedColumns . Add ( new ColumnSymbol ( errorColumnName , ScalarTypes . String ) ) ;
459+ }
460+ }
461+
462+ var resultColumns = sourceColumns . Concat ( addedColumns ) ;
463+
464+ return new TableSymbol ( resultColumns ) ;
465+ } ,
466+ Tabularity . Tabular ,
467+ new Parameter ( "Prompt" , ScalarTypes . String , ArgumentKind . Column | ArgumentKind . Literal ) ,
468+ new Parameter ( "ConnectionString" , ScalarTypes . String ) ,
469+ new Parameter ( "Options" , ParameterTypeKind . DynamicBag , minOccurring : 0 ) ,
470+ new Parameter ( "IncludeErrorMessages" , ScalarTypes . Bool , minOccurring : 0 ) ) ;
471+
472+
412473 public static readonly FunctionSymbol Identity =
413474 new FunctionSymbol ( "identity" ,
414475 new Signature (
@@ -835,7 +896,9 @@ private static TableSymbol GetOutputSchema(CustomReturnTypeContext context)
835896 SqlRequest ,
836897 MySqlRequest ,
837898 PostgreSqlRequest ,
838- AIEmbedText
899+ AIEmbedText ,
900+ AIChatCompletion ,
901+ AIChatCompletionPrompt ,
839902 } ;
840903
841904 private static Dictionary < string , FunctionSymbol > s_nameToPlugInMap ;
0 commit comments