From abd92fa0651ff3ecb86f3389a3f62c51209f4ea1 Mon Sep 17 00:00:00 2001 From: dalmeow Date: Thu, 11 Jan 2024 18:52:22 +0530 Subject: [PATCH 1/2] adding ama --- neuralspace/constants.py | 10 +++++++--- neuralspace/env.py | 1 + neuralspace/voice_ai.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/neuralspace/constants.py b/neuralspace/constants.py index 7666bbc..453bcfd 100644 --- a/neuralspace/constants.py +++ b/neuralspace/constants.py @@ -10,7 +10,7 @@ if env.BASE_URL is not None: BASE_URL = env.BASE_URL -JOBS_URL = 'api/v1/jobs' +JOBS_URL = 'api/v2/jobs' if env.JOBS_URL is not None: JOBS_URL = env.JOBS_URL @@ -18,14 +18,17 @@ if env.STREAM_URL is not None: STREAM_URL = env.STREAM_URL -LANGS_URL = 'api/v1/languages' +LANGS_URL = 'api/v2/languages' if env.LANGS_URL is not None: LANGS_URL = env.LANGS_URL -TOKEN_URL = 'api/v1/token' +TOKEN_URL = 'api/v2/token' if env.TOKEN_URL is not None: TOKEN_URL = env.TOKEN_URL +AMA_URL = 'api/v2/prompts' +if env.AMA_URL is not None: + AMA_URL = env.AMA_URL # full url formation @@ -33,6 +36,7 @@ FULL_STREAM_URL = f'{BASE_URL.replace("https://", "wss://").rstrip("/")}/{STREAM_URL.strip("/")}' FULL_LANGS_URL = f'{BASE_URL.rstrip("/")}/{LANGS_URL.strip("/")}' FULL_TOKEN_URL = f'{BASE_URL.rstrip("/")}/{TOKEN_URL.strip("/")}' +FULL_AMA_URL = f'{BASE_URL.rstrip("/")}/{AMA_URL.strip("/")}' # literals diff --git a/neuralspace/env.py b/neuralspace/env.py index 83a2ede..4d49969 100644 --- a/neuralspace/env.py +++ b/neuralspace/env.py @@ -10,4 +10,5 @@ STREAM_URL = get('NS_STREAM_URL') LANGS_URL = get('NS_LANGS_URL') TOKEN_URL = get('NS_TOKEN_URL') +AMA_URL = get('NS_AMA_URL') TIMEOUT_SEC = get('NS_TIMEOUT_SEC') diff --git a/neuralspace/voice_ai.py b/neuralspace/voice_ai.py index dc93e20..de2f2d4 100644 --- a/neuralspace/voice_ai.py +++ b/neuralspace/voice_ai.py @@ -254,6 +254,36 @@ def poll_until_complete(self, job_id: str, poll_schedule: Optional[List[float]] return result + def ama(self, job_id: str, prompts: List[str]) -> Dict[str, Any]: + """ + Create and send a request for an AMA job. + + Parameters + ---------- + job_id: str + The job ID for the AMA session. + prompts: List[str] + List of prompts for the AMA session. + + Returns + ------- + result: dict + The response from the server. + """ + url = f'{K.FULL_AMA_URL.rstrip("/")}' + hdrs = self._create_headers() + hdrs['Content-Type'] = 'application/json' + data = json.dumps({ + "jobId": job_id, + "prompts": prompts + }) + + sess = self._get_session() + r = sess.post(url, headers=hdrs, data=data) + resp = utils.get_json_resp(r) + return resp + + def _get_short_lived_token(self, timeout): url = f'{K.FULL_TOKEN_URL}?duration={timeout}' hdrs = self._create_headers() From e8a0944d7c84a356966ff161e7ad7be5dd258497 Mon Sep 17 00:00:00 2001 From: dalmeow Date: Thu, 11 Jan 2024 19:03:48 +0530 Subject: [PATCH 2/2] minor tweaks --- neuralspace/constants.py | 2 +- neuralspace/voice_ai.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/neuralspace/constants.py b/neuralspace/constants.py index fee9d53..81478e8 100644 --- a/neuralspace/constants.py +++ b/neuralspace/constants.py @@ -14,7 +14,7 @@ if env.JOBS_URL is not None: JOBS_URL = env.JOBS_URL -TTS_URL = 'api/v1/tts' +TTS_URL = 'api/v2/tts' if env.TTS_URL is not None: TTS_URL = env.TTS_URL diff --git a/neuralspace/voice_ai.py b/neuralspace/voice_ai.py index bfac712..8ef91a9 100644 --- a/neuralspace/voice_ai.py +++ b/neuralspace/voice_ai.py @@ -277,9 +277,9 @@ def ama(self, job_id: str, prompts: List[str]) -> Dict[str, Any]: Parameters ---------- job_id: str - The job ID for the AMA session. + The job ID for the transcript on which to run AMA. prompts: List[str] - List of prompts for the AMA session. + List of prompts for the AMA. Returns -------