1
1
using System . Diagnostics ;
2
2
using System . Text . Json ;
3
+ using AI . Model . Services ;
4
+ using AI . Services ;
5
+ using ChatGPT . Model . Services ;
6
+ using ChatGPT . Services ;
3
7
using ChatGPT . ViewModels ;
4
8
using ChatGPT . ViewModels . Chat ;
5
9
@@ -8,6 +12,14 @@ namespace ChatGPT.CLI;
8
12
internal static class Chat
9
13
{
10
14
private static readonly Action < object > ? s_log = Console . WriteLine ;
15
+ private static readonly IChatSerializer s_chatSerializer ;
16
+ private static readonly IChatService s_chatService ;
17
+
18
+ static Chat ( )
19
+ {
20
+ s_chatSerializer = new SystemTextJsonChatSerializer ( ) ;
21
+ s_chatService = new ChatService ( s_chatSerializer ) ;
22
+ }
11
23
12
24
private static async Task RunJob ( ChatJob job , CancellationToken token )
13
25
{
@@ -19,7 +31,7 @@ private static async Task RunJob(ChatJob job, CancellationToken token)
19
31
}
20
32
21
33
var input = await File . ReadAllTextAsync ( job . InputPath , token ) ;
22
- var chat = new ChatViewModel ( job . Settings ) ;
34
+ var chat = new ChatViewModel ( s_chatService , s_chatSerializer , job . Settings ) ;
23
35
chat . AddSystemMessage ( job . Settings . Directions ) ;
24
36
chat . AddUserMessage ( input ) ;
25
37
var result = await chat . SendAsync ( chat . CreateChatMessages ( ) , token ) ;
@@ -129,7 +141,7 @@ private static List<ChatJob> GetJobs(CliSettings cliSettings, List<FileInfo> pat
129
141
using var stream = File . OpenRead ( cliSettings . SettingsFile . FullName ) ;
130
142
fileSettings = JsonSerializer . Deserialize (
131
143
stream ,
132
- MainViewModelJsonContext . s_instance . ChatSettingsViewModel ) ;
144
+ CoreJsonContext . s_instance . ChatSettingsViewModel ) ;
133
145
}
134
146
135
147
var chatSettings = fileSettings ?? new ChatSettingsViewModel
0 commit comments