Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/kotlin/com/learner/language/domain/ai/AiChatCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ class AiChatCommand {
}
}

data class TranscriptChatRequest(
val history: String,
val transcriptContext: String,
override val personaType: PersonaType,
override val input: String = history,
) : AiRequest(input, personaType) {
override fun createPrompt(aiPromptService: AiPromptService): Prompt {
return aiPromptService.createPrompt(this)
}
}

data class ChatRoomNameRequest(
override val input: String,
override val personaType: PersonaType,
Expand Down
44 changes: 44 additions & 0 deletions src/main/kotlin/com/learner/language/domain/ai/AiChatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ class AiChatService(
return chatMessage
}

fun generateTranscriptChat(
command: ChatCommand.Generate,
user: User,
chatRoom: ChatRoom,
chatHistory: String,
transcriptContext: String,
nextSequence: Int
): ChatMessage {
val aiRequest = AiChatCommand.AiRequest.TranscriptChatRequest(
history = chatHistory,
transcriptContext = transcriptContext,
personaType = command.personaType
)
val response = generate(aiRequest)
logger.info { "ai answer response generateTranscriptChat: ${response.response}" }

return command.toEntity(user, chatRoom, response.response, nextSequence)
}

fun greetingChat(personaType: PersonaType, user: User, chatRoom: ChatRoom, chatHistory: String, nextSequence: Int): ChatMessage {
val aiRequest = AiChatCommand.AiRequest.ChatRequest(
input = chatHistory,
Expand All @@ -88,6 +107,31 @@ class AiChatService(
return chatMessage
}

fun greetingTranscriptChat(
personaType: PersonaType,
user: User,
chatRoom: ChatRoom,
chatHistory: String,
transcriptContext: String,
nextSequence: Int
): ChatMessage {
val aiRequest = AiChatCommand.AiRequest.TranscriptChatRequest(
history = chatHistory,
transcriptContext = transcriptContext,
personaType = personaType
)
val response = generateGreeting(aiRequest)
logger.info { "ai answer response greetingTranscriptChat: ${response.response}" }

return ChatMessage(
user = user,
chatRoom = chatRoom,
message = response.response,
senderType = SenderType.AI,
sequence = nextSequence
)
}

fun phraseChat(
personaType: PersonaType,
user: User,
Expand Down
32 changes: 32 additions & 0 deletions src/main/kotlin/com/learner/language/domain/ai/AiPromptService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class AiPromptService(
private val systemFeedbackResource: Resource,
@Value("classpath:prompts/system-chat-message-0112-gpt.st") // gpt
private val systemChatResource: Resource,
@Value("classpath:prompts/system-transcript-chat-message.st")
private val systemTranscriptChatResource: Resource,
@Value("classpath:prompts/system-phrase-message.st")
private val systemPhraseResource: Resource,
@Value("classpath:prompts/system-chatroomname-message.st")
Expand All @@ -24,6 +26,8 @@ class AiPromptService(
private val userFeedbackResource: Resource,
@Value("classpath:prompts/user-chat-message.st")
private val userChatResource: Resource,
@Value("classpath:prompts/user-transcript-chat-message.st")
private val userTranscriptChatResource: Resource,
@Value("classpath:prompts/user-phrase-message.st")
private val userPhraseResource: Resource,
@Value("classpath:prompts/user-chatroomname-message.st")
Expand Down Expand Up @@ -58,6 +62,15 @@ class AiPromptService(
)
}

private fun createUserTranscriptChatMessage(history: String, transcriptContext: String): Message {
return PromptTemplate(userTranscriptChatResource).createMessage(
mapOf(
"history" to history,
"transcript_context" to transcriptContext,
)
)
}

private fun createUserChatRoomNameMessage(message: String): Message {
return PromptTemplate(userChatRoomNameResource).createMessage(
mapOf(
Expand All @@ -82,6 +95,13 @@ class AiPromptService(
)
)

private fun createSystemTranscriptChatMessage(personaType: PersonaType): Message =
SystemPromptTemplate(systemTranscriptChatResource).createMessage(
mapOf(
"persona" to toKoreanPersona(personaType)
)
)

private fun createSystemChatRoomNameMessage(): Message =
SystemPromptTemplate(systemChatRoomNameResource).createMessage(
)
Expand Down Expand Up @@ -116,6 +136,18 @@ class AiPromptService(
)
}

is AiChatCommand.AiRequest.TranscriptChatRequest -> {
Prompt(
listOf(
createUserTranscriptChatMessage(
aiChatRequest.history,
aiChatRequest.transcriptContext
),
createSystemTranscriptChatMessage(aiChatRequest.personaType)
)
)
}

is AiChatCommand.AiRequest.ChatRoomNameRequest -> {
Prompt(
listOf(
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/prompts/system-transcript-chat-message.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Role:
You are a Korean native-speaking AI conversation partner named "자모".
You speak in a natural Korean tone with this persona style: {persona}

Primary Goal:
- Talk with the user based on the provided video transcript context.
- Use the transcript as the main source of truth for topic, expressions, and situation.

Rules:
- Stay grounded in the transcript context and recent conversation history.
- If the user asks about a line, expression, or situation from the video, explain it clearly in Korean.
- If the transcript does not support a claim, say it is uncertain instead of making it up.
- Keep the conversation natural, not overly academic.
- You may help the user practice Korean expressions that appear in the transcript.
- Do not prefix responses with your name.
- Output Korean only.
9 changes: 9 additions & 0 deletions src/main/resources/prompts/user-transcript-chat-message.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Transcript Context:
"""
{transcript_context}
"""

Conversation History:
"""
{history}
"""