Skip to content

Commit dd3b342

Browse files
committed
feat: LLM 개선
1 parent db00b15 commit dd3b342

File tree

15 files changed

+738
-133
lines changed

15 files changed

+738
-133
lines changed

ProjectVG.Api/Controllers/ChatController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task<IActionResult> ProcessChat([FromBody] ChatRequest request)
3131
userGuid,
3232
request.CharacterId,
3333
request.Message,
34-
DateTime.UtcNow,
34+
request.RequestAt,
3535
request.UseTTS);
3636

3737
var result = await _chatService.EnqueueChatRequestAsync(command);

ProjectVG.Api/Models/Chat/Request/ChatRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ public class ChatRequest
1616

1717
[JsonPropertyName("use_tts")]
1818
public bool UseTTS { get; set; } = true;
19+
20+
[JsonPropertyName("request_at")]
21+
public DateTime RequestAt { get; set; }
1922
}
2023
}

ProjectVG.Application/Models/Chat/ChatMessageSegment.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
namespace ProjectVG.Application.Models.Chat
22
{
3+
public enum SegmentType
4+
{
5+
Text = 0,
6+
Action = 1
7+
}
8+
39
public class ChatMessageSegment
410
{
511
public string? Text { get; set; }
612
public byte[]? AudioData { get; set; }
713
public string? AudioContentType { get; set; }
814
public float? AudioLength { get; set; }
915
public string? Emotion { get; set; }
16+
public string? Action { get; set; }
17+
public SegmentType Type { get; set; } = SegmentType.Text;
1018
public int Order { get; set; }
1119

1220
public bool HasText => !string.IsNullOrEmpty(Text);
1321
public bool HasAudio => AudioData != null && AudioData.Length > 0;
14-
public bool IsEmpty => !HasText && !HasAudio;
22+
public bool IsEmpty => !HasText && !HasAudio && string.IsNullOrEmpty(Action);
23+
public bool IsTextSegment => Type == SegmentType.Text && HasText;
24+
public bool IsActionSegment => Type == SegmentType.Action && !string.IsNullOrEmpty(Action);
1525

1626

1727
public static ChatMessageSegment CreateTextOnly(string text, int order = 0)
1828
{
1929
return new ChatMessageSegment
2030
{
2131
Text = text,
32+
Type = SegmentType.Text,
33+
Order = order
34+
};
35+
}
36+
37+
public static ChatMessageSegment CreateActionOnly(string action, int order = 0)
38+
{
39+
return new ChatMessageSegment
40+
{
41+
Action = action,
42+
Type = SegmentType.Action,
2243
Order = order
2344
};
2445
}

ProjectVG.Application/Models/Chat/ChatProcessContext.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ChatProcessContext
1010
public Guid CharacterId { get; private set; }
1111
public string UserMessage { get; private set; } = string.Empty;
1212
public string MemoryStore { get; private set; } = string.Empty;
13+
public DateTime UserRequestAt { get; private set; } = DateTime.Now;
1314
public bool UseTTS { get; private set; } = true;
1415

1516
public CharacterDto? Character { get; private set; }
@@ -19,11 +20,6 @@ public class ChatProcessContext
1920
public string Response { get; private set; } = string.Empty;
2021
public double Cost { get; private set; }
2122
public List<ChatMessageSegment> Segments { get; private set; } = new List<ChatMessageSegment>();
22-
23-
public string FullText => string.Join(" ", Segments.Where(s => s.HasText).Select(s => s.Text));
24-
public bool HasAudio => Segments.Any(s => s.HasAudio);
25-
public bool HasText => Segments.Any(s => s.HasText);
26-
2723

2824
public ChatProcessContext(ChatRequestCommand command)
2925
{
@@ -32,6 +28,7 @@ public ChatProcessContext(ChatRequestCommand command)
3228
UserMessage = command.UserPrompt;
3329
MemoryStore = command.UserId.ToString();
3430
UseTTS = command.UseTTS;
31+
UserRequestAt = command.UserRequestAt;
3532
}
3633

3734
public ChatProcessContext(
@@ -67,9 +64,7 @@ public IEnumerable<string> ParseConversationHistory(int count = 5)
6764
{
6865
if (ConversationHistory == null) return Enumerable.Empty<string>();
6966

70-
return ConversationHistory
71-
.Take(count)
72-
.Select(h => $"{h.Role}: {h.Content}");
67+
return ConversationHistory.Take(count).Select(h => $"{h.Role}: {h.Content}");
7368
}
7469
}
7570
}

ProjectVG.Application/Services/Auth/AuthService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ public async Task<AuthResult> LoginWithOAuthAsync(string provider, string provid
3939

4040
if (user == null)
4141
{
42+
string uuid = providerUserId.Substring(0, Math.Min(providerUserId.Length, 20));
4243
// 새로운 게스트 사용자 생성
4344
var createCommand = new UserCreateCommand(
44-
Username: $"guest_{providerUserId.Substring(0, 20)}",
45-
Email: $"guest@guest{providerUserId.Substring(0,20)}.local",
45+
Username: $"guest_{uuid}",
46+
Email: $"guest@guest{uuid}.local",
4647
ProviderId: providerUserId,
4748
Provider: "guest"
4849
);

ProjectVG.Application/Services/Chat/ChatService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ private async Task<ChatProcessContext> PrepareChatRequestAsync(ChatRequestComman
9393
var conversationHistoryContext = await _conversationService.GetConversationHistoryAsync(command.UserId, command.CharacterId, 10);
9494
var memoryContext = await _memoryPreprocessor.CollectMemoryContextAsync(command);
9595

96-
return new ChatProcessContext(command, characterInfo, conversationHistoryContext, memoryContext);
96+
97+
98+
return new ChatProcessContext(
99+
command,
100+
characterInfo,
101+
conversationHistoryContext,
102+
memoryContext
103+
);
97104
}
98105

99106
/// <summary>

0 commit comments

Comments
 (0)