Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend multiple-term Find & Replace to <=py3.9 #115

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

jkroll-deepgram
Copy link
Contributor

Previous PR (#99) relied on the | union operator, which is only supported in >=py3.10.

Existing code throws the follow error when importing from deepgram import Deepgram (using 3.9.17):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "39env/lib/python3.9/site-packages/deepgram/__init__.py", line 2, in <module>
    from ._types import Options
  File "39env/lib/python3.9/site-packages/deepgram/_types.py", line 54, in <module>
    class TranscriptionOptions(TypedDict, total=False):
  File "39env/lib/python3.9/site-packages/deepgram/_types.py", line 85, in TranscriptionOptions
    replace: str | List[str]
TypeError: unsupported operand type(s) for |: 'type' and '_GenericAlias'

Need to rely on the Union operator to support 3.9 and earlier. I tested this change in 3.9 and confirmed that the Deepgram import works successfully, as does making a call against Find & Replace with multiple terms.

from deepgram import Deepgram
import json
import asyncio

DEEPGRAM_API_KEY = '<key>'

AUDIO_URL = 'https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav'

async def main():
	dg_client = Deepgram(DEEPGRAM_API_KEY)
	response = await dg_client.transcription.prerecorded(
		{ 'url': AUDIO_URL},
		{
			"model": "nova",
			"smart_format": True,
			"replace": ["fast:slow", "miss:snooze"]
		},
	)
	print(response["results"]["channels"][0]["alternatives"][0]["transcript"])

asyncio.run(main())


Yep. I said it before, and I'll say it again. Life moves pretty slow. You don't stop and look around once in a while. you could snooze it.

Tests also pass - pytest --api-key <key> tests/

@lukeocodes lukeocodes merged commit 3d932dd into deepgram:main Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants