데모 페이지 수정- 발화 가이드 사용 후 페르소나 변경 등
This commit is contained in:
1 parent
f0e8071887
commit
310b85bf36
4 files changed
+55
-15
No files matched your search
@@ -4,3 +4,5 @@ __pycache__/
|
||||
|
||||
.env
|
||||
.claude/
|
||||
|
||||
*.pptx
|
||||
+36
-10
@@ -29,6 +29,9 @@
|
||||
button { padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); font: inherit; cursor: pointer; }
|
||||
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
button.small { padding: 2px 10px; font-size: 12px; margin-left: auto; }
|
||||
.speaker-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
|
||||
.speaker-picker button { padding: 4px 12px; font-size: 13px; }
|
||||
.speaker-picker button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
button:disabled { opacity: .5; cursor: default; }
|
||||
.error { margin-top: 8px; font-size: 12px; color: var(--danger); white-space: pre-wrap; }
|
||||
.empty { color: var(--muted); }
|
||||
@@ -77,6 +80,7 @@
|
||||
<label for="topic">토론 주제</label><textarea id="topic" rows="3"></textarea>
|
||||
|
||||
<h3>다음 화자</h3>
|
||||
<div class="speaker-picker" id="speakerPicker"></div>
|
||||
<label for="speakerName">이름</label><input id="speakerName">
|
||||
<label for="speakerKeywords">키워드 (쉼표로 구분)</label><input id="speakerKeywords">
|
||||
<div class="row">
|
||||
@@ -129,8 +133,7 @@ function resetState() {
|
||||
editingIndex: null, // 수정 중인 최신 발화의 위치
|
||||
pendingGuide: null, // { speaker, guide } — 아직 쓰이지 않은 다음 발화 가이드
|
||||
previousContext: null,
|
||||
previousPersonaInfo: null,
|
||||
personaKey: null,
|
||||
personaInfoByKey: new Map(), // 한 번이라도 모델에 보낸 화자의 페르소나 정보. 키는 personaKeyOf()
|
||||
lastResult: null,
|
||||
personaReused: false,
|
||||
});
|
||||
@@ -149,7 +152,7 @@ function readNextSpeaker() {
|
||||
};
|
||||
}
|
||||
|
||||
// 이전 페르소나 정보는 페르소나 입력과 토론 주제가 그대로일 때만 보낸다. 이 검증은 호스트(이 페이지)의 몫이다.
|
||||
// 페르소나 정보는 화자별로 저장해 두고, 페르소나 입력과 토론 주제가 같을 때 꺼내 보낸다. 이 검증은 호스트(이 페이지)의 몫이다.
|
||||
function personaKeyOf(input) {
|
||||
return JSON.stringify([input.next_speaker.persona, input.topic]);
|
||||
}
|
||||
@@ -172,7 +175,7 @@ function buildInput() {
|
||||
previous_context: state.previousContext,
|
||||
next_speaker: readNextSpeaker(),
|
||||
};
|
||||
input.previous_persona_info = personaKeyOf(input) === state.personaKey ? state.previousPersonaInfo : null;
|
||||
input.previous_persona_info = state.personaInfoByKey.get(personaKeyOf(input)) ?? null;
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -372,6 +375,11 @@ function render() {
|
||||
const editing = state.editingIndex !== null;
|
||||
$("runButton").disabled = !state.draftTurns.length || editing;
|
||||
$("manualButton").disabled = editing;
|
||||
|
||||
// 가이드를 만든 뒤에는 그 화자의 발화가 나올 때까지 다음 화자를 바꾸지 못하게 한다.
|
||||
const speakerLocked = Boolean(state.pendingGuide) && !state.draftTurns.length;
|
||||
for (const id of ["speakerName", "speakerKeywords", "speakerGender", "speakerAge"]) $(id).disabled = speakerLocked;
|
||||
for (const button of $("speakerPicker").querySelectorAll("button")) button.disabled = speakerLocked;
|
||||
}
|
||||
|
||||
async function runStyleGuide() {
|
||||
@@ -386,11 +394,10 @@ async function runStyleGuide() {
|
||||
draftTurns: [],
|
||||
pendingGuide: { speaker: input.next_speaker.name, guide: result.guide },
|
||||
previousContext: result.context,
|
||||
previousPersonaInfo: result.persona_info,
|
||||
personaKey: personaKeyOf(input),
|
||||
lastResult: result,
|
||||
personaReused: input.previous_persona_info !== null,
|
||||
});
|
||||
state.personaInfoByKey.set(personaKeyOf(input), result.persona_info);
|
||||
}
|
||||
|
||||
async function runDummyUtterance() {
|
||||
@@ -440,6 +447,26 @@ function cancelDraft() {
|
||||
render();
|
||||
}
|
||||
|
||||
// 저장해 둔 테스트용 화자. 버튼을 누르면 다음 화자 칸이 그 화자로 채워진다.
|
||||
let speakers = [];
|
||||
|
||||
function applySpeaker(speaker) {
|
||||
$("speakerName").value = speaker.name;
|
||||
$("speakerKeywords").value = speaker.persona.keywords.join(", ");
|
||||
$("speakerGender").value = speaker.persona.gender;
|
||||
$("speakerAge").value = speaker.persona.age ?? "";
|
||||
renderSpeakerPicker();
|
||||
}
|
||||
|
||||
function renderSpeakerPicker() {
|
||||
const current = $("speakerName").value.trim();
|
||||
$("speakerPicker").innerHTML = speakers.map((speaker, index) => `
|
||||
<button data-speaker-index="${index}" class="${speaker.name === current ? "active" : ""}">${escapeHtml(speaker.name)}</button>`).join("");
|
||||
for (const button of $("speakerPicker").querySelectorAll("button")) {
|
||||
button.addEventListener("click", () => applySpeaker(speakers[Number(button.dataset.speakerIndex)]));
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSample() {
|
||||
resetState();
|
||||
showError("");
|
||||
@@ -448,10 +475,8 @@ async function loadSample() {
|
||||
$("bookTitle").value = sample.book.title;
|
||||
$("bookAuthor").value = sample.book.author;
|
||||
$("topic").value = sample.topic;
|
||||
$("speakerName").value = sample.next_speaker.name;
|
||||
$("speakerKeywords").value = sample.next_speaker.persona.keywords.join(", ");
|
||||
$("speakerGender").value = sample.next_speaker.persona.gender;
|
||||
$("speakerAge").value = sample.next_speaker.persona.age ?? "";
|
||||
speakers = sample.speakers;
|
||||
applySpeaker(sample.next_speaker);
|
||||
state.draftTurns = sample.new_turns.map((turn) => ({ ...turn, isDummy: false }));
|
||||
} catch (error) {
|
||||
showError(`샘플 입력을 불러오지 못했습니다: ${error.message}`);
|
||||
@@ -459,6 +484,7 @@ async function loadSample() {
|
||||
render();
|
||||
}
|
||||
|
||||
$("speakerName").addEventListener("input", renderSpeakerPicker);
|
||||
$("runButton").addEventListener("click", (event) => withBusy(event.currentTarget, runStyleGuide));
|
||||
$("manualButton").addEventListener("click", startManualDraft);
|
||||
$("resetButton").addEventListener("click", loadSample);
|
||||
|
||||
@@ -12,7 +12,7 @@ from starlette.routing import Route
|
||||
from models.context import AnalysisInput
|
||||
from services.utterance_guide import generate_style_guide
|
||||
from tests.dummy_utterance import DummyUtteranceInput, generate_dummy_utterance
|
||||
from tests.test_modules import BOOK, NEXT_SPEAKER, TOPIC, TURN_1, TURN_2, TURN_3
|
||||
from tests.test_modules import BOOK, NEXT_SPEAKER, SPEAKERS, TOPIC, TURN_1, TURN_2, TURN_3
|
||||
|
||||
DEMO_HTML = Path(__file__).with_name("demo.html")
|
||||
|
||||
@@ -31,6 +31,7 @@ async def sample(request: Request) -> JSONResponse:
|
||||
"topic": TOPIC,
|
||||
"new_turns": [TURN_1.model_dump(), TURN_2.model_dump(), TURN_3.model_dump()],
|
||||
"next_speaker": NEXT_SPEAKER.model_dump(),
|
||||
"speakers": [speaker.model_dump() for speaker in SPEAKERS],
|
||||
})
|
||||
|
||||
|
||||
|
||||
+15
-4
@@ -33,10 +33,21 @@ TURN_3 = DiscussionTurn(
|
||||
text="그래도 그 쪽지를 건넨 것도 데미안이에요. 혼자였다면 알이 있다는 것조차 몰랐을 거예요.",
|
||||
)
|
||||
|
||||
NEXT_SPEAKER = NextSpeaker(
|
||||
name="서연",
|
||||
persona=PersonaInput(keywords=["침착함", "이성적", "논리적"], gender="Female"),
|
||||
)
|
||||
SPEAKERS = [
|
||||
NextSpeaker(
|
||||
name="민준",
|
||||
persona=PersonaInput(keywords=["열정적", "직관적", "감성적"], gender="Male", age=24),
|
||||
),
|
||||
NextSpeaker(
|
||||
name="서연",
|
||||
persona=PersonaInput(keywords=["침착함", "이성적", "논리적"], gender="Female"),
|
||||
),
|
||||
NextSpeaker(
|
||||
name="도윤",
|
||||
persona=PersonaInput(keywords=["호기심 많음", "질문형", "개방적"], gender="Male", age=31),
|
||||
),
|
||||
]
|
||||
NEXT_SPEAKER = SPEAKERS[1]
|
||||
|
||||
|
||||
def _print(title: str, model: BaseModel) -> None:
|
||||
|
||||
Reference in new issue
Block a user