forked from HemulGM/ChatGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChatGPT.Classes.pas
116 lines (93 loc) · 2.59 KB
/
ChatGPT.Classes.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
unit ChatGPT.Classes;
interface
uses
System.SysUtils, OpenAI.Chat.Functions;
{$SCOPEDENUMS ON}
type
TWindowMode = (Compact, Full);
TPartType = (Text, Code);
TMessageKind = (User, Assistant, System, Error, Func);
TMessageKindHelper = record helper for TMessageKind
function ToString: string;
class function FromString(const Value: string): TMessageKind; static;
end;
TMessageFuncState = (Wait, Success, Error, Executing);
TPart = record
PartType: TPartType;
Content: string;
Language: string;
end;
TUnderMouse = record
WordStart: Int64;
WordLength: Int64;
WordLine: Int64;
Text: string;
end;
TOnFuncExecute = procedure(Sender: TObject; const FuncName, FuncArgs: string; Callback: TProc<Boolean, string>) of object;
TOnNeedFuncList = procedure(Sender: TObject; out Items: TArray<IChatFunction>) of object;
TOnTextUpdated = procedure(Sender: TObject; const MessageId, Text: string) of object;
const
MaxMessageWidth = 850;
procedure OpenUrl(const URL: string);
implementation
uses
{$IFDEF ANDROID}
Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.NET,
{$ENDIF}
{$IFDEF IOS OR IOS64}
MacApi.Helpers, iOSApi.Foundation, FMX.Helpers.iOS,
{$ENDIF}
{$IFDEF POSIX}
Posix.Stdlib,
{$ENDIF POSIX}
{$IFDEF MSWINDOWS}
ShellAPI, DarkModeApi.FMX, FMX.Platform.Win,
{$ENDIF}
FMX.Platform;
procedure OpenUrl(const URL: string);
begin
{$IFDEF ANDROID}
TAndroidHelper.Context.startActivity(TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW, StrToJURI(URL)));
{$ENDIF}
{$IFDEF IOS OR IOS64}
SharedApplication.OpenURL(StrToNSUrl(URL));
{$ENDIF}
{$IFDEF POSIX}
_system(PAnsiChar('open ' + AnsiString(URL)));
{$ENDIF POSIX}
{$IFDEF MSWINDOWS}
ShellExecute(0, 'open', PChar(URL), nil, nil, 1);
{$ENDIF}
end;
{ TMessageKindHelper }
class function TMessageKindHelper.FromString(const Value: string): TMessageKind;
begin
if Value = 'system' then
Exit(TMessageKind.System)
else if Value = 'user' then
Exit(TMessageKind.User)
else if Value = 'assistant' then
Exit(TMessageKind.Assistant)
else if Value = 'error' then
Exit(TMessageKind.Error)
else if Value = 'function' then
Exit(TMessageKind.Func)
else
Result := TMessageKind.User;
end;
function TMessageKindHelper.ToString: string;
begin
case Self of
TMessageKind.System:
Result := 'system';
TMessageKind.User:
Result := 'user';
TMessageKind.Assistant:
Result := 'assistant';
TMessageKind.Error:
Result := 'error';
TMessageKind.Func:
Result := 'function';
end;
end;
end.