From Clomosy Docs
Clomosy Seminar Demos
The codes of the examples we prepared during the Clomosy seminar event are provided here.
These examples are written to demonstrate the features of Clomosy infrastructure. As Clomosy developers, you can improve these examples and use the features within them in other applications.
Artificial Intelligence Example
A conversational AI chat engine specialized in dialogue using the OpenAI engine has been developed within the Clomosy infrastructure, and it has been utilized in this example.
Code:
var
MyForm:TclForm;
BtnSend:TclProButton;
LblDisplay:TclLabel;
MemMsg:TclMemo;
ghMsgList,MsgList:TclMemo;
MyOpenAIEngine:TclOpenAIEngine;
bigPanel,smallPanel:TclProPanel;
bigLyt:TClLayout;
sendLbl:TClProLabel;
MyMQTT : TclMQTT;
GetTimer,
settingsTmr: TClTimer;
counter:integer;
Procedure BtnSendClick;
begin
if Clomosy.AppUserProfile=1 then
begin
if MemMsg.Text = '' then
begin
ShowMessage('Please write your message.!');
end
else
begin
MyOpenAIEngine.SendAIMessage(MemMsg.Text);
MemMsg.Text := '';
end;
end;
End;
Procedure OnNewMessageEvent;
begin
if MyMQTT.ReceivedAlright = False then
begin
MsgList.Lines.Add('');
MyMQTT.Send(MyOpenAIEngine.NewMessageContent);
if Clomosy.AppUserProfile = 1 then
MsgList.Lines.Add(MyOpenAIEngine.NewMessageContent);
MsgList.ScrollTo(0,MsgList.Lines.Count*MsgList.Lines.Count,True);
end;
End;
Procedure MyMQTTStatusChanged;
begin
If MyMQTT.Connected Then
begin
LblDisplay.TextSettings.FontColor := clAlphaColor.clHexToColor('#00ff00');
end
Else
begin
LblDisplay.TextSettings.FontColor := clAlphaColor.clHexToColor('#ff0000');
end;
End;
Procedure MyMQTTPublishReceived;
begin
If MyMQTT.ReceivedAlright Then
Begin
if Clomosy.AppUserProfile <> 1 then
begin
MsgList.Lines.Add('');
MsgList.Lines.Add(' ' + MyMQTT.ReceivedMessage);
MsgList.ScrollTo(0,MsgList.Lines.Count*MsgList.Lines.Count,True);
if MyMQTT.ReceivedMessage = 'e95vX2faG@3M' then
begin
MsgList.Text := '';
MsgList.Visible := False;
end;
if MyMQTT.ReceivedMessage = '52eJz#EzV6Yz' then
begin
MsgList.Text := '';
MsgList.Visible := True;
end;
end;
End;
end;
procedure runTimer;
begin
Dec(counter);
BtnSend.caption := IntToStr(counter);
if counter = 19 then
begin
if Clomosy.AppUserProfile = 1 then
begin
MyMQTT.Send('e95vX2faG@3M');
MyOpenAIEngine.SendAIMessage('Clomosy stands for cloud mobile system.
Currently, we are testing an OpenAI chatbot application through Clomosy.
Clomosy is a platform that enables businesses to develop custom mobile applications to meet their specific needs.
It is a cloud-based mobile application development system that allows for the creation of user-friendly,
customizable, and platform-independent mobile applications that can be developed for different platforms such as Android, iOS, and Windows.
To become a Clomosy developer, you need to create an account on the website (clomosy.com).
To use the projects you have developed on Clomosy, you need to upload the applications from the platforms (AppStore/PlayStore).
You can visit docs.clomosy.com to access Clomosy documentation.');
end;
end;
if counter <=0 then
begin
if Clomosy.AppUserProfile = 1 then
begin
ShowMessage('Now you can start asking your questions.');
MemMsg.Enabled := True;
MemMsg.SetFocus;
BtnSend.Enabled := True;
BtnSend.caption := 'Send';
end;
MsgList.Visible := True;
MsgList.Text := '';
GetTimer.Enabled := False;
counter := 20;
MyMQTT.Send('52eJz#EzV6Yz');
end;
end;
begin
MyForm := TclForm.Create(Self);
MyForm.SetFormBGImage('https://clomosy.com/educa/bg5.png');
bigLyt := MyForm.AddNewLayout(MyForm,'bigLyt');
bigLyt.Align:=alContents;
bigLyt.Margins.Left:=20;
bigLyt.Margins.Right:=20;
bigLyt.Margins.Top:=30;
bigLyt.Margins.Bottom:=30;
smallPanel:=MyForm.AddNewProPanel(bigLyt,'smallPanel');
clComponent.SetupComponent(smallPanel,'{"Align" : "Top","Width" :300,"Height":50,"RoundHeight":10,
"MarginBottom":10,"RoundWidth":10,"BorderColor":"#808080","BorderWidth":2,"BackgroundColor":"9b9b9b"}');
LblDisplay:= MyForm.AddNewLabel(smallPanel,'LblDisplay','CLOMOSY Artificial Intelligence');
LblDisplay.Align := alcenter;
LblDisplay.StyledSettings := ssFamily;
LblDisplay.TextSettings.Font.Size := 18;
LblDisplay.TextSettings.FontColor := clAlphaColor.clHexToColor('#000000');
LblDisplay.Margins.Left:=10;
LblDisplay.Margins.Right:=10;
LblDisplay.Height:=45;
LblDisplay.Width := 200;
MyMQTT := MyForm.AddNewMQTTConnection(MyForm,'MyMQTT');
MyForm.AddNewEvent(MyMQTT,tbeOnMQTTStatusChanged,'MyMQTTStatusChanged');
MyForm.AddNewEvent(MyMQTT,tbeOnMQTTPublishReceived,'MyMQTTPublishReceived');
MyMQTT.Channel := 'chat';//project guid + channel
MyMQTT.Connect;
bigPanel:=MyForm.AddNewProPanel(bigLyt,'bigPanel');
clComponent.SetupComponent(bigPanel,'{"Align" : "Client","MarginRight":10,"MarginLeft":10,
"RoundHeight":10,"RoundWidth":10,"BorderColor":"#008000","BorderWidth":3}');
MsgList:= MyForm.AddNewMemo(bigPanel,'MsgList','');
MsgList.Align := alClient;
MsgList.ReadOnly := True;
MsgList.Margins.Top:= 10;
MsgList.Margins.Left:= 10;
MsgList.Margins.Right :=10;
MsgList.TextSettings.Font.Size:=26;
MsgList.TextSettings.WordWrap := True;
MsgList.EnabledScroll := True;
MsgList.Visible := False;
if Clomosy.AppUserProfile = 1 then
begin
MemMsg:= MyForm.AddNewMemo(bigPanel,'MemMsg','');
MemMsg.Align := alBottom;
MemMsg.Height := MemMsg.Height * 2;
MemMsg.Margins.Right:=10;
MemMsg.Margins.Left:=10;
MemMsg.Margins.Bottom:= 10;
MemMsg.Enabled := False;
sendLbl := MyForm.AddNewProLabel(bigPanel,'sendLbl','Write your message');
clComponent.SetupComponent(sendLbl,'{"Align" : "Bottom","MarginBottom":5,"MarginTop":5,
"MarginLeft":15,"Width" :150,"Height":15,"TextColor":"#000000","TextSize":10,"TextVerticalAlign":"center",
"TextHorizontalAlign":"left","TextBold":"yes"}');
BtnSend := MyForm.AddNewProButton(bigPanel,'BtnSend','');
clComponent.SetupComponent(BtnSend,'{"caption":"GÖNDER","Align" : "MostBottom",
"MarginLeft":100,"MarginRight":100,"RoundHeight":2, "RoundWidth":2,"MarginBottom":8,
"BorderColor":"#808080","BorderWidth":2,"TextBold":"yes"}');
BtnSend.Enabled := False;
MyForm.AddNewEvent(BtnSend,tbeOnClick,'BtnSendClick');
MyOpenAIEngine:=TclOpenAIEngine.Create(Self);
MyOpenAIEngine.ParentForm := MyForm;
MyOpenAIEngine.SetToken('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');
MyOpenAIEngine.OnNewMessageEvent := 'OnNewMessageEvent';
ShowMessage('Hello! Wait for me to get ready. After 20 seconds you can manage me the problem.');
counter := 20;
BtnSend.Caption := IntToStr(counter);
GetTimer:= MyForm.AddNewTimer(MyForm,'GetTimer',1000);
GetTimer.Enabled := True;
MyForm.AddNewEvent(GetTimer,tbeOnTimer,'runTimer');
end;
MyForm.Run;
End;