2024-09-15 20:06:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								using  AIStudio.Chat ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-12 10:31:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								using  AIStudio.Dialogs.Settings ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-15 20:06:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								namespace  AIStudio.Assistants.LegalCheck ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-12 10:31:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								public  partial  class  AssistantLegalCheck  :  AssistantBaseCore < SettingsDialogLegalCheck > 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-14 17:20:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    public  override  Tools . Components  Component  = >  Tools . Components . LEGAL_CHECK_ASSISTANT ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-04 13:44:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2025-04-27 07:06:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  string  Title  = >  T ( "Legal Check" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2025-04-27 07:06:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  string  Description  = >  T ( "Provide a legal document and ask a question about it. This assistant does not replace legal advice. Consult a lawyer to get professional advice. Remember that LLMs can invent answers and facts. Please do not rely on this answers." ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    protected  override  string  SystemPrompt  = >  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "" "
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        You  are  an  expert  in  legal  matters .  You  have  studied  international  law  and  are  familiar  with  the  law  in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        various  countries .  You  receive  a  legal  document  and  answer  the  user ' s  questions .  You  are  a  friendly  and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        professional  assistant .  You  respond  to  the  user  in  the  language  in  which  the  questions  were  asked .  If 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        you  are  unsure ,  unfamiliar  with  the  legal  area ,  or  do  not  know  the  answers ,  you  inform  the  user . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        Never  invent  facts ! 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "" ";
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2024-09-04 13:44:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  IReadOnlyList < IButtonData >  FooterButtons  = >  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2025-04-27 07:06:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  string  SubmitText  = >  T ( "Ask your questions" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-11 21:08:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    protected  override  Func < Task >  SubmitAction  = >  this . AksQuestions ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-12 10:31:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-11 21:08:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  bool  SubmitDisabled  = >  this . isAgentRunning ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2024-09-15 20:06:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  ChatThread  ConvertToChatThread  = >  ( this . chatThread  ? ?  new ( ) )  with 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        SystemPrompt  =  SystemPrompts . DEFAULT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2025-01-01 14:49:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    protected  override  void  ResetForm ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        this . inputLegalDocument  =  string . Empty ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        this . inputQuestions  =  string . Empty ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-01 17:13:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        if  ( ! this . MightPreselectValues ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . showWebContentReader  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . useContentCleanerAgent  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    protected  override  bool  MightPreselectValues ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( this . SettingsManager . ConfigurationData . LegalCheck . PreselectOptions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . showWebContentReader  =  this . SettingsManager . ConfigurationData . LegalCheck . PreselectWebContentReader ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . useContentCleanerAgent  =  this . SettingsManager . ConfigurationData . LegalCheck . PreselectContentCleanerAgent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-04 13:44:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-01 17:13:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    private  bool  showWebContentReader ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  bool  useContentCleanerAgent ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    private  bool  isAgentRunning ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  string  inputLegalDocument  =  string . Empty ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  string  inputQuestions  =  string . Empty ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    #region  Overrides  of  ComponentBase 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    protected  override  async  Task  OnInitializedAsync ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        var  deferredContent  =  MessageBus . INSTANCE . CheckDeferredMessages < string > ( Event . SEND_TO_LEGAL_CHECK_ASSISTANT ) . FirstOrDefault ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( deferredContent  is  not  null ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . inputQuestions  =  deferredContent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        await  base . OnInitializedAsync ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    #endregion 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  string?  ValidatingLegalDocument ( string  text ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if ( string . IsNullOrWhiteSpace ( text ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2025-04-27 07:06:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  T ( "Please provide a legal document as input. You might copy the desired text from a document or a website." ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  string?  ValidatingQuestions ( string  text ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if ( string . IsNullOrWhiteSpace ( text ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2025-04-27 07:06:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            return  T ( "Please provide your questions as input." ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-23 19:47:07 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    private  async  Task  AksQuestions ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        await  this . form ! . Validate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( ! this . inputIsValid ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        this . CreateChatThread ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        var  time  =  this . AddUserRequest ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $"" "
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                #  The  legal  document 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                { this . inputLegalDocument } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                #  The  questions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                { this . inputQuestions } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								             "" ");
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        await  this . AddAIResponseAsync ( time ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}