Skip to content

Commit

Permalink
update for (future) AI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland-Lannuzel committed Jan 21, 2025
1 parent a0a0d82 commit 824519b
Show file tree
Hide file tree
Showing 56 changed files with 1,276 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ DEV/
# Added by user
#--------------------------------
Project/Sources/dependencies.json
Resources/4DWP_AI/aiPref.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Class constructor($formName : Text)

Function getPersonas()->$personas : Collection


var $folder : 4D:C1709.Folder
var $file : 4D:C1709.File
var $lang; $DBname : Text
Expand Down Expand Up @@ -46,10 +45,11 @@ Function getPersonas()->$personas : Collection
//$validated:=This.JSONvalidate("persona"; $file.getText())
$validated:=True:C214
If ($validated)
$persona:=JSON Parse:C1218($file.getText())
$persona:=JSON Parse:C1218($file.getText()) // .name and .prompt and .temperature
$persona._fileName:=$file.fullName
$persona._origin:=$i // 0: "Default" 1:"Resources" 2:"User")
$persona._originIcon:=This:C1470._originIcons[$i]

$personas.push($persona)
End if
End for each
Expand All @@ -66,6 +66,11 @@ Function getPersonas()->$personas : Collection
$personas.combine($dataPersonas)


Function getValues()->$values : Collection

$values:=This:C1470.personas.extract("name")


Function getIcons()->$icons : Collection

var $fileNames : Collection
Expand All @@ -80,11 +85,11 @@ Function getIcons()->$icons : Collection
$icons.push($picture)
End for each

Function getPersona($id : Integer)->$persona : Object
//Function getPersona($id : Integer)->$persona : Object

If ($id<=This:C1470.personas.length)
$persona:=This:C1470.personas[$id]
End if
//If ($id<=This.personas.length)
//$persona:=This.personas[$id]
//End if

Function save($persona : Object; $saveWhere : Integer)

Expand Down
9 changes: 0 additions & 9 deletions Project/Sources/Forms/D_AI/method.4dm

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CONFIRM:C162(".Are you sure?.")
If (ok=1)
Form:C1466.ai.delete(Form:C1466.persona)
Form:C1466.personaWizard.delete(Form:C1466.persona)


//*** reload list
Expand Down
6 changes: 6 additions & 0 deletions Project/Sources/Forms/D_AI_Personas/ObjectMethods/btnSave.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Form:C1466.personaWizard.save(Form:C1466.editPersona; Form:C1466.saveDestination.index) //index = 0…3

//*** reload list

UI_Personas("init")

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"onLoad",
"onTimer"
],
"windowTitle": "window title",
"windowTitle": ".Personas editor",
"destination": "detailScreen",
"pages": [
{
Expand Down Expand Up @@ -122,7 +122,7 @@
"events": [
"onSelectionChange"
],
"dataSource": "Form:C1466.ai.personas",
"dataSource": "Form:C1466.personaWizard.personas",
"listboxType": "collection",
"currentItemSource": "Form:C1466.persona",
"showHeaders": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Case of
: (Form event code:C388=On Load:K2:1)

Form:C1466.ai:=cs:C1710.AiWizard.new()
Form:C1466.personaWizard:=cs:C1710.PersonaWizard.new()
LISTBOX SELECT ROW:C912(*; "LB_Personas"; 1; lk replace selection:K53:1)

Form:C1466.saveDestination:={values: [".Default"; ".Resources"; ".Single user"; ".All users"]; index: 0}
Expand Down
20 changes: 20 additions & 0 deletions Project/Sources/Forms/D_AI_Prompt/ObjectMethods/Button1.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var $aiParameters : Object

$aiParameters:=New object:C1471

$aiParameters.apiKey:=Form:C1466.apiKey
$aiParameters.windowID:=Form:C1466.windowID

// $aiParameters.function:=Form.local.tabs.values[Form.local.tabs.index] // chat or picture

$aiParameters.function:="Text"
$aiParameters.callbackAction:="Text"
$aiParameters.prompt:=Form:C1466.prompt

//$aiParameters.size:="1024x1024" // for pictures only

Form:C1466.answer:=""
OBJECT SET VISIBLE:C603(*; "waitGears"; True:C214)
AI Call($aiParameters)


12 changes: 12 additions & 0 deletions Project/Sources/Forms/D_AI_Prompt/ObjectMethods/Button2.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//var $file : 4D.File

//$file:=File("/RESOURCES/4DWP_AI/templateAI.4wp")
//Form.WPai:=WP Import document($file)
//WP SET ATTRIBUTES(Form.WPai; wk background color; wk transparent)


//Form.bookmarks:=[]


Form:C1466.reset:=True:C214
SET TIMER:C645(-1)
65 changes: 65 additions & 0 deletions Project/Sources/Forms/D_AI_Prompt/ObjectMethods/Button3.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var $text; $size : Text
var $wp; $range : Object
var $paragraphs; $replaced : Collection
var $paragraph : Object
var $remove; $p1; $p2 : Integer

$text:=WP Get text:C1575(Form:C1466.WPai)

$wp:=WP New:C1317()
WP SET TEXT:C1574($wp; $text; wk replace:K81:177)
WP SET ATTRIBUTES:C1342($wp; wk font size:K81:66; "18pt")

$paragraphs:=WP Get elements:C1550($wp; wk type paragraph:K81:191)

For each ($paragraph; $paragraphs)


$text:=WP Get text:C1575($paragraph; wk expressions as value:K81:255)

Case of
: ($text="####@")
$remove:=6
$size:="24pt"

: ($text="###@")
$remove:=5
$size:="28pt"

: ($text="##@")
$remove:=4
$size:="32pt"

: ($text="#@")
$remove:=3
$size:="36pt"

Else
$remove:=0
End case

If ($remove#0)
$text:=Substring:C12($text; $remove)
WP SET TEXT:C1574($paragraph; $text; wk replace:K81:177)
WP SET ATTRIBUTES:C1342($paragraph; wk font size:K81:66; $size)
End if

$p1:=Position:C15("**"; $text; 0)
If ($p1>0)
$p2:=Position:C15("**"; $text; $p1+1)
If ($p2>0)
$range:=WP Paragraph range:C1346($paragraph)
$range:=WP Text range:C1341($range; $range.start+$p1+1; $range.start+$p2-1)

WP SET ATTRIBUTES:C1342($range; wk font bold:K81:68; wk true:K81:174)

End if
End if

End for each

$replaced:=WP Find all:C1755($wp; "**"; wk all insensitive:K81:334; "")


Form:C1466.WPai:=WP New:C1317($wp)

11 changes: 11 additions & 0 deletions Project/Sources/Forms/D_AI_Prompt/ObjectMethods/Button4.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var $text : Text
var $range : Object

If (Form:C1466.selectedRow#Null:C1517)

$range:=Form:C1466.selectedRow.answerRange
$text:=WP Get text:C1575($range; wk expressions as value:K81:255)
WP SET TEXT:C1574(Form:C1466.wpSelection; $text; wk replace:K81:177)
End if


18 changes: 18 additions & 0 deletions Project/Sources/Forms/D_AI_Prompt/ObjectMethods/LB_Bookmarks.4dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var $range : Object

If (Form:C1466.bookmarks.length>0)

If (Form:C1466.selectedRow=Null:C1517)

Form:C1466.selectedRowID:=1
LISTBOX SELECT ROW:C912(*; "LB_Bookmarks"; 1; lk replace selection:K53:1)

Form:C1466.selectedRow:=Form:C1466.bookmarks[0]

End if


$range:=Form:C1466.selectedRow.answerRange
WP SELECT:C1348(*; "WParea"; $range.start; $range.start)

End if
Loading

0 comments on commit 824519b

Please sign in to comment.