From 05c545a2bcb297f642daa70c57316a59530875a5 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Sun, 14 Apr 2024 19:32:32 -0700 Subject: [PATCH] Proper URL encoding --- hume/_voice/mixins/chat_mixin.py | 37 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/hume/_voice/mixins/chat_mixin.py b/hume/_voice/mixins/chat_mixin.py index 8a87d6f4..13d32674 100644 --- a/hume/_voice/mixins/chat_mixin.py +++ b/hume/_voice/mixins/chat_mixin.py @@ -1,5 +1,5 @@ -import json import logging +import urllib.parse from contextlib import asynccontextmanager from typing import AsyncIterator, ClassVar, Optional @@ -39,23 +39,24 @@ async def connect( """Connect to the voice API.""" uri_base = self._build_endpoint("evi", "chat", Protocol.WS) - # TODO: Use proper query param formatting - uri = ( - f"{uri_base}" - f"?speed_ratio={speed_ratio}" - f"&postprocess={json.dumps(self.DEFAULT_POSTPROCESS)}" - f"&cut_ms={self.DEFAULT_CUT_MS}" - f"&encoding={self.DEFAULT_ENCODING_NAME}" - f"&channels={VoiceSocket.N_CHANNELS}" - f"&sample_rate={VoiceSocket.SAMPLE_RATE}" - f"&language_model_type={self.DEFAULT_LANGUAGE_MODEL_TYPE}" - f"&language_model_temperature={self.DEFAULT_LANGUAGE_MODEL_TEMPERATURE}" - f"&generate_short_response={json.dumps(self.DEFAULT_GENERATE_SHORT_RESPONSE)}" - f"&no_binary={json.dumps(self.DEFAULT_NO_BINARY)}" - f"&send_gap_ms={self.DEFAULT_SEND_GAP_MS}" - f"&sensitive_interruptibility={json.dumps(self.DEFAULT_SENSITIVE_INTERRUPTIBILITY)}" - f"&tts={tts_type}" - ) + params = { + "speed_ratio": speed_ratio, + "postprocess": self.DEFAULT_POSTPROCESS, + "cut_ms": self.DEFAULT_CUT_MS, + "encoding": self.DEFAULT_ENCODING_NAME, + "channels": VoiceSocket.N_CHANNELS, + "sample_rate": VoiceSocket.SAMPLE_RATE, + "language_model_type": self.DEFAULT_LANGUAGE_MODEL_TYPE, + "language_model_temperature": self.DEFAULT_LANGUAGE_MODEL_TEMPERATURE, + "generate_short_response": self.DEFAULT_GENERATE_SHORT_RESPONSE, + "no_binary": self.DEFAULT_NO_BINARY, + "send_gap_ms": self.DEFAULT_SEND_GAP_MS, + "sensitive_interruptibility": self.DEFAULT_SENSITIVE_INTERRUPTIBILITY, + "tts": tts_type, + } + + encoded_params = urllib.parse.urlencode(params) + uri = f"{uri_base}?{encoded_params}" if config_id is not None: uri += f"&config_id={config_id}"