(
transport: BaseTransport,
transport_kind: Literal["browser", "esp32"],
handle_sigint: bool = False,
)
| 141 | |
| 142 | |
| 143 | async def run_bot_session( |
| 144 | transport: BaseTransport, |
| 145 | transport_kind: Literal["browser", "esp32"], |
| 146 | handle_sigint: bool = False, |
| 147 | ): |
| 148 | voice_route = CURRENT_VOICE_ROUTE |
| 149 | logger.info(f"Starting bot session for {transport_kind} via route={voice_route}") |
| 150 | |
| 151 | context = LLMContext() |
| 152 | input_processor = RealtimeInputControlProcessor(voice_route) |
| 153 | if voice_route == "gem_live": |
| 154 | route_processors, assistant_aggregator = build_gem_live_route(input_processor, context) |
| 155 | elif voice_route == "grok": |
| 156 | route_processors, assistant_aggregator = build_grok_route(input_processor, context) |
| 157 | else: |
| 158 | route_processors, assistant_aggregator = build_voice_pipeline(input_processor, context) |
| 159 | |
| 160 | processors = [transport.input(), *route_processors] |
| 161 | |
| 162 | if transport_kind in {"esp32", "browser"}: |
| 163 | processors.append(RealtimeOutputControlProcessor()) |
| 164 | processors.append(transport.output()) |
| 165 | processors.append(assistant_aggregator) |
| 166 | |
| 167 | pipeline = Pipeline(processors) |
| 168 | |
| 169 | task = PipelineTask( |
| 170 | pipeline, |
| 171 | params=PipelineParams( |
| 172 | enable_metrics=True, |
| 173 | enable_usage_metrics=True, |
| 174 | audio_in_sample_rate=AUDIO_IN_SAMPLE_RATE, |
| 175 | audio_out_sample_rate=AUDIO_OUT_SAMPLE_RATE, |
| 176 | ), |
| 177 | ) |
| 178 | |
| 179 | @transport.event_handler("on_client_connected") |
| 180 | async def on_client_connected(transport, client): |
| 181 | logger.info(f"{transport_kind} client connected") |
| 182 | if voice_route in {"gem_live", "grok"}: |
| 183 | context.add_message( |
| 184 | { |
| 185 | "role": "user", |
| 186 | "content": "Say hello and briefly introduce yourself.", |
| 187 | } |
| 188 | ) |
| 189 | await task.queue_frames( |
| 190 | [ |
| 191 | LLMContextFrame(context=context) |
| 192 | ] |
| 193 | ) |
| 194 | else: |
| 195 | context.add_message( |
| 196 | { |
| 197 | "role": "developer", |
| 198 | "content": "Say hello and briefly introduce yourself.", |
| 199 | } |
| 200 | ) |
no test coverage detected