@@ -38,6 +38,12 @@ public partial class AiChatControl : WeifenLuo.WinFormsUI.Docking.DockContent
3838
3939 public AiChatControl ( FetchXmlBuilder fetchXmlBuilder )
4040 {
41+ ChatMessageHistory . UserTextColor = OnlineSettings . Instance . Colors . Bright ;
42+ ChatMessageHistory . UserBackgroundColor = OnlineSettings . Instance . Colors . Medium ;
43+ ChatMessageHistory . AssistansTextColor = OnlineSettings . Instance . Colors . Dark ;
44+ ChatMessageHistory . AssistansBackgroundColor = OnlineSettings . Instance . Colors . Bright ;
45+ ChatMessageHistory . WaitingBackColor = Color . FromArgb ( 240 , 240 , 240 ) ;
46+
4147 fxb = fetchXmlBuilder ;
4248 InitializeComponent ( ) ;
4349 Initialize ( ) ;
@@ -50,12 +56,6 @@ public AiChatControl(FetchXmlBuilder fetchXmlBuilder)
5056
5157 internal void Initialize ( )
5258 {
53- ChatMessageHistory . UserTextColor = OnlineSettings . Instance . Colors . Bright ;
54- ChatMessageHistory . UserBackgroundColor = OnlineSettings . Instance . Colors . Medium ;
55- ChatMessageHistory . AssistansTextColor = OnlineSettings . Instance . Colors . Dark ;
56- ChatMessageHistory . AssistansBackgroundColor = OnlineSettings . Instance . Colors . Bright ;
57- ChatMessageHistory . WaitingBackColor = Color . FromArgb ( 240 , 240 , 240 ) ;
58-
5959 freeusers = null ;
6060 ClosingSession ( ) ;
6161
@@ -77,9 +77,13 @@ internal void Initialize()
7777 var apikey = "" ;
7878 if ( supplier . IsFree )
7979 {
80+ logname = "AI-Free" ;
8081 if ( ! IsFreeAiUser ( fxb ) )
8182 {
82- PromptToUseForFree ( fxb ) ;
83+ if ( MessageBoxEx . Show ( fxb , $ "To use the free AI provider, you have to fill in this form.\n On this webpage you can read details about why and why.", "Free AI by Jonas" , MessageBoxButtons . OKCancel ) == DialogResult . OK )
84+ {
85+ PromptToUseForFree ( fxb ) ;
86+ }
8387 return ;
8488 }
8589 apikey = model . ApiKey ;
@@ -110,14 +114,18 @@ internal static bool IsFreeAiUser(PluginControlBase tool)
110114
111115 internal static void PromptToUseForFree ( PluginControlBase tool )
112116 {
113- if ( MessageBoxEx . Show ( tool , $ "To use the free AI provider, you have to fill in this form.\n On this webpage you can read details about why and why.", "Free AI by Jonas" , MessageBoxButtons . OKCancel ) == DialogResult . OK )
114- {
115- var url = OnlineSettings . Instance . AiSupport . UrlToUseForFree ;
116- var wpf = OnlineSettings . Instance . AiSupport . WpfToUseForFree ;
117- var installid = InstallationInfo . Instance . InstallationId ;
118- var version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ;
119- Process . Start ( $ "{ url } ?wpf{ wpf } _31={ tool . ToolName } &wpf{ wpf } _32={ version } &wpf{ wpf } _33={ installid } ") ;
120- }
117+ var install = Installation . Load ( null ) ;
118+ var url = OnlineSettings . Instance . AiSupport . UrlToUseForFree ;
119+ var wpf = OnlineSettings . Instance . AiSupport . WpfToUseForFree ;
120+ var installid = InstallationInfo . Instance . InstallationId ;
121+ var version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ;
122+ var fullurl = $ "{ url } ?" +
123+ $ "wpf{ wpf } _1_first={ install ? . PersonalFirstName } &" +
124+ $ "wpf{ wpf } _1_last={ install ? . PersonalLastName } &" +
125+ $ "wpf{ wpf } _3={ install ? . PersonalCountry } &" +
126+ $ "wpf{ wpf } _4={ install ? . PersonalEmail } &" +
127+ $ "wpf{ wpf } _31={ tool . ToolName } &wpf{ wpf } _32={ version } &wpf{ wpf } _33={ installid } ";
128+ Process . Start ( fullurl ) ;
121129 }
122130
123131 #endregion Internal Methods
@@ -225,7 +233,7 @@ private void SendChatToAI(object sender, EventArgs e = null)
225233 intro += Environment . NewLine + PromptMyName . Replace ( "{callme}" , fxb . settings . AiSettings . MyName ) . Trim ( ) ;
226234 }
227235 chatHistory . Initialize ( intro ) ;
228- fxb . LogUse ( $ "{ logname } - { model } -Init", count : intro . Length , ai2 : true , ai1 : false ) ;
236+ Log ( $ "{ model } -Init", count : intro . Length ) ;
229237 sessionstopwatch = Stopwatch . StartNew ( ) ;
230238 }
231239 else if ( ! manualquery . EqualXml ( lastquery ) )
@@ -236,7 +244,7 @@ private void SendChatToAI(object sender, EventArgs e = null)
236244
237245 chatHistory . IsRunning = true ;
238246 EnableButtons ( ) ;
239- fxb . LogUse ( $ " { logname } - { action } " , count : text . Length , ai2 : true , ai1 : false ) ;
247+ Log ( action , count : text . Length ) ;
240248 callingstopwatch = Stopwatch . StartNew ( ) ;
241249 try
242250 {
@@ -261,7 +269,7 @@ private void SendChatToAI(object sender, EventArgs e = null)
261269 private void HandlingResponseFromAi ( ChatResponse response )
262270 {
263271 callingstopwatch ? . Stop ( ) ;
264- fxb . LogUse ( $ " { logname } - Response", count : response ? . ToString ( ) ? . Length , duration : callingstopwatch ? . ElapsedMilliseconds , ai2 : true , ai1 : false ) ;
272+ Log ( " Response", response ? . ToString ( ) ? . Length , callingstopwatch ? . ElapsedMilliseconds ) ;
265273 txtAiChat . Clear ( ) ;
266274 txtUsage . Text = chatHistory . Responses . UsageToString ( ) ;
267275 EnableButtons ( ) ;
@@ -277,7 +285,7 @@ private string ExecuteFetchXMLQuery([Description("The FetchXML Query to be Execu
277285 var sw = Stopwatch . StartNew ( ) ;
278286 var result = fxb . RetrieveMultipleSync ( fetchXml , null , null ) ;
279287 sw . Stop ( ) ;
280- fxb . LogUse ( $ "{ logname } - Query-Execute", count : result is QueryInfo qi ? qi . Results . Entities . Count : 0 , duration : sw . ElapsedMilliseconds , ai2 : true , ai1 : false ) ;
288+ Log ( $ "Query-Execute", result is QueryInfo qi ? qi . Results . Entities . Count : 0 , sw . ElapsedMilliseconds ) ;
281289 fxb . HandleRetrieveMultipleResult ( result ) ;
282290 //fxb.dockControlGrid?.ResetLayout(); Commented it out since it exploded, but it might be good to do this after each new query execute
283291 return "Query executed successfully" ;
@@ -321,7 +329,7 @@ private string GetMetadataForUnknownEntity([Description("The name/description of
321329 var result = AiCommunication . SamplingAI ( PromptEntityMeta . Replace ( "{metadata}" , json ) ,
322330 $ "Please find entries that match the description { tableDescription } ", chatHistory ) ;
323331 sw . Stop ( ) ;
324- fxb . LogUse ( $ "{ logname } - Meta-Entity-{ tableDescription } ", count : entities . Count , duration : sw . ElapsedMilliseconds , ai2 : true , ai1 : false ) ;
332+ Log ( $ "Meta-Entity-{ tableDescription } ", entities . Count , sw . ElapsedMilliseconds ) ;
325333
326334 chatHistory . Add ( result , true ) ;
327335 return result . Text ;
@@ -359,7 +367,7 @@ private string GetMetadataForUnknownAttribute([Description("The logical name of
359367 var result = AiCommunication . SamplingAI ( PromptAttributeMeta . Replace ( "{metadata}" , json ) ,
360368 $ "Please find attributes that match the description { attributeDescription } ", chatHistory ) ;
361369 sw . Stop ( ) ;
362- fxb . LogUse ( $ "{ logname } - Meta-Attribute-{ entityName } ", count : attributes . Count , duration : sw . ElapsedMilliseconds , ai2 : true , ai1 : false ) ;
370+ Log ( $ "Meta-Attribute-{ entityName } ", attributes . Count , sw . ElapsedMilliseconds ) ;
363371
364372 chatHistory . Add ( result , true ) ;
365373
@@ -375,7 +383,7 @@ private void SetQueryFromAi(string fetch)
375383 lastquery = fetch ;
376384 MethodInvoker mi = ( ) => { fxb . dockControlBuilder . Init ( fetch , null , false , "Query from AI" , true ) ; } ;
377385 if ( InvokeRequired ) Invoke ( mi ) ; else mi ( ) ;
378- fxb . LogUse ( $ "{ logname } - Query-Change", ai2 : true , ai1 : false ) ;
386+ Log ( $ "Query-Change") ;
379387 }
380388
381389 private void PopupMessageIfRelevant ( )
@@ -410,15 +418,22 @@ private void ClosingSession()
410418 chatHistory . Save ( Paths . LogsPath , "FXB" ) ;
411419 if ( manualcalls > 0 )
412420 {
413- fxb . LogUse ( $ "{ logname } - Session-Calls", count : manualcalls , ai2 : true , ai1 : false ) ;
421+ Log ( $ "Session-Calls", count : manualcalls ) ;
414422 }
415- if ( chatHistory ? . Initialized == true )
423+ if ( chatHistory . Initialized )
416424 {
417- fxb . LogUse ( $ "{ logname } -Closing ", count : chatHistory . Responses ? . Count , duration : sessionstopwatch ? . ElapsedMilliseconds , ai2 : true , ai1 : false ) ;
425+ Log ( $ "Session-Responses ", chatHistory . Responses ? . Count , sessionstopwatch ? . ElapsedMilliseconds ) ;
418426 }
427+ chatHistory = null ;
428+ Log ( "Close" ) ;
419429 }
420430 }
421431
432+ private void Log ( string action , double ? count = null , double ? duration = null )
433+ {
434+ fxb . LogUse ( $ "{ logname } -{ action } ", false , count , duration , false , true ) ;
435+ }
436+
422437 #endregion Private Methods
423438
424439 #region Private Event Handlers
0 commit comments