return random phone number and id card number
This commit is contained in:
parent
e09e4b6930
commit
f2fcbe485f
@ -4,6 +4,7 @@ import base64
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import re
|
||||
from dataclasses import asdict, dataclass
|
||||
@ -104,6 +105,8 @@ DEFAULT_INSTRUCTIONS = """# 角色
|
||||
- 你已经说过下面的开场白所以不需要重复说:“您好,这里是无锡交警,我将为您远程处理交通事故。请将人员撤离至路侧安全区域,开启危险报警双闪灯、放置三角警告牌、做好安全防护,谨防二次事故伤害。若您已经准备好了,请点击继续办理,如需人工服务,请说转人工。”
|
||||
"""
|
||||
|
||||
DEFAULT_TALKING_MODE = 'push_to_talk'
|
||||
|
||||
# ## 黄金对话路径示例 (GOLDEN_CONVERSATION_PATH)
|
||||
|
||||
# ```
|
||||
@ -606,11 +609,15 @@ class MyAgent(Agent):
|
||||
f"│ plate: \"{normalized_plate}\"\n"
|
||||
"└───────────────"
|
||||
)
|
||||
# Dummy fixed response (placeholder backend)
|
||||
# Generate random mobile number (11 digits: 1[3-9] + 9 random digits)
|
||||
mobile_prefix = random.choice(['13', '14', '15', '16', '17', '18', '19'])
|
||||
mobile_suffix = ''.join([str(random.randint(0, 9)) for _ in range(9)])
|
||||
random_mobile = f"{mobile_prefix}{mobile_suffix}"
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"plate": normalized_plate,
|
||||
"mobile": "13800001234",
|
||||
"mobile": random_mobile,
|
||||
}
|
||||
|
||||
@function_tool()
|
||||
@ -631,11 +638,24 @@ class MyAgent(Agent):
|
||||
f"│ plate: \"{normalized_plate}\"\n"
|
||||
"└───────────────"
|
||||
)
|
||||
# Dummy fixed response (placeholder backend)
|
||||
# Generate random ID card number (18 digits: 6-digit area code + 8-digit birth date + 3-digit sequence + 1 check digit)
|
||||
# Area code: random 6 digits (typically 110000-659999 for Chinese ID cards)
|
||||
area_code = random.randint(110000, 659999)
|
||||
# Birth date: random date between 1950-01-01 and 2000-12-31
|
||||
year = random.randint(1950, 2000)
|
||||
month = random.randint(1, 12)
|
||||
day = random.randint(1, 28) # Use 28 to avoid month-specific day issues
|
||||
birth_date = f"{year:04d}{month:02d}{day:02d}"
|
||||
# Sequence number: 3 random digits
|
||||
sequence = random.randint(100, 999)
|
||||
# Check digit: random digit or X (10% chance of X)
|
||||
check_digit = 'X' if random.random() < 0.1 else str(random.randint(0, 9))
|
||||
random_id_card = f"{area_code}{birth_date}{sequence}{check_digit}"
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"plate": normalized_plate,
|
||||
"id_card": "320101198001011234",
|
||||
"id_card": random_id_card,
|
||||
}
|
||||
|
||||
@function_tool()
|
||||
@ -749,7 +769,7 @@ class MyAgent(Agent):
|
||||
raise ToolError(f"Unable to hang up call: {str(e)}")
|
||||
|
||||
@function_tool()
|
||||
async def ask_important_question(self, context: RunContext, message: str, options: Optional[List[str]] = None):
|
||||
async def ask_important_question(self, context: RunContext, message: str, options: Optional[List[str]] | str = None):
|
||||
"""询问关键问题并等待用户选择选项,返回用户的选择结果。
|
||||
|
||||
参数:
|
||||
@ -759,7 +779,12 @@ class MyAgent(Agent):
|
||||
返回:
|
||||
str: 用户选择的文本内容。
|
||||
"""
|
||||
await self._send_chat_message(f"🔨 Call: ask_important_question\n • message: \"{message}\"\n • options: {options}")
|
||||
await self._send_chat_message(
|
||||
"┌─🔨 Call: ask_important_question\n"
|
||||
f"│ message: \"{message}\"\n"
|
||||
f"│ options: {options}\n"
|
||||
"└───────────────"
|
||||
)
|
||||
try:
|
||||
room = get_job_context().room
|
||||
participant_identity = next(iter(room.remote_participants))
|
||||
@ -805,7 +830,11 @@ class MyAgent(Agent):
|
||||
user_selection = response_data.get("selection", "确认")
|
||||
logger.info(f"User selected: {user_selection}")
|
||||
|
||||
await self._send_chat_message(f"✅ Result: ask_important_question\n • selection: \"{user_selection}\"")
|
||||
await self._send_chat_message(
|
||||
"┌─✅ Result: ask_important_question\n"
|
||||
f"│ selection: \"{user_selection}\"\n"
|
||||
"└───────────────"
|
||||
)
|
||||
return f"用户选择了: {user_selection}"
|
||||
except json.JSONDecodeError:
|
||||
logger.error(f"Failed to parse response: {response}")
|
||||
@ -1015,10 +1044,11 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_
|
||||
)
|
||||
|
||||
# disable input audio at the start
|
||||
_talking_mode = DEFAULT_TALKING_MODE
|
||||
if _talking_mode == "push_to_talk":
|
||||
session.input.set_audio_enabled(False)
|
||||
|
||||
# Track current audio state for mode switching
|
||||
_audio_enabled_state = False
|
||||
else:
|
||||
session.input.set_audio_enabled(True)
|
||||
|
||||
@ctx.room.local_participant.register_rpc_method("start_turn")
|
||||
async def start_turn(data: rtc.RpcInvocationData):
|
||||
@ -1058,13 +1088,13 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_
|
||||
|
||||
@ctx.room.local_participant.register_rpc_method("switch_ptt_and_rt")
|
||||
async def switch_ptt_and_rt(data: rtc.RpcInvocationData):
|
||||
nonlocal _audio_enabled_state
|
||||
# Toggle audio input state
|
||||
_audio_enabled_state = not _audio_enabled_state
|
||||
session.input.set_audio_enabled(_audio_enabled_state)
|
||||
mode = "push-to-talk" if not _audio_enabled_state else "realtime"
|
||||
logger.info(f"Switched to {mode} mode (audio enabled: {_audio_enabled_state})")
|
||||
return json.dumps({"success": True, "mode": mode, "audio_enabled": _audio_enabled_state})
|
||||
nonlocal _talking_mode
|
||||
_talking_mode = "push_to_talk" if _talking_mode == "realtime" else "realtime"
|
||||
if _talking_mode == "push_to_talk":
|
||||
session.input.set_audio_enabled(False)
|
||||
else:
|
||||
session.input.set_audio_enabled(True)
|
||||
return json.dumps({"success": True, "mode": _talking_mode})
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
@ -1063,9 +1063,10 @@ export function PhoneSimulator({
|
||||
)}
|
||||
|
||||
{/* Push-to-Talk Mode Layout */}
|
||||
{isPushToTalkMode && phoneMode !== "important_message" && phoneMode !== "hand_off" && voiceAssistant.agent && (
|
||||
{isPushToTalkMode && phoneMode !== "hand_off" && voiceAssistant.agent && (
|
||||
<div className="w-full flex items-center justify-center gap-8">
|
||||
{/* Camera Switch Button - Left */}
|
||||
{/* Camera Switch Button - Left (hidden in important_message mode) */}
|
||||
{phoneMode !== "important_message" && (
|
||||
<div className="relative">
|
||||
<button
|
||||
className="p-4 rounded-full bg-gray-800/50 text-white hover:bg-gray-800/70 transition-colors"
|
||||
@ -1094,17 +1095,20 @@ export function PhoneSimulator({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Large Push-to-Talk Button - Center */}
|
||||
{/* Large Push-to-Talk Button - Center (hidden in important_message mode) */}
|
||||
{phoneMode !== "important_message" && (
|
||||
<button
|
||||
ref={pushToTalkButtonRef}
|
||||
className={`w-24 h-24 rounded-full backdrop-blur-md transition-all flex flex-col items-center justify-center gap-2 ${
|
||||
className={`w-24 h-24 rounded-full backdrop-blur-md transition-all flex flex-col items-center justify-center gap-2 aspect-square ${
|
||||
interruptRejected
|
||||
? "bg-red-500/70 text-white"
|
||||
: isPushToTalkActive
|
||||
? "bg-green-500 text-white scale-110 shadow-lg shadow-green-500/50"
|
||||
: "bg-blue-500/70 text-white hover:bg-blue-500/90"
|
||||
}`}
|
||||
style={{ borderRadius: '50%' }}
|
||||
onMouseDown={handlePushToTalkMouseDown}
|
||||
onMouseUp={handlePushToTalkMouseUp}
|
||||
onTouchStart={handlePushToTalkTouchStart}
|
||||
@ -1116,8 +1120,9 @@ export function PhoneSimulator({
|
||||
{interruptRejected ? "不允许打断" : "按住说话"}
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* End Call Button - Right */}
|
||||
{/* End Call Button - Right (always shown in PTT mode) */}
|
||||
<button
|
||||
className="p-4 rounded-full bg-red-500 text-white hover:bg-red-600 transition-colors"
|
||||
onClick={handleDisconnect}
|
||||
@ -1156,6 +1161,18 @@ export function PhoneSimulator({
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Hand Off Mode - Show only End Call Button */}
|
||||
{phoneMode === "hand_off" && (
|
||||
<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>
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user