diff --git a/Project/Sources/Forms/D_Chat/Images/Gears.gif b/Project/Sources/Forms/D_Chat/Images/Gears.gif new file mode 100644 index 0000000..1a4ecbf Binary files /dev/null and b/Project/Sources/Forms/D_Chat/Images/Gears.gif differ diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button.4dm new file mode 100644 index 0000000..1ff1e30 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button.4dm @@ -0,0 +1,15 @@ +var $aiParameters : Object + +$aiParameters:=New object:C1471 + +$aiParameters.apiKey:=Form:C1466.apiKey +$aiParameters.windowID:=Form:C1466.windowID + +$aiParameters.function:=Form:C1466.ddownList.values[Form:C1466.ddownList.index] +$aiParameters.prompt:=Form:C1466.prompt + +Form:C1466.answer:="" +OBJECT SET VISIBLE:C603(*; "waitGears"; True:C214) +AI Call($aiParameters) + + diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button10.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button10.4dm new file mode 100644 index 0000000..e0db735 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button10.4dm @@ -0,0 +1,6 @@ + +If (Shift down:C543) + Form:C1466.prompt:="Generate an advertising for the new book “Have fun gardening”" +Else + Form:C1466.prompt:="Génère une publicité pour le nouveau livre ”Jardinez en vous amusant”" +End if diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button2.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button2.4dm new file mode 100644 index 0000000..4cfc297 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button2.4dm @@ -0,0 +1,20 @@ +//var $aiSignal : 4D.Signal +//var $done : Boolean + + +//$aiSignal:=New signal("Call AI") +//Use ($aiSignal) +//$aiSignal.apiKey:=Form.apiKey +//$aiParameters.windowID:=Form.windowID + +//$aiSignal.function:="Reset context" +//End use + +//AI Call($aiSignal) +//$done:=$aiSignal.wait(5) +//If ($done) +//ALERT("Done") +//Else +//ALERT("no anwser") +//End if + diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button3.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button3.4dm new file mode 100644 index 0000000..ac17c9c --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button3.4dm @@ -0,0 +1,5 @@ +If (Shift down:C543) + Form:C1466.prompt:="Generate a formal invitation for the \"World Motor Show\" 2025" +Else + Form:C1466.prompt:="Génère une invitation formelle pour le \"Mondial de l'automobile\" 2025" +End if \ No newline at end of file diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button4.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button4.4dm new file mode 100644 index 0000000..bbb47ad --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button4.4dm @@ -0,0 +1,5 @@ +If (Shift down:C543) + Form:C1466.prompt:="Generate a funny invitation for the wedding of PAUL and VIRGINIE" +Else + Form:C1466.prompt:="Génère une invitation de mariage amusante pour le mariage de PAUL et VIRGINIE" +End if \ No newline at end of file diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button5.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button5.4dm new file mode 100644 index 0000000..5743046 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button5.4dm @@ -0,0 +1,6 @@ +If (Shift down:C543) + Form:C1466.prompt:="Generate geek invitation for the hi-tech show 2025" +Else + Form:C1466.prompt:="Génère invitation spécial geek pour le salon hi-tech 2025" +End if + diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button6.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button6.4dm new file mode 100644 index 0000000..fed42e7 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button6.4dm @@ -0,0 +1,6 @@ + +If (Shift down:C543) + Form:C1466.prompt:="Generate a formal invitation for lawers congress of Chicago" +Else + Form:C1466.prompt:="Génère a invitation formelle pour le salon des avocats d'Aix-en-Provence" +End if diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button7.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button7.4dm new file mode 100644 index 0000000..8839599 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button7.4dm @@ -0,0 +1,14 @@ +var $aiParameters : Object + +$aiParameters:=New object:C1471 + +$aiParameters.apiKey:=Form:C1466.apiKey +$aiParameters.windowID:=Form:C1466.windowID + +$aiParameters.function:=Form:C1466.ddownList.values[Form:C1466.ddownList.index] +$aiParameters.prompt:=Form:C1466.prompt + +OBJECT SET VISIBLE:C603(*; "waitText"; True:C214) +AI Call($aiParameters) + + diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Button9.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Button9.4dm new file mode 100644 index 0000000..0102601 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Button9.4dm @@ -0,0 +1,6 @@ + +If (Shift down:C543) + Form:C1466.prompt:="Generates an invitation to the opening of the “Maxi-DYI\\” store." +Else + Form:C1466.prompt:="Génère une invitation à l'inauguration du magasin de bricolage “MaxiBricolle“" +End if diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/Popup Dropdown List.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/Popup Dropdown List.4dm new file mode 100644 index 0000000..c0c3aa1 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/Popup Dropdown List.4dm @@ -0,0 +1 @@ +SET TIMER:C645(-1) \ No newline at end of file diff --git a/Project/Sources/Forms/D_Chat/ObjectMethods/WParea.4dm b/Project/Sources/Forms/D_Chat/ObjectMethods/WParea.4dm new file mode 100644 index 0000000..b840dc1 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/ObjectMethods/WParea.4dm @@ -0,0 +1 @@ +WP UpdateWidget ("WPtoolbar";"WParea") diff --git a/Project/Sources/Forms/D_Chat/form.4DForm b/Project/Sources/Forms/D_Chat/form.4DForm new file mode 100644 index 0000000..6d5890d --- /dev/null +++ b/Project/Sources/Forms/D_Chat/form.4DForm @@ -0,0 +1,309 @@ +{ + "$4d": { + "version": "1", + "kind": "form" + }, + "windowSizingX": "variable", + "windowSizingY": "variable", + "windowMinWidth": 0, + "windowMinHeight": 0, + "windowMaxWidth": 32767, + "windowMaxHeight": 32767, + "events": [ + "onLoad", + "onTimer" + ], + "windowTitle": "Prompt Window", + "destination": "detailScreen", + "pages": [ + { + "objects": {} + }, + { + "objects": { + "Button": { + "type": "button", + "text": "Generate", + "top": 240, + "left": 800, + "width": 100, + "height": 20, + "events": [ + "onClick" + ], + "method": "ObjectMethods/Button.4dm", + "focusable": false, + "defaultButton": true, + "sizingX": "move", + "sizingY": "fixed" + }, + "VisionUrl": { + "type": "input", + "left": 1292, + "top": 60, + "width": 440, + "height": 40, + "dataSource": "Form:C1466.url", + "visibility": "visible", + "placeholder": "Enter an image url", + "sizingX": "grow", + "sizingY": "fixed" + }, + "Popup Dropdown List": { + "type": "dropdown", + "left": 1370, + "top": 20, + "width": 180, + "height": 20, + "events": [ + "onClick" + ], + "dataSource": "Form:C1466.ddownList", + "method": "ObjectMethods/Popup Dropdown List.4dm", + "dataSourceTypeHint": "object", + "focusable": false + }, + "Prompt": { + "type": "input", + "left": 130, + "top": 240, + "width": 650, + "height": 20, + "dataSource": "Form:C1466.prompt", + "visibility": "visible", + "placeholder": "Ask anything", + "sizingX": "grow", + "sizingY": "fixed" + }, + "Button1": { + "type": "button", + "text": "Cancel", + "top": 640, + "left": 174, + "width": 100, + "height": 20, + "events": [ + "onClick" + ], + "focusable": false, + "defaultButton": false, + "sizingX": "fixed", + "sizingY": "move", + "action": "cancel" + }, + "Text": { + "type": "text", + "text": "Function:", + "top": 22, + "left": 1280, + "width": 80, + "height": 16, + "textAlign": "right" + }, + "Button2": { + "type": "button", + "text": "Reset context", + "top": 640, + "left": 19, + "width": 140, + "height": 20, + "events": [ + "onClick" + ], + "focusable": false, + "defaultButton": false, + "sizingX": "fixed", + "sizingY": "move", + "method": "ObjectMethods/Button2.4dm" + }, + "Prompt1": { + "type": "input", + "left": 124, + "top": 764, + "width": 880, + "height": 56, + "dataSource": "Form:C1466.answer", + "visibility": "visible", + "placeholder": "…", + "sizingX": "grow", + "sizingY": "grow", + "fontSize": 16 + }, + "Button3": { + "type": "button", + "text": "The World\\Motor Show", + "top": 30, + "left": 20, + "width": 160, + "height": 160, + "events": [ + "onClick" + ], + "icon": "/RESOURCES/Images/Them4.png", + "style": "custom", + "method": "ObjectMethods/Button3.4dm", + "fontWeight": "bold" + }, + "Button4": { + "type": "button", + "text": "Wedding\\invitation", + "top": 30, + "left": 164, + "width": 160, + "height": 160, + "events": [ + "onClick" + ], + "icon": "/RESOURCES/Images/Them2.png", + "style": "custom", + "method": "ObjectMethods/Button4.4dm", + "fontWeight": "bold" + }, + "Button6": { + "type": "button", + "text": "Lawyers\\Congress", + "top": 30, + "left": 450, + "width": 160, + "height": 160, + "events": [ + "onClick" + ], + "icon": "/RESOURCES/Images/Them1.png", + "style": "custom", + "method": "ObjectMethods/Button6.4dm", + "fontWeight": "bold" + }, + "Button7": { + "type": "button", + "text": "Random them", + "top": 240, + "left": 19, + "width": 100, + "height": 20, + "events": [ + "onClick" + ], + "method": "ObjectMethods/Button7.4dm", + "focusable": false, + "defaultButton": false, + "sizingX": "fixed", + "sizingY": "fixed" + }, + "Button5": { + "type": "button", + "text": "Hi-Tech\\Show", + "top": 30, + "left": 307, + "width": 160, + "height": 160, + "events": [ + "onClick" + ], + "icon": "/RESOURCES/Images/Them3.png", + "style": "custom", + "method": "ObjectMethods/Button5.4dm", + "fontWeight": "bold" + }, + "Button8": { + "type": "button", + "text": "Insert text", + "top": 640, + "left": 780, + "width": 120, + "height": 20, + "events": [ + "onClick" + ], + "focusable": false, + "defaultButton": false, + "sizingX": "move", + "sizingY": "move", + "action": "cancel" + }, + "Button9": { + "type": "button", + "text": "DIY\\Training", + "top": 30, + "left": 593, + "width": 160, + "height": 160, + "events": [ + "onClick" + ], + "icon": "/RESOURCES/Images/Them5.png", + "style": "custom", + "method": "ObjectMethods/Button9.4dm", + "fontWeight": "bold" + }, + "Button10": { + "type": "button", + "text": "Gardening\\skills", + "top": 30, + "left": 736, + "width": 160, + "height": 160, + "events": [ + "onClick" + ], + "icon": "/RESOURCES/Images/Them6.png", + "style": "custom", + "method": "ObjectMethods/Button10.4dm", + "fontWeight": "bold" + }, + "WParea": { + "type": "write", + "top": 282, + "left": 19, + "width": 877, + "height": 347, + "sizingX": "grow", + "sizingY": "grow", + "dataSource": "Form:C1466.WPai", + "hideFocusRing": true, + "scrollbarVertical": "automatic", + "scrollbarHorizontal": "automatic", + "dpi": 0, + "borderStyle": "none", + "method": "ObjectMethods/WParea.4dm", + "events": [ + "onLoad", + "onLosingFocus", + "onGettingFocus", + "onSelectionChange", + "onAfterEdit" + ], + "layoutMode": "embedded", + "showHorizontalRuler": false, + "showVerticalRuler": false + }, + "WaitGears": { + "type": "picture", + "top": 307, + "left": 149, + "width": 288, + "height": 219, + "picture": "/RESOURCES/Images/Gears.gif", + "pictureFormat": "scaled", + "visibility": "hidden" + } + } + } + ], + "geometryStamp": 953, + "editor": { + "activeView": "Gears", + "defaultView": "View 1", + "views": { + "View 1": {}, + "Gears": { + "objects": [ + "WaitGears" + ] + } + } + }, + "method": "method.4dm", + "width": 920, + "height": 680 +} \ No newline at end of file diff --git a/Project/Sources/Forms/D_Chat/method.4dm b/Project/Sources/Forms/D_Chat/method.4dm new file mode 100644 index 0000000..c862ad6 --- /dev/null +++ b/Project/Sources/Forms/D_Chat/method.4dm @@ -0,0 +1,41 @@ +Case of + : (Form event code:C388=On Load:K2:1) + + Form:C1466.ddownList:=New object:C1471 + + Form:C1466.ddownList.values:=["Chat"; "Image"; "Vision"; "Moderation"] + Form:C1466.ddownList.index:=0 + + Form:C1466.WPai:=WP New:C1317 + WP SET ATTRIBUTES:C1342(Form:C1466.WPai; wk font family:K81:65; "Arial"; wk font size:K81:66; "16pt") + + SET TIMER:C645(-1) + + : (Form event code:C388=On Timer:K2:25) + + SET TIMER:C645(0) + + Case of + + : (Form:C1466.ddownList.index=0) // "Chat" + OBJECT SET VISIBLE:C603(*; "Prompt"; True:C214) + OBJECT SET VISIBLE:C603(*; "VisionUrl"; False:C215) + + //: (Form.ddownList.index=1) //"Reset Context" + //OBJECT SET VISIBLE(*; "Prompt"; False) + //OBJECT SET VISIBLE(*; "VisionUrl"; False) + + : (Form:C1466.ddownList.index=1) //"Image" + OBJECT SET VISIBLE:C603(*; "Prompt"; True:C214) + OBJECT SET VISIBLE:C603(*; "VisionUrl"; False:C215) + + : (Form:C1466.ddownList.index=2) //"Vision" + OBJECT SET VISIBLE:C603(*; "Prompt"; True:C214) + OBJECT SET VISIBLE:C603(*; "VisionUrl"; True:C214) + + : (Form:C1466.ddownList.index=3) //"Moderation" + OBJECT SET VISIBLE:C603(*; "Prompt"; True:C214) + OBJECT SET VISIBLE:C603(*; "VisionUrl"; False:C215) + + End case +End case \ No newline at end of file diff --git a/Project/Sources/Forms/D_Chat/updateOutput.4dm b/Project/Sources/Forms/D_Chat/updateOutput.4dm new file mode 100644 index 0000000..e69de29 diff --git a/Project/Sources/Methods/AI Call.4dm b/Project/Sources/Methods/AI Call.4dm new file mode 100644 index 0000000..87fb462 --- /dev/null +++ b/Project/Sources/Methods/AI Call.4dm @@ -0,0 +1,78 @@ +//%attributes = {"invisible":true,"shared":true} +#DECLARE($aiParameters : Object) + +var $openAI : cs:C1710.ai.openAI +$openAI:=cs:C1710.ai.openAI.new($aiParameters.apiKey) // PRIVATE KEY + + +var $textGenerationParam : Object +var $imageGenerationParam : Object +var $visionParam : Object +var $assistantCreationParam : Object +var $assistantListParam : Object +var $retrieveListParam : Object + +var $moderationResult : Collection +var $moderationFlag : Boolean +var $moderationCategories : Text + +var $assistantResult : Text +var $assistantFileUrl : Text + +var $alertResult : Text +var $assistant_info : Text + +var $threadParam : Object + +var $formInupt : Text + +$formPrompt:=Form:C1466.prompt +$formVisionUrl:=Form:C1466.url + + +//$ddList:=Form.ddownList + +$function:=$aiParameters.function + +Case of + + : ($function="Chat") // CHAT ----------------------------------------------------------------- + + $textGenerationParam:=New object:C1471(\ + "userPrompt"; $formPrompt; \ + "systemPrompt"; ""; \ + "openAiChatContext"; 5; \ + "model"; "") + $openAI.textGeneration($textGenerationParam; Formula:C1597(AI_CallBack($1; $aiParameters))) + + : ($function="Reset Context") // RESET CHAT CONTEXT ----------------------------------------------------------------- + + $openAI.resetTextGenerationContext(Formula:C1597(ALERT:C41($1))) + + : ($function="Image") //IMAGE ----------------------------------------------------------------- + + $imageGenerationParam:=New object:C1471(\ + "userPrompt"; $formPrompt; \ + "model"; "dall-e-3"; \ + "quantity"; 1; \ + "downloadImage"; True:C214; \ + "size"; "") + $openAI.imageGeneration($imageGenerationParam; Formula:C1597(ALERT:C41($1.join(" || ")))) + + : ($function="Vision") //VISION ----------------------------------------------------------------- + + $visionParam:=New object:C1471(\ + "pictureUrl"; $formVisionUrl; \ + "userPrompt"; $formPrompt; \ + "model"; ""; \ + "detail"; "") + $openAI.visionGeneration($visionParam; Formula:C1597(ALERT:C41($1))) + + : ($function="Moderation") //MODERATION ----------------------------------------------------------------- + + $openAI.textModeration($formPrompt; Formula:C1597(ALERT:C41("Sensitive content: "+String:C10($1[0].isFlagged)+"\n"+String:C10($1[1].flaggedCategories.join(", "))))) + +End case + + + diff --git a/Project/Sources/Methods/AI Dialog.4dm b/Project/Sources/Methods/AI Dialog.4dm new file mode 100644 index 0000000..5dfa75d --- /dev/null +++ b/Project/Sources/Methods/AI Dialog.4dm @@ -0,0 +1,15 @@ +//%attributes = {"shared":true} +#DECLARE($apikey) + +var $windowID : Integer + +If (Count parameters:C259=0) + // alert (An API key is needed) + $apiKey:="XXXXXXX" + + //Else + + $windowID:=Open form window:C675("D_Chat"; Plain form window:K39:10; Horizontally centered:K39:1; Vertically centered:K39:4; *) + DIALOG:C40("D_Chat"; {apiKey: $apiKey; windowID: $windowID}) + +End if \ No newline at end of file diff --git a/Project/Sources/Methods/AI_CallBack.4dm b/Project/Sources/Methods/AI_CallBack.4dm new file mode 100644 index 0000000..44b1da9 --- /dev/null +++ b/Project/Sources/Methods/AI_CallBack.4dm @@ -0,0 +1,6 @@ +//%attributes = {} +#DECLARE($result : Collection; $parameters : Object) +var $answer : Text + +$answer:=$result.last().content +CALL FORM:C1391($parameters.windowID; "AI_updateForm"; $answer) diff --git a/Project/Sources/Methods/AI_updateForm.4dm b/Project/Sources/Methods/AI_updateForm.4dm new file mode 100644 index 0000000..02d7654 --- /dev/null +++ b/Project/Sources/Methods/AI_updateForm.4dm @@ -0,0 +1,26 @@ +//%attributes = {} +#DECLARE($content : Text) + +var $range : Object + +$content:=Replace string:C233($content; "**"; "") + +// insert the answer at the beginning +WP INSERT BREAK:C1413(Form:C1466.WPai; wk paragraph break:K81:259; wk prepend:K81:178) +WP SET TEXT:C1574(Form:C1466.WPai; $content; wk prepend:K81:178) + + +$range:=WP Text range:C1341(Form:C1466.WPai; 1; Length:C16($content)+1) +WP SET ATTRIBUTES:C1342($range; wk text color:K81:64; "black"; wk text align:K81:49; wk left:K81:95; wk background color:K81:20; "white") + +// insert the prompt (before) +WP INSERT BREAK:C1413(Form:C1466.WPai; wk paragraph break:K81:259; wk prepend:K81:178) +WP SET TEXT:C1574(Form:C1466.WPai; Form:C1466.prompt; wk prepend:K81:178) + +$range:=WP Text range:C1341(Form:C1466.WPai; 1; Length:C16(Form:C1466.prompt)+1) +WP SET ATTRIBUTES:C1342($range; wk text color:K81:64; "Red"; wk text align:K81:49; wk right:K81:96; wk background color:K81:20; "lightgrey") + +WP SELECT:C1348(Form:C1466.WPai; 1; 1) + +Form:C1466.answer:=$content +OBJECT SET VISIBLE:C603(*; "waitGears"; False:C215) diff --git a/Resources/Images/Gears.gif b/Resources/Images/Gears.gif new file mode 100644 index 0000000..1a4ecbf Binary files /dev/null and b/Resources/Images/Gears.gif differ diff --git a/Resources/Images/Them1.png b/Resources/Images/Them1.png new file mode 100644 index 0000000..bb1b02a Binary files /dev/null and b/Resources/Images/Them1.png differ diff --git a/Resources/Images/Them1@2x.png b/Resources/Images/Them1@2x.png new file mode 100644 index 0000000..79e82bb Binary files /dev/null and b/Resources/Images/Them1@2x.png differ diff --git a/Resources/Images/Them2.png b/Resources/Images/Them2.png new file mode 100644 index 0000000..0a798b4 Binary files /dev/null and b/Resources/Images/Them2.png differ diff --git a/Resources/Images/Them2@2x.png b/Resources/Images/Them2@2x.png new file mode 100644 index 0000000..4bd9393 Binary files /dev/null and b/Resources/Images/Them2@2x.png differ diff --git a/Resources/Images/Them3.png b/Resources/Images/Them3.png new file mode 100644 index 0000000..deec535 Binary files /dev/null and b/Resources/Images/Them3.png differ diff --git a/Resources/Images/Them3@2x.png b/Resources/Images/Them3@2x.png new file mode 100644 index 0000000..ae4ea7d Binary files /dev/null and b/Resources/Images/Them3@2x.png differ diff --git a/Resources/Images/Them4.png b/Resources/Images/Them4.png new file mode 100644 index 0000000..e9f381c Binary files /dev/null and b/Resources/Images/Them4.png differ diff --git a/Resources/Images/Them4@2x.png b/Resources/Images/Them4@2x.png new file mode 100644 index 0000000..8be043a Binary files /dev/null and b/Resources/Images/Them4@2x.png differ diff --git a/Resources/Images/Them5.png b/Resources/Images/Them5.png new file mode 100644 index 0000000..cd30815 Binary files /dev/null and b/Resources/Images/Them5.png differ diff --git a/Resources/Images/Them5@2x.png b/Resources/Images/Them5@2x.png new file mode 100644 index 0000000..58479ef Binary files /dev/null and b/Resources/Images/Them5@2x.png differ diff --git a/Resources/Images/Them6.png b/Resources/Images/Them6.png new file mode 100644 index 0000000..7a4c8bc Binary files /dev/null and b/Resources/Images/Them6.png differ diff --git a/Resources/Images/Them6@2x.png b/Resources/Images/Them6@2x.png new file mode 100644 index 0000000..e43069a Binary files /dev/null and b/Resources/Images/Them6@2x.png differ