11using MaIN . Domain . Entities ;
22using MaIN . Domain . Models ;
3+ using MaIN . Services . Constants ;
34using MaIN . Services . Dtos ;
45using MaIN . Services . Services . Abstract ;
56using MaIN . Services . Services . Models ;
@@ -10,8 +11,9 @@ namespace MaIN.Core.Hub.Contexts;
1011public class ChatContext
1112{
1213 private readonly IChatService _chatService ;
14+ private bool _preProcess ;
1315 private Chat _chat { get ; set ; }
14- private List < FileInfo > _files { get ; set ; }
16+ private List < FileInfo > _files { get ; set ; } = [ ] ;
1517
1618 internal ChatContext ( IChatService chatService )
1719 {
@@ -84,7 +86,7 @@ public ChatContext WithSystemPrompt(string systemPrompt)
8486 return this ;
8587 }
8688
87- public ChatContext WithFiles ( List < FileStream > fileStreams )
89+ public ChatContext WithFiles ( List < FileStream > fileStreams , bool preProcess = false )
8890 {
8991 var files = fileStreams . Select ( p => new FileInfo ( )
9092 {
@@ -94,17 +96,19 @@ public ChatContext WithFiles(List<FileStream> fileStreams)
9496 StreamContent = p
9597 } ) . ToList ( ) ;
9698
99+ _preProcess = preProcess ;
97100 _files = files ;
98101 return this ;
99102 }
100103
101- public ChatContext WithFiles ( List < FileInfo > files )
104+ public ChatContext WithFiles ( List < FileInfo > files , bool preProcess = false )
102105 {
103106 _files = files ;
107+ _preProcess = preProcess ;
104108 return this ;
105109 }
106110
107- public ChatContext WithFiles ( List < string > filePaths )
111+ public ChatContext WithFiles ( List < string > filePaths , bool preProcess = false )
108112 {
109113 var files = filePaths . Select ( p => new FileInfo ( )
110114 {
@@ -113,6 +117,7 @@ public ChatContext WithFiles(List<string> filePaths)
113117 Extension = Path . GetExtension ( p )
114118 } ) . ToList ( ) ;
115119
120+ _preProcess = preProcess ;
116121 _files = files ;
117122 return this ;
118123 }
@@ -135,6 +140,11 @@ public async Task<ChatResult> CompleteAsync(
135140 throw new InvalidOperationException ( "Chat has no messages." ) ; //TODO good candidate for domain exception
136141 }
137142 _chat . Messages . Last ( ) . Files = _files ;
143+ if ( _preProcess )
144+ {
145+ _chat . Messages . Last ( ) . Properties . Add ( ServiceConstants . Messages . PreProcessProperty , string . Empty ) ;
146+ }
147+
138148 if ( ! await ChatExists ( _chat . Id ) )
139149 {
140150 await _chatService . Create ( _chat ) ;
0 commit comments