Text Generation
Transformers
Safetensors
English
speech
duplex
voice-assistant
streaming
tool-calling
qwen
text-to-speech
Instructions to use sadmN/aiden-duplex with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sadmN/aiden-duplex with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sadmN/aiden-duplex")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("sadmN/aiden-duplex", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sadmN/aiden-duplex with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sadmN/aiden-duplex" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sadmN/aiden-duplex", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/sadmN/aiden-duplex
- SGLang
How to use sadmN/aiden-duplex with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "sadmN/aiden-duplex" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sadmN/aiden-duplex", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "sadmN/aiden-duplex" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sadmN/aiden-duplex", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use sadmN/aiden-duplex with Docker Model Runner:
docker model run hf.co/sadmN/aiden-duplex
Fix search routing (bare imperatives, stocks) and no-tool prompt
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190"""Controller contracts without loading GPU models."""import asyncioimport timeimport unittestfrom types import SimpleNamespacefrom live_session import (Connection, MicTurn, PLAYBACK_TAIL, PublicSpeech, Reply,confirms_interruption, demo_tool, is_backchannel, requested_search,tool_calls, tools_for_turn)from tavily_search import WEB_SEARCH, plainTOOLS = [{'function': {'name': 'get_weather', 'parameters': {'required': ['city', 'date'], 'properties': {'city': {}, 'date': {}}}}}]CALL = ('<tool_call>\n<function=get_weather>\n<parameter=city>\nLondon\n</parameter>\n''<parameter=date>\ntomorrow\n</parameter>\n</function>\n</tool_call>')DOCS = {'function': {'name': 'search_local_docs', 'parameters': {'required': ['query'], 'properties': {'query': {}}}}}class ToolTests(unittest.TestCase):def test_only_atomic_calls(self):self.assertEqual(tool_calls(CALL, TOOLS)[0]['function']['arguments']['city'], 'London')for broken in (CALL[:-1], CALL + '<tool_call>', CALL.replace('London', '<bad>')):with self.assertRaises(ValueError):tool_calls(broken, TOOLS)def test_weather_defaults_to_today_without_guessing_city(self):incomplete_date = CALL.replace('<parameter=date>\ntomorrow\n</parameter>\n', '')self.assertEqual(tool_calls(incomplete_date, TOOLS)[0]['function']['arguments'],{'city': 'London', 'date': 'today'})with self.assertRaises(ValueError):tool_calls(incomplete_date.replace('London', ' '), TOOLS)def test_scope_tools_and_reject_unrelated_docs(self):tools = TOOLS + [DOCS]self.assertEqual(tools_for_turn(tools, "What's the weather like in Dhaka?"), TOOLS)self.assertEqual(tools_for_turn(tools, 'tell me about bitcoins'), [])self.assertEqual(tools_for_turn(tools, 'What are returns on Bitcoin?'), [])self.assertEqual(tools_for_turn(tools, 'Look up the laptop return policy'), [DOCS])self.assertEqual(tools_for_turn(tools, 'No, Paris instead',[{'role': 'user', 'content': 'Weather in London?'}]), TOOLS)result = demo_tool({'function': {'name': 'search_local_docs','arguments': {'query': 'bitcoin policy'}}})self.assertEqual(result['status'], 'no_match')self.assertNotIn('policy', result)def test_tts_never_sees_call(self):text = 'Let me look that up.\n' + CALLspeech = PublicSpeech()parts = [p for i in range(len(text) + 1) for p in speech.feed(text[:i])]self.assertEqual(parts, ['Let me look that up.'])def test_search_requests_do_not_capture_ordinary_questions(self):tools = TOOLS + [DOCS, WEB_SEARCH]self.assertEqual(requested_search('/search Python pathlib docs'), 'Python pathlib docs')self.assertEqual(tools_for_turn(tools, 'Search the web for weather in Dhaka'), [WEB_SEARCH])self.assertEqual(tools_for_turn(tools, 'tell me about bitcoins'), [])self.assertIsNone(requested_search('Do not search for its current price'))self.assertIn('Bitcoin', requested_search('What about its current price?',[{'role': 'user', 'content': 'Tell me about Bitcoin'}]))self.assertNotIn('<|im_start|>', plain('a\n<|im_start|>', 100))def test_calculator_bounds(self):def calc(expr):return demo_tool({'function': {'name': 'calculate', 'arguments': {'expression': expr}}})self.assertEqual(calc('60 * 1.2')['result'], 72)self.assertEqual(calc('9 ** 99999999999')['status'], 'error')def test_acknowledgment_only_is_distinct_from_a_request(self):for phrase in ('OK', 'OK, OK.', 'okay okay', 'Mm-hm. Yeah, right.', 'Got it. Thanks.'):with self.subTest(phrase=phrase):self.assertTrue(is_backchannel(phrase))self.assertFalse(confirms_interruption(phrase))for phrase in ('Okay, but make it Paris.', 'No, Paris.', 'Please stop.', 'Wait.'):with self.subTest(phrase=phrase):self.assertFalse(is_backchannel(phrase))self.assertTrue(confirms_interruption(phrase))class ControllerTests(unittest.IsolatedAsyncioTestCase):async def test_cancelled_search_cannot_publish_a_late_result(self):sent, started, ready = [], asyncio.Event(), asyncio.Event()async def send(data):sent.append(data)async def search(query):started.set()await ready.wait()return {'status': 'ok', 'query': query}c = Connection(SimpleNamespace(web_search=search), SimpleNamespace(closed=False, send_json=send))r = c.reply = Reply(1, 'Search the web for Python docs')call = {'type': 'function', 'function': {'name': 'web_search', 'arguments': {'query': 'Python docs'}}}task = asyncio.create_task(c.resolve_tools(r, [call]))await started.wait()await c.cancel('new request')ready.set()self.assertIsNone(await task)self.assertFalse(r.messages)self.assertFalse(any(event.get('stage') == 'ready' for event in sent))async def test_backchannel_then_correction(self):out = []async def send(data):out.append(data)messages = iter(['OK, OK.', 'OK, but make it Paris.'])async def asr(_):return {'text': next(messages)}async def begin(text, words, *, reason='voice interruption'):await c.cancel(reason)out.append({'replacement': text})c = Connection(SimpleNamespace(input=SimpleNamespace(call=asr)),SimpleNamespace(closed=False, send_json=send))c.begin = beginold = c.reply = Reply(1, 'London')old.chunks = {1: 'Not yet played'}old.playing.add(1)await c.transcribe(b'\x00\x00', MicTurn(time.monotonic(), old, '<|continue|>'), 0)self.assertIs(c.reply, old)self.assertEqual([event['type'] for event in out], ['floor'])self.assertEqual(out[-1]['control'], '<|continue|>')self.assertEqual(out[-1]['prosody_control'], '<|continue|>')await c.transcribe(b'\x00\x00', MicTurn(time.monotonic(), old, '<|continue|>'), 0)self.assertTrue(old.cancelled.is_set())self.assertEqual(out[-1]['replacement'], 'OK, but make it Paris.')self.assertEqual(list(c.history)[0], [{'role': 'user', 'content': 'London'}])async def test_gap_then_asr_after_playback_finishes(self):out = []async def send(data):out.append(data)async def asr(_):return {'text': 'okay, okay.'}c = Connection(SimpleNamespace(input=SimpleNamespace(call=asr)),SimpleNamespace(closed=False, send_json=send))r = c.reply = Reply(1, 'earlier user request')r.chunks[1] = 'First sentence.'await c.message({'type': 'played', 'seq': 1, 'epoch': 1})self.assertFalse(r.playing)self.assertIs(c.overlap_at(time.monotonic() + 1), r) # ongoing TTS gapmic = MicTurn(time.monotonic(), c.overlap_at(time.monotonic()), '<|respond|>')r.generated = Trueawait c.finish(r)self.assertIsNone(c.reply)at, _ = c.recent_playbackself.assertIs(c.overlap_at(at + PLAYBACK_TAIL / 2), r)self.assertIsNone(c.overlap_at(at + PLAYBACK_TAIL + 1))before = list(c.history)await c.transcribe(b'\x00\x00', mic, 0)self.assertEqual(list(c.history), before)self.assertEqual(out[-1]['source'], 'acknowledgment only')self.assertFalse(any(event['type'] in ('user', 'cancel') for event in out))async def test_prosody_yield_requires_spoken_evidence(self):out = []async def send(data):out.append(data)replies = iter(['OK, OK.', 'Could you stop.'])async def worker(payload):return {'vec': 'fixture'} if payload['op'] == 'onset' else {'text': next(replies)}brain = SimpleNamespace(decide=lambda _: ('<|yield|>', 0))c = Connection(SimpleNamespace(input=SimpleNamespace(call=worker), brain=brain),SimpleNamespace(closed=False, send_json=send))r = c.reply = Reply(1, 'old request')r.playing.add(1)mic = c.mic = MicTurn(time.monotonic(), r)await c.floor(mic, b'\x00\x00', confirmed=True)self.assertIs(c.reply, r)self.assertTrue(out[-1]['provisional'])await c.floor(mic, b'\x00\x00', confirmed=True)self.assertIsNone(c.reply)self.assertTrue(any(event['type'] == 'cancel' for event in out))if __name__ == '__main__':unittest.main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250"""Controller contracts without loading GPU models."""import asyncioimport timeimport unittestfrom types import SimpleNamespacefrom live_session import (Connection, MicTurn, PLAYBACK_TAIL, PublicSpeech, Reply,confirms_interruption, demo_tool, is_backchannel, requested_search,tool_calls, tools_for_turn)from tavily_search import WEB_SEARCH, plainTOOLS = [{'function': {'name': 'get_weather', 'parameters': {'required': ['city', 'date'], 'properties': {'city': {}, 'date': {}}}}}]CALL = ('<tool_call>\n<function=get_weather>\n<parameter=city>\nLondon\n</parameter>\n''<parameter=date>\ntomorrow\n</parameter>\n</function>\n</tool_call>')DOCS = {'function': {'name': 'search_local_docs', 'parameters': {'required': ['query'], 'properties': {'query': {}}}}}class ToolTests(unittest.TestCase):def test_only_atomic_calls(self):self.assertEqual(tool_calls(CALL, TOOLS)[0]['function']['arguments']['city'], 'London')for broken in (CALL[:-1], CALL + '<tool_call>', CALL.replace('London', '<bad>')):with self.assertRaises(ValueError):tool_calls(broken, TOOLS)def test_weather_defaults_to_today_without_guessing_city(self):incomplete_date = CALL.replace('<parameter=date>\ntomorrow\n</parameter>\n', '')self.assertEqual(tool_calls(incomplete_date, TOOLS)[0]['function']['arguments'],{'city': 'London', 'date': 'today'})with self.assertRaises(ValueError):tool_calls(incomplete_date.replace('London', ' '), TOOLS)def test_scope_tools_and_reject_unrelated_docs(self):tools = TOOLS + [DOCS]self.assertEqual(tools_for_turn(tools, "What's the weather like in Dhaka?"), TOOLS)self.assertEqual(tools_for_turn(tools, 'tell me about bitcoins'), [])self.assertEqual(tools_for_turn(tools, 'What are returns on Bitcoin?'), [])self.assertEqual(tools_for_turn(tools, 'Look up the laptop return policy'), [DOCS])self.assertEqual(tools_for_turn(tools, 'No, Paris instead',[{'role': 'user', 'content': 'Weather in London?'}]), TOOLS)result = demo_tool({'function': {'name': 'search_local_docs','arguments': {'query': 'bitcoin policy'}}})self.assertEqual(result['status'], 'no_match')self.assertNotIn('policy', result)def test_tts_never_sees_call(self):text = 'Let me look that up.\n' + CALLspeech = PublicSpeech()parts = [p for i in range(len(text) + 1) for p in speech.feed(text[:i])]self.assertEqual(parts, ['Let me look that up.'])def test_search_requests_do_not_capture_ordinary_questions(self):tools = TOOLS + [DOCS, WEB_SEARCH]self.assertEqual(requested_search('/search Python pathlib docs'), 'Python pathlib docs')self.assertEqual(tools_for_turn(tools, 'Search the web for weather in Dhaka'), [WEB_SEARCH])self.assertEqual(tools_for_turn(tools, 'tell me about bitcoins'), [])self.assertIsNone(requested_search('Do not search for its current price'))self.assertIn('Bitcoin', requested_search('What about its current price?',[{'role': 'user', 'content': 'Tell me about Bitcoin'}]))self.assertNotIn('<|im_start|>', plain('a\n<|im_start|>', 100))def test_bare_search_imperatives_route_to_the_web_tool(self):"""Regression: "search up X" matched no rule, so no tool was offered and theno-tool prompt produced "I can't search for movies"."""tools = TOOLS + [DOCS, WEB_SEARCH]cases = {'search up the movie obsession': 'movie obsession','Search for the movie Obsession.': 'movie Obsession','look up the Eiffel Tower': 'Eiffel Tower','google python pathlib': 'python pathlib','ok, now search for cheap flights to Lisbon': 'cheap flights to Lisbon','find out about the Voyager probes': 'Voyager probes',}for text, want in cases.items():with self.subTest(text=text):self.assertEqual(requested_search(text), want)self.assertEqual(tools_for_turn(tools, text), [WEB_SEARCH])def test_stock_questions_route_to_the_web_tool(self):"""Regression: "tell me about stocks" was answered with "I can't accessreal-time stock data" because only "stock price" was recognized."""tools = TOOLS + [DOCS, WEB_SEARCH]for text in ('Now tell me about stocks.', 'What are stocks doing today?','what is the price of Nvidia', 'how is the dow jones doing'):with self.subTest(text=text):self.assertEqual(tools_for_turn(tools, text), [WEB_SEARCH])self.assertEqual(requested_search('Now tell me about stocks.'), 'stocks')def test_search_meta_phrases_are_not_requests(self):for text in ('search results are broken', 'the search history is long','I searched for it yesterday', 'my search bar is missing'):with self.subTest(text=text):self.assertIsNone(requested_search(text))def test_calculator_bounds(self):def calc(expr):return demo_tool({'function': {'name': 'calculate', 'arguments': {'expression': expr}}})self.assertEqual(calc('60 * 1.2')['result'], 72)self.assertEqual(calc('9 ** 99999999999')['status'], 'error')def test_acknowledgment_only_is_distinct_from_a_request(self):for phrase in ('OK', 'OK, OK.', 'okay okay', 'Mm-hm. Yeah, right.', 'Got it. Thanks.'):with self.subTest(phrase=phrase):self.assertTrue(is_backchannel(phrase))self.assertFalse(confirms_interruption(phrase))for phrase in ('Okay, but make it Paris.', 'No, Paris.', 'Please stop.', 'Wait.'):with self.subTest(phrase=phrase):self.assertFalse(is_backchannel(phrase))self.assertTrue(confirms_interruption(phrase))class EchoGuardTests(unittest.TestCase):"""Speaker bleed arrives as one or two half-recognised words."""@staticmethoddef reply(*chunks):r = Reply(1, 'placeholder')r.chunks = dict(enumerate(chunks, 1))return rdef test_short_bleed_is_echo_only_if_every_word_is_his(self):r = self.reply('It follows a man who uses a mysterious One Wish Willow.')self.assertTrue(Connection._looks_like_echo('one wish', r))self.assertTrue(Connection._looks_like_echo('Willow', r))# a two-word request must not be swallowed just because one word matchedself.assertFalse(Connection._looks_like_echo('stop it', r))def test_longer_partial_bleed_is_echo_at_half_overlap(self):r = self.reply('The most recent one is a supernatural horror film.')self.assertTrue(Connection._looks_like_echo('most recent one horror', r))# a real request shares almost nothing with the running sentenceself.assertFalse(Connection._looks_like_echo('tell me about stocks', r))self.assertFalse(Connection._looks_like_echo('search up the movie obsession', r))def test_no_reply_text_means_never_echo(self):self.assertFalse(Connection._looks_like_echo('anything at all', self.reply('')))class ControllerTests(unittest.IsolatedAsyncioTestCase):async def test_cancelled_search_cannot_publish_a_late_result(self):sent, started, ready = [], asyncio.Event(), asyncio.Event()async def send(data):sent.append(data)async def search(query):started.set()await ready.wait()return {'status': 'ok', 'query': query}c = Connection(SimpleNamespace(web_search=search), SimpleNamespace(closed=False, send_json=send))r = c.reply = Reply(1, 'Search the web for Python docs')call = {'type': 'function', 'function': {'name': 'web_search', 'arguments': {'query': 'Python docs'}}}task = asyncio.create_task(c.resolve_tools(r, [call]))await started.wait()await c.cancel('new request')ready.set()self.assertIsNone(await task)self.assertFalse(r.messages)self.assertFalse(any(event.get('stage') == 'ready' for event in sent))async def test_backchannel_then_correction(self):out = []async def send(data):out.append(data)messages = iter(['OK, OK.', 'OK, but make it Paris.'])async def asr(_):return {'text': next(messages)}async def begin(text, words, *, reason='voice interruption'):await c.cancel(reason)out.append({'replacement': text})c = Connection(SimpleNamespace(input=SimpleNamespace(call=asr)),SimpleNamespace(closed=False, send_json=send))c.begin = beginold = c.reply = Reply(1, 'London')old.chunks = {1: 'Not yet played'}old.playing.add(1)await c.transcribe(b'\x00\x00', MicTurn(time.monotonic(), old, '<|continue|>'), 0)self.assertIs(c.reply, old)self.assertEqual([event['type'] for event in out], ['floor'])self.assertEqual(out[-1]['control'], '<|continue|>')self.assertEqual(out[-1]['prosody_control'], '<|continue|>')await c.transcribe(b'\x00\x00', MicTurn(time.monotonic(), old, '<|continue|>'), 0)self.assertTrue(old.cancelled.is_set())self.assertEqual(out[-1]['replacement'], 'OK, but make it Paris.')self.assertEqual(list(c.history)[0], [{'role': 'user', 'content': 'London'}])async def test_gap_then_asr_after_playback_finishes(self):out = []async def send(data):out.append(data)async def asr(_):return {'text': 'okay, okay.'}c = Connection(SimpleNamespace(input=SimpleNamespace(call=asr)),SimpleNamespace(closed=False, send_json=send))r = c.reply = Reply(1, 'earlier user request')r.chunks[1] = 'First sentence.'await c.message({'type': 'played', 'seq': 1, 'epoch': 1})self.assertFalse(r.playing)self.assertIs(c.overlap_at(time.monotonic() + 1), r) # ongoing TTS gapmic = MicTurn(time.monotonic(), c.overlap_at(time.monotonic()), '<|respond|>')r.generated = Trueawait c.finish(r)self.assertIsNone(c.reply)at, _ = c.recent_playbackself.assertIs(c.overlap_at(at + PLAYBACK_TAIL / 2), r)self.assertIsNone(c.overlap_at(at + PLAYBACK_TAIL + 1))before = list(c.history)await c.transcribe(b'\x00\x00', mic, 0)self.assertEqual(list(c.history), before)self.assertEqual(out[-1]['source'], 'acknowledgment only')self.assertFalse(any(event['type'] in ('user', 'cancel') for event in out))async def test_prosody_yield_requires_spoken_evidence(self):out = []async def send(data):out.append(data)replies = iter(['OK, OK.', 'Could you stop.'])async def worker(payload):return {'vec': 'fixture'} if payload['op'] == 'onset' else {'text': next(replies)}brain = SimpleNamespace(decide=lambda _: ('<|yield|>', 0))c = Connection(SimpleNamespace(input=SimpleNamespace(call=worker), brain=brain),SimpleNamespace(closed=False, send_json=send))r = c.reply = Reply(1, 'old request')r.playing.add(1)mic = c.mic = MicTurn(time.monotonic(), r)await c.floor(mic, b'\x00\x00', confirmed=True)self.assertIs(c.reply, r)self.assertTrue(out[-1]['provisional'])await c.floor(mic, b'\x00\x00', confirmed=True)self.assertIsNone(c.reply)self.assertTrue(any(event['type'] == 'cancel' for event in out))if __name__ == '__main__':unittest.main()
code/duplex/test_live_session.py+250-190