Merge branch 'phone-interface'
This commit is contained in:
@@ -103,7 +103,7 @@ DEFAULT_INSTRUCTIONS = """# 角色
|
|||||||
- 一次询问一个问题
|
- 一次询问一个问题
|
||||||
- 不要在你的回复中使用 emojis, asterisks, markdown, 或其他特殊字符
|
- 不要在你的回复中使用 emojis, asterisks, markdown, 或其他特殊字符
|
||||||
- 不同阶段直接的过渡语句自然
|
- 不同阶段直接的过渡语句自然
|
||||||
- 你已经说过下面的开场白所以不需要重复说:“您好,这里是无锡交警,我将为您远程处理交通事故。请将人员撤离至路侧安全区域,开启危险报警双闪灯、放置三角警告牌、做好安全防护,谨防二次事故伤害。若您已经准备好了,请点击继续办理,如需人工服务,请说转人工。”
|
- 你已经说过下面的开场白,用户点击继续办理说明已经认可,所以不需要重复说:“您好,这里是无锡交警,我将为您远程处理交通事故。请将人员撤离至路侧安全区域,开启危险报警双闪灯、放置三角警告牌、做好安全防护,谨防二次事故伤害。若您已经准备好了,请点击继续办理,如需人工服务,请说转人工。”
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DEFAULT_TALKING_MODE = 'push_to_talk'
|
DEFAULT_TALKING_MODE = 'push_to_talk'
|
||||||
@@ -1030,6 +1030,7 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_
|
|||||||
logger.info("Using default DeepSeek backend")
|
logger.info("Using default DeepSeek backend")
|
||||||
llm = openai.LLM.with_deepseek(
|
llm = openai.LLM.with_deepseek(
|
||||||
model='deepseek-chat',
|
model='deepseek-chat',
|
||||||
|
temperature=0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
session = AgentSession(
|
session = AgentSession(
|
||||||
|
|||||||
@@ -715,7 +715,7 @@ export function PhoneSimulator({
|
|||||||
>
|
>
|
||||||
<PhoneIcon className="w-8 h-8" />
|
<PhoneIcon className="w-8 h-8" />
|
||||||
</div>
|
</div>
|
||||||
<span className="font-medium text-white">Call Agent</span>
|
<span className="font-medium text-white">呼叫智能体</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
@@ -725,7 +725,7 @@ export function PhoneSimulator({
|
|||||||
>
|
>
|
||||||
<VoiceIcon className="w-3 h-3" />
|
<VoiceIcon className="w-3 h-3" />
|
||||||
<span>
|
<span>
|
||||||
{currentVoiceId === "BV001_streaming" ? "Female Voice" : "Male Voice"}
|
{currentVoiceId === "BV001_streaming" ? "女性声音" : "男性声音"}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
{showVoiceMenu && (
|
{showVoiceMenu && (
|
||||||
@@ -745,7 +745,7 @@ export function PhoneSimulator({
|
|||||||
: "text-white"
|
: "text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span>Female Voice</span>
|
<span>女性声音</span>
|
||||||
{currentVoiceId === "BV001_streaming" && <CheckIcon />}
|
{currentVoiceId === "BV001_streaming" && <CheckIcon />}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@@ -760,7 +760,7 @@ export function PhoneSimulator({
|
|||||||
: "text-white"
|
: "text-white"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span>Male Voice</span>
|
<span>男性声音</span>
|
||||||
{currentVoiceId === "BV002_streaming" && (
|
{currentVoiceId === "BV002_streaming" && (
|
||||||
<CheckIcon />
|
<CheckIcon />
|
||||||
)}
|
)}
|
||||||
@@ -1198,6 +1198,20 @@ export function PhoneSimulator({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Fallback: Show End Call Button when in push-to-talk mode but no agent/audio */}
|
||||||
|
{phoneMode === "normal" &&
|
||||||
|
isPushToTalkMode &&
|
||||||
|
!voiceAssistant.agent && (
|
||||||
|
<div className="w-full flex items-center justify-center">
|
||||||
|
<button
|
||||||
|
className="p-4 rounded-full bg-red-500 text-white hover:bg-red-600 transition-colors"
|
||||||
|
onClick={handleDisconnect}
|
||||||
|
>
|
||||||
|
<PhoneOffIcon className="w-6 h-6" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -479,6 +479,7 @@ export default function Playground({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const instructionsContent = (
|
const instructionsContent = (
|
||||||
|
<>
|
||||||
<ConfigurationPanelItem title="Instructions">
|
<ConfigurationPanelItem title="Instructions">
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full bg-gray-950 text-white text-sm p-3 rounded-md border border-gray-800 focus:border-gray-600 focus:outline-none transition-colors resize-none disabled:opacity-50 disabled:cursor-not-allowed"
|
className="w-full bg-gray-950 text-white text-sm p-3 rounded-md border border-gray-800 focus:border-gray-600 focus:outline-none transition-colors resize-none disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
@@ -494,6 +495,18 @@ export default function Playground({
|
|||||||
disabled={roomState !== ConnectionState.Disconnected}
|
disabled={roomState !== ConnectionState.Disconnected}
|
||||||
/>
|
/>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
|
<ConfigurationPanelItem title="Color">
|
||||||
|
<ColorPicker
|
||||||
|
colors={themeColors}
|
||||||
|
selectedColor={config.settings.theme_color}
|
||||||
|
onSelect={(color) => {
|
||||||
|
const userSettings = { ...config.settings };
|
||||||
|
userSettings.theme_color = color;
|
||||||
|
setUserSettings(userSettings);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ConfigurationPanelItem>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRpcCall = useCallback(async () => {
|
const handleRpcCall = useCallback(async () => {
|
||||||
@@ -516,13 +529,13 @@ export default function Playground({
|
|||||||
const settingsTileContent = useMemo(() => {
|
const settingsTileContent = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full w-full items-start overflow-y-auto">
|
<div className="flex flex-col h-full w-full items-start overflow-y-auto">
|
||||||
{config.description && (
|
{/* {config.description && (
|
||||||
<ConfigurationPanelItem title="Description">
|
<ConfigurationPanelItem title="Description">
|
||||||
{config.description}
|
{config.description}
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
)}
|
)} */}
|
||||||
|
|
||||||
<ConfigurationPanelItem title="Room">
|
{/* <ConfigurationPanelItem title="Room">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<EditableNameValueRow
|
<EditableNameValueRow
|
||||||
name="Room name"
|
name="Room name"
|
||||||
@@ -556,9 +569,9 @@ export default function Playground({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem> */}
|
||||||
|
|
||||||
<ConfigurationPanelItem title="Agent">
|
{/* <ConfigurationPanelItem title="Agent">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<EditableNameValueRow
|
<EditableNameValueRow
|
||||||
name="Agent name"
|
name="Agent name"
|
||||||
@@ -621,9 +634,9 @@ export default function Playground({
|
|||||||
.
|
.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem> */}
|
||||||
|
|
||||||
<ConfigurationPanelItem title="User">
|
{/* <ConfigurationPanelItem title="User">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<EditableNameValueRow
|
<EditableNameValueRow
|
||||||
name="Name"
|
name="Name"
|
||||||
@@ -675,7 +688,7 @@ export default function Playground({
|
|||||||
connectionState={roomState}
|
connectionState={roomState}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem> */}
|
||||||
|
|
||||||
{roomState === ConnectionState.Connected &&
|
{roomState === ConnectionState.Connected &&
|
||||||
config.settings.inputs.screen && (
|
config.settings.inputs.screen && (
|
||||||
@@ -725,19 +738,6 @@ export default function Playground({
|
|||||||
<AudioInputTile trackRef={localMicTrack} />
|
<AudioInputTile trackRef={localMicTrack} />
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
)}
|
)}
|
||||||
<div className="w-full">
|
|
||||||
<ConfigurationPanelItem title="Color">
|
|
||||||
<ColorPicker
|
|
||||||
colors={themeColors}
|
|
||||||
selectedColor={config.settings.theme_color}
|
|
||||||
onSelect={(color) => {
|
|
||||||
const userSettings = { ...config.settings };
|
|
||||||
userSettings.theme_color = color;
|
|
||||||
setUserSettings(userSettings);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ConfigurationPanelItem>
|
|
||||||
</div>
|
|
||||||
{config.show_qr && (
|
{config.show_qr && (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<ConfigurationPanelItem title="QR Code">
|
<ConfigurationPanelItem title="QR Code">
|
||||||
@@ -748,7 +748,6 @@ export default function Playground({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}, [
|
}, [
|
||||||
config.description,
|
|
||||||
config.settings,
|
config.settings,
|
||||||
config.show_qr,
|
config.show_qr,
|
||||||
localParticipant,
|
localParticipant,
|
||||||
@@ -842,7 +841,7 @@ export default function Playground({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PlaygroundHeader
|
{/* <PlaygroundHeader
|
||||||
title={config.title}
|
title={config.title}
|
||||||
logo={logo}
|
logo={logo}
|
||||||
githubLink={config.github_link}
|
githubLink={config.github_link}
|
||||||
@@ -856,10 +855,10 @@ export default function Playground({
|
|||||||
handleDisconnect();
|
handleDisconnect();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/> */}
|
||||||
<div
|
<div
|
||||||
className={`flex gap-4 py-4 grow w-full selection:bg-${config.settings.theme_color}-900`}
|
className={`flex gap-4 py-4 grow w-full selection:bg-${config.settings.theme_color}-900`}
|
||||||
style={{ height: `calc(100% - ${headerHeight}px)` }}
|
style={{ height: `100%` }}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col grow basis-1/2 gap-4 h-full lg:hidden">
|
<div className="flex flex-col grow basis-1/2 gap-4 h-full lg:hidden">
|
||||||
<PlaygroundTabbedTile
|
<PlaygroundTabbedTile
|
||||||
@@ -926,14 +925,14 @@ export default function Playground({
|
|||||||
</PlaygroundTile>
|
</PlaygroundTile>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<PlaygroundTile
|
{/* <PlaygroundTile
|
||||||
padding={false}
|
padding={false}
|
||||||
backgroundColor="gray-950"
|
backgroundColor="gray-950"
|
||||||
className="h-full w-full basis-1/4 items-start overflow-y-auto hidden max-w-[480px] lg:flex"
|
className="h-full w-full basis-1/4 items-start overflow-y-auto hidden max-w-[480px] lg:flex"
|
||||||
childrenClassName="h-full grow items-start"
|
childrenClassName="h-full grow items-start"
|
||||||
>
|
>
|
||||||
{settingsTileContent}
|
{settingsTileContent}
|
||||||
</PlaygroundTile>
|
</PlaygroundTile> */}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -100,7 +100,18 @@ export const PlaygroundTabbedTile: React.FC<PlaygroundTabbedTileProps> = ({
|
|||||||
padding: `${contentPadding * 4}px`,
|
padding: `${contentPadding * 4}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{tabs[activeTab].content}
|
{tabs.map((tab, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
style={{
|
||||||
|
display: index === activeTab ? 'block' : 'none',
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{tab.content}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
Track,
|
Track,
|
||||||
TranscriptionSegment,
|
TranscriptionSegment,
|
||||||
} from "livekit-client";
|
} from "livekit-client";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, useRef } from "react";
|
||||||
|
|
||||||
export function TranscriptionTile({
|
export function TranscriptionTile({
|
||||||
agentAudioTrack,
|
agentAudioTrack,
|
||||||
@@ -30,39 +30,51 @@ export function TranscriptionTile({
|
|||||||
participant: localParticipant.localParticipant,
|
participant: localParticipant.localParticipant,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [transcripts, setTranscripts] = useState<Map<string, ChatMessageType>>(
|
|
||||||
new Map(),
|
|
||||||
);
|
|
||||||
const [messages, setMessages] = useState<ChatMessageType[]>([]);
|
const [messages, setMessages] = useState<ChatMessageType[]>([]);
|
||||||
const { chatMessages, send: sendChat } = useChat();
|
const { chatMessages, send: sendChat } = useChat();
|
||||||
|
const transcriptMapRef = useRef<Map<string, ChatMessageType>>(new Map());
|
||||||
|
|
||||||
// store transcripts
|
// Build messages from segments and chat - always rebuild from current state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const transcriptMap = transcriptMapRef.current;
|
||||||
|
|
||||||
|
// Process agent segments - update existing or add new
|
||||||
if (agentAudioTrack) {
|
if (agentAudioTrack) {
|
||||||
agentMessages.segments.forEach((s) =>
|
agentMessages.segments.forEach((s) => {
|
||||||
transcripts.set(
|
const existing = transcriptMap.get(s.id);
|
||||||
|
transcriptMap.set(
|
||||||
s.id,
|
s.id,
|
||||||
segmentToChatMessage(
|
segmentToChatMessage(
|
||||||
s,
|
s,
|
||||||
transcripts.get(s.id),
|
existing,
|
||||||
agentAudioTrack.participant,
|
agentAudioTrack.participant,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
localMessages.segments.forEach((s) =>
|
// Process local segments - update existing or add new
|
||||||
transcripts.set(
|
localMessages.segments.forEach((s) => {
|
||||||
|
const existing = transcriptMap.get(s.id);
|
||||||
|
transcriptMap.set(
|
||||||
s.id,
|
s.id,
|
||||||
segmentToChatMessage(
|
segmentToChatMessage(
|
||||||
s,
|
s,
|
||||||
transcripts.get(s.id),
|
existing,
|
||||||
localParticipant.localParticipant,
|
localParticipant.localParticipant,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const allMessages = Array.from(transcripts.values());
|
// Build all messages
|
||||||
|
const allMessages: ChatMessageType[] = [];
|
||||||
|
|
||||||
|
// Add all transcript messages
|
||||||
|
transcriptMap.forEach((msg) => {
|
||||||
|
allMessages.push(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add chat messages
|
||||||
for (const msg of chatMessages) {
|
for (const msg of chatMessages) {
|
||||||
const isAgent = agentAudioTrack
|
const isAgent = agentAudioTrack
|
||||||
? msg.from?.identity === agentAudioTrack.participant?.identity
|
? msg.from?.identity === agentAudioTrack.participant?.identity
|
||||||
@@ -79,6 +91,7 @@ export function TranscriptionTile({
|
|||||||
name = "Unknown";
|
name = "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allMessages.push({
|
allMessages.push({
|
||||||
name,
|
name,
|
||||||
message: msg.message,
|
message: msg.message,
|
||||||
@@ -86,10 +99,11 @@ export function TranscriptionTile({
|
|||||||
isSelf: isSelf,
|
isSelf: isSelf,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort by timestamp
|
||||||
allMessages.sort((a, b) => a.timestamp - b.timestamp);
|
allMessages.sort((a, b) => a.timestamp - b.timestamp);
|
||||||
setMessages(allMessages);
|
setMessages(allMessages);
|
||||||
}, [
|
}, [
|
||||||
transcripts,
|
|
||||||
chatMessages,
|
chatMessages,
|
||||||
localParticipant.localParticipant,
|
localParticipant.localParticipant,
|
||||||
agentAudioTrack?.participant,
|
agentAudioTrack?.participant,
|
||||||
|
|||||||
Reference in New Issue
Block a user