diff --git a/.fern/metadata.json b/.fern/metadata.json index 1bf9cd7e..770bf67f 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -1,7 +1,7 @@ { - "cliVersion": "4.92.0", + "cliVersion": "4.107.0", "generatorName": "fernapi/fern-python-sdk", - "generatorVersion": "5.5.11", + "generatorVersion": "5.8.3", "generatorConfig": { "client": { "class_name": "BaseClient", @@ -16,10 +16,8 @@ "skip_validation": true } }, - "originGitCommit": "a11286b37e09a565312275eb0ee6b111fbdc5360", + "originGitCommit": "05bd7add608b322a6278fa20da22f2ed501d50ef", "originGitCommitIsDirty": true, "invokedBy": "manual", - "requestedVersion": null, - "ciProvider": null, - "sdkVersion": "6.1.2" + "sdkVersion": "7.0.1" } \ No newline at end of file diff --git a/.fernignore b/.fernignore index 642889b3..ab51029b 100644 --- a/.fernignore +++ b/.fernignore @@ -17,8 +17,22 @@ src/deepgram/listen/v1/socket_client.py src/deepgram/listen/v2/socket_client.py src/deepgram/speak/v1/socket_client.py +# Backward-compatibility alias shims for renamed generated public types/params. +# These are hand-written wrappers around the current generated names and must not be regenerated. +src/deepgram/agent/v1/types/agent_v1history_content.py +src/deepgram/agent/v1/types/agent_v1history_function_calls.py +src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_content.py +src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_function_calls.py +src/deepgram/agent/v1/requests/agent_v1history_content.py +src/deepgram/agent/v1/requests/agent_v1history_function_calls.py +src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_content.py +src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_function_calls.py +src/deepgram/types/create_key_v1request_one.py +src/deepgram/requests/create_key_v1request_one.py + # Hand-written custom tests tests/custom/test_agent_history.py +tests/custom/test_compat_aliases.py tests/custom/test_text_builder.py tests/custom/test_transport.py diff --git a/AGENTS.md b/AGENTS.md index ffb21162..a8d76aa1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,8 +24,12 @@ How to identify: Current permanently frozen files: - `src/deepgram/client.py` — entirely custom (Bearer auth, session ID); no Fern equivalent - `src/deepgram/helpers/` — hand-written TextBuilder helpers +- `src/deepgram/agent/v1/types/agent_v1history_content.py`, `src/deepgram/agent/v1/types/agent_v1history_function_calls.py`, `src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_content.py`, `src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_function_calls.py` — hand-written compatibility aliases preserving old public Agent History type imports after regen renames +- `src/deepgram/agent/v1/requests/agent_v1history_content.py`, `src/deepgram/agent/v1/requests/agent_v1history_function_calls.py`, `src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_content.py`, `src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_function_calls.py` — hand-written compatibility aliases preserving old public Agent History request-param imports after regen renames +- `src/deepgram/types/create_key_v1request_one.py`, `src/deepgram/requests/create_key_v1request_one.py` — hand-written compatibility aliases preserving the old public create-key request imports after the regen rename to `CreateKeyV1Request` - `src/deepgram/transport_interface.py`, `src/deepgram/transport.py`, `src/deepgram/transports/` — custom transport layer - `tests/custom/test_agent_history.py` — hand-written regression test for Agent History websocket payload parsing +- `tests/custom/test_compat_aliases.py` — hand-written regression test for backward-compatible alias imports after regen renames - `tests/custom/test_text_builder.py`, `tests/custom/test_transport.py` — hand-written tests - `tests/manual/` — manual standalone tests - `README.md`, `CHANGELOG.md`, `CONTRIBUTING.md`, `reference.md` — docs diff --git a/examples/14-transcription-live-websocket-v2.py b/examples/14-transcription-live-websocket-v2.py index c60a50ab..a0fe09bc 100644 --- a/examples/14-transcription-live-websocket-v2.py +++ b/examples/14-transcription-live-websocket-v2.py @@ -3,6 +3,9 @@ This example shows how to use Listen V2 for advanced conversational speech recognition with contextual turn detection. + +It streams the bundled WAV fixture directly, so the example lets Deepgram infer the +audio format from the container instead of forcing raw linear16 settings. """ import os @@ -31,8 +34,6 @@ try: with client.listen.v2.connect( model="flux-general-en", - encoding="linear16", - sample_rate="16000", ) as connection: def on_message(message: ListenV2SocketClientResponse) -> None: diff --git a/examples/24-text-builder-streaming.py b/examples/24-text-builder-streaming.py index 3b49748e..b3608a00 100644 --- a/examples/24-text-builder-streaming.py +++ b/examples/24-text-builder-streaming.py @@ -4,15 +4,20 @@ This example demonstrates using TextBuilder with streaming text-to-speech over WebSocket for real-time audio generation. + +The streaming API path shown here focuses on pronunciation controls. Inline +pause tokens are omitted because the WebSocket endpoint may reject them with +DATA-0002 policy violations. """ import os +import threading from typing import Union from deepgram import DeepgramClient from deepgram.helpers import TextBuilder from deepgram.core.events import EventType -from deepgram.speak.v1.types import SpeakV1Close, SpeakV1Flush, SpeakV1Text +from deepgram.speak.v1.types import SpeakV1Text SpeakV1SocketClientResponse = Union[str, bytes] @@ -30,7 +35,6 @@ def example_streaming_with_textbuilder(): .text(" twice daily with ") .pronunciation("dupilumab", "duːˈpɪljuːmæb") .text(" injections.") - .pause(500) .text(" Do not exceed prescribed dosage.") .build() ) @@ -46,8 +50,9 @@ def example_streaming_with_textbuilder(): try: with client.speak.v1.connect( - model="aura-asteria-en", encoding="linear16", sample_rate=24000 + model="aura-2-asteria-en", encoding="linear16", sample_rate=24000 ) as connection: + closed_event = threading.Event() def on_message(message: SpeakV1SocketClientResponse) -> None: if isinstance(message, bytes): @@ -58,10 +63,12 @@ def on_message(message: SpeakV1SocketClientResponse) -> None: else: msg_type = getattr(message, "type", "Unknown") print(f"Received {msg_type} event") + if msg_type == "Flushed": + connection.send_close() connection.on(EventType.OPEN, lambda _: print("✓ Connection opened")) connection.on(EventType.MESSAGE, on_message) - connection.on(EventType.CLOSE, lambda _: print("✓ Connection closed")) + connection.on(EventType.CLOSE, lambda _: (print("✓ Connection closed"), closed_event.set())) connection.on(EventType.ERROR, lambda error: print(f"✗ Error: {error}")) # Send the TextBuilder-generated text @@ -70,11 +77,9 @@ def on_message(message: SpeakV1SocketClientResponse) -> None: # Flush to ensure all text is processed connection.send_flush() - # Close the connection when done - connection.send_close() - - # Start listening - this blocks until the connection closes - connection.start_listening() + listener = threading.Thread(target=connection.start_listening, daemon=True) + listener.start() + closed_event.wait(30) print("\n✓ Audio saved to streaming_output.raw") print(" Convert to WAV: ffmpeg -f s16le -ar 24000 -ac 1 -i streaming_output.raw output.wav") @@ -118,19 +123,24 @@ def example_multiple_messages(): try: with client.speak.v1.connect( - model="aura-asteria-en", encoding="linear16", sample_rate=24000 + model="aura-2-asteria-en", encoding="linear16", sample_rate=24000 ) as connection: audio_chunks = [] + closed_event = threading.Event() def on_message(message: SpeakV1SocketClientResponse) -> None: if isinstance(message, bytes): audio_chunks.append(message) print(f"Received {len(message)} bytes") + else: + msg_type = getattr(message, "type", "Unknown") + if msg_type == "Flushed": + connection.send_close() connection.on(EventType.OPEN, lambda _: print("✓ Connection opened")) connection.on(EventType.MESSAGE, on_message) - connection.on(EventType.CLOSE, lambda _: print("✓ Connection closed")) + connection.on(EventType.CLOSE, lambda _: (print("✓ Connection closed"), closed_event.set())) # Send multiple messages for i, text in enumerate([intro, instruction1, instruction2, closing], 1): @@ -138,9 +148,10 @@ def on_message(message: SpeakV1SocketClientResponse) -> None: connection.send_text(SpeakV1Text(text=text)) connection.send_flush() - connection.send_close() - connection.start_listening() + listener = threading.Thread(target=connection.start_listening, daemon=True) + listener.start() + closed_event.wait(30) # Save all audio with open("streaming_multi.raw", "wb") as f: @@ -155,6 +166,11 @@ def on_message(message: SpeakV1SocketClientResponse) -> None: def main(): """Run all streaming examples""" + if os.path.exists("streaming_output.raw"): + os.remove("streaming_output.raw") + if os.path.exists("streaming_multi.raw"): + os.remove("streaming_multi.raw") + example_streaming_with_textbuilder() example_multiple_messages() @@ -165,4 +181,3 @@ def main(): if __name__ == "__main__": main() - diff --git a/examples/30-voice-agent.py b/examples/30-voice-agent.py index f88188a7..75f57cfb 100644 --- a/examples/30-voice-agent.py +++ b/examples/30-voice-agent.py @@ -2,10 +2,10 @@ Example: Voice Agent (Agent V1) This example shows how to set up a voice agent that can listen, think, and speak. -It streams a pre-recorded audio file to simulate user speech. +To keep the example deterministic, it injects a user message after the settings are +applied and then prints the agent's text and audio responses. """ -import os import threading import time from typing import Union @@ -16,6 +16,7 @@ from deepgram import DeepgramClient from deepgram.agent.v1.types import ( + AgentV1InjectUserMessage, AgentV1Settings, AgentV1SettingsAgent, AgentV1SettingsAgentListen, @@ -30,13 +31,15 @@ from deepgram.types.think_settings_v1provider import ThinkSettingsV1Provider_OpenAi AgentV1SocketClientResponse = Union[str, bytes] +USER_MESSAGE = "What does the first all-female spacewalk symbolize?" client = DeepgramClient() -audio_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "audio.wav") - try: with client.agent.v1.connect() as agent: + settings_applied_event = threading.Event() + assistant_response_event = threading.Event() + # Configure the agent settings settings = AgentV1Settings( audio=AgentV1SettingsAudio( @@ -69,18 +72,20 @@ ), ) - print("Sending agent settings...") - agent.send_settings(settings) - def on_message(message: AgentV1SocketClientResponse) -> None: if isinstance(message, bytes): print(f"Received agent audio ({len(message)} bytes)") else: msg_type = getattr(message, "type", "Unknown") - if msg_type == "ConversationText": + if msg_type == "SettingsApplied": + print("Received SettingsApplied event") + settings_applied_event.set() + elif msg_type == "ConversationText": role = getattr(message, "role", "unknown") content = getattr(message, "content", "") print(f"[{role}] {content}") + if role == "assistant": + assistant_response_event.set() elif msg_type == "UserStartedSpeaking": print(">> User started speaking") elif msg_type == "AgentThinking": @@ -89,6 +94,11 @@ def on_message(message: AgentV1SocketClientResponse) -> None: print(">> Agent started speaking") elif msg_type == "AgentAudioDone": print(">> Agent finished speaking") + elif msg_type == "Error": + print( + f">> Agent error: {getattr(message, 'code', 'unknown')} - " + f"{getattr(message, 'description', 'unknown error')}" + ) else: print(f"Received {msg_type} event") @@ -97,26 +107,23 @@ def on_message(message: AgentV1SocketClientResponse) -> None: agent.on(EventType.CLOSE, lambda _: print("Connection closed")) agent.on(EventType.ERROR, lambda error: print(f"Error: {error}")) - # Stream audio in a background thread - def send_audio(): - with open(audio_path, "rb") as f: - audio_data = f.read() + listener = threading.Thread(target=agent.start_listening, daemon=True) + listener.start() + + print("Sending agent settings...") + agent.send_settings(settings) - chunk_size = 8192 - for i in range(0, len(audio_data), chunk_size): - chunk = audio_data[i : i + chunk_size] - if chunk: - agent.send_media(chunk) - time.sleep(0.01) + if not settings_applied_event.wait(10): + raise TimeoutError("Timed out waiting for agent settings to apply") - print("Finished streaming audio, waiting for agent response...") - time.sleep(15) + print(f"Sending injected user message: {USER_MESSAGE}") + agent.send_inject_user_message(AgentV1InjectUserMessage(content=USER_MESSAGE)) - sender = threading.Thread(target=send_audio, daemon=True) - sender.start() + if not assistant_response_event.wait(30): + raise TimeoutError("Timed out waiting for the agent to respond") - # Start listening - blocks until connection closes - agent.start_listening() + # Give the final audio callbacks a moment to flush before exiting the context. + time.sleep(2) except Exception as e: print(f"Error: {e}") diff --git a/examples/50-management-projects.py b/examples/50-management-projects.py index 43a39fb9..9500074f 100644 --- a/examples/50-management-projects.py +++ b/examples/50-management-projects.py @@ -27,10 +27,14 @@ project = client.manage.v1.projects.get(project_id=project_id) print(f"Project name: {project.name}") - # Update project name + # Update the project using the current name so the example exercises the + # update endpoint without unexpectedly renaming a live project. print("\nUpdating project name...") - updated = client.manage.v1.projects.update(project_id=project_id, name="Updated Project Name") - print(f"Updated project name: {updated.name}") + updated = client.manage.v1.projects.update(project_id=project_id, name=project.name) + print(f"Update response: {updated.message}") + + refreshed_project = client.manage.v1.projects.get(project_id=project_id) + print(f"Verified project name: {refreshed_project.name}") # Note: Delete and leave operations are commented out for safety # Delete a project: diff --git a/poetry.lock b/poetry.lock index 5399b9ba..fb7ee00d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -881,13 +881,13 @@ files = [ [[package]] name = "packaging" -version = "26.1" +version = "26.2" description = "Core utilities for Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "packaging-26.1-py3-none-any.whl", hash = "sha256:5d9c0669c6285e491e0ced2eee587eaf67b670d94a19e94e3984a481aba6802f"}, - {file = "packaging-26.1.tar.gz", hash = "sha256:f042152b681c4bfac5cae2742a55e103d27ab2ec0f3d88037136b6bfe7c9c5de"}, + {file = "packaging-26.2-py3-none-any.whl", hash = "sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e"}, + {file = "packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"}, ] [[package]] @@ -1681,4 +1681,4 @@ aiohttp = ["aiohttp", "httpx-aiohttp"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "dd099e9cb03874e4a2fecf5b883fca8ac95981d50355ce3e88fa1f46d8e33b35" +content-hash = "d5bb491d83f174bf8206626bc5d74340716472be6f8907c2b3cfe7c8b8f0598a" diff --git a/pyproject.toml b/pyproject.toml index 6b35588d..f3e246f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ dynamic = ["version"] [tool.poetry] name = "deepgram-sdk" -version = "7.0.0" +version = "7.0.1" description = "" readme = "README.md" authors = [] @@ -53,7 +53,7 @@ pytest-asyncio = "^1.0.0" pytest-xdist = "^3.6.1" python-dateutil = "^2.9.0" types-python-dateutil = "^2.9.0.20240316" -urllib3 = ">=1.26.19,<2.0.0 || >=2.2.2,<3.0.0" +urllib3 = ">=2.6.3,<3.0.0" requests = "^2.33.0" types-requests = "^2.33.0" ruff = "==0.11.5" diff --git a/src/deepgram/__init__.py b/src/deepgram/__init__.py index 8f46a0b9..f7fe77c0 100644 --- a/src/deepgram/__init__.py +++ b/src/deepgram/__init__.py @@ -38,6 +38,7 @@ CartesiaSpeakProviderModelId, CartesiaSpeakProviderVoice, CreateAgentConfigurationV1Response, + CreateKeyV1Request, CreateKeyV1RequestOne, CreateKeyV1Response, CreateProjectDistributionCredentialsV1Response, @@ -163,6 +164,7 @@ ListenV2EotThreshold, ListenV2EotTimeoutMs, ListenV2Keyterm, + ListenV2LanguageHint, ListenV2MipOptOut, ListenV2Model, ListenV2SampleRate, @@ -263,6 +265,7 @@ CartesiaParams, CartesiaSpeakProviderVoiceParams, CreateAgentConfigurationV1ResponseParams, + CreateKeyV1RequestParams, CreateKeyV1ResponseParams, CreateProjectDistributionCredentialsV1ResponseDistributionCredentialsParams, CreateProjectDistributionCredentialsV1ResponseMemberParams, @@ -347,6 +350,7 @@ ListenV1ResponseResultsUtterancesItemWordsItemParams, ListenV1ResponseResultsUtterancesParams, ListenV2KeytermParams, + ListenV2LanguageHintParams, OpenAiSpeakProviderParams, OpenAiThinkProviderParams, ProjectRequestResponseParams, @@ -463,7 +467,9 @@ "CartesiaSpeakProviderVoiceParams": ".requests", "CreateAgentConfigurationV1Response": ".types", "CreateAgentConfigurationV1ResponseParams": ".requests", + "CreateKeyV1Request": ".types", "CreateKeyV1RequestOne": ".types", + "CreateKeyV1RequestParams": ".requests", "CreateKeyV1Response": ".types", "CreateKeyV1ResponseParams": ".requests", "CreateProjectDistributionCredentialsV1Response": ".types", @@ -676,6 +682,8 @@ "ListenV2EotTimeoutMs": ".types", "ListenV2Keyterm": ".types", "ListenV2KeytermParams": ".requests", + "ListenV2LanguageHint": ".types", + "ListenV2LanguageHintParams": ".requests", "ListenV2MipOptOut": ".types", "ListenV2Model": ".types", "ListenV2SampleRate": ".types", @@ -895,7 +903,9 @@ def __dir__(): "CartesiaSpeakProviderVoiceParams", "CreateAgentConfigurationV1Response", "CreateAgentConfigurationV1ResponseParams", + "CreateKeyV1Request", "CreateKeyV1RequestOne", + "CreateKeyV1RequestParams", "CreateKeyV1Response", "CreateKeyV1ResponseParams", "CreateProjectDistributionCredentialsV1Response", @@ -1108,6 +1118,8 @@ def __dir__(): "ListenV2EotTimeoutMs", "ListenV2Keyterm", "ListenV2KeytermParams", + "ListenV2LanguageHint", + "ListenV2LanguageHintParams", "ListenV2MipOptOut", "ListenV2Model", "ListenV2SampleRate", diff --git a/src/deepgram/agent/__init__.py b/src/deepgram/agent/__init__.py index 599c19b5..81dcbfa0 100644 --- a/src/deepgram/agent/__init__.py +++ b/src/deepgram/agent/__init__.py @@ -33,6 +33,7 @@ AgentV1HistoryFunctionCallsParams, AgentV1HistoryParams, AgentV1InjectAgentMessage, + AgentV1InjectAgentMessageBehavior, AgentV1InjectAgentMessageParams, AgentV1InjectUserMessage, AgentV1InjectUserMessageParams, @@ -109,6 +110,10 @@ AgentV1WarningParams, AgentV1Welcome, AgentV1WelcomeParams, + ConversationHistoryMessage, + ConversationHistoryMessageParams, + FunctionCallHistoryMessage, + FunctionCallHistoryMessageParams, ) _dynamic_imports: typing.Dict[str, str] = { "AgentV1AgentAudioDone": ".v1", @@ -136,6 +141,7 @@ "AgentV1HistoryFunctionCallsParams": ".v1", "AgentV1HistoryParams": ".v1", "AgentV1InjectAgentMessage": ".v1", + "AgentV1InjectAgentMessageBehavior": ".v1", "AgentV1InjectAgentMessageParams": ".v1", "AgentV1InjectUserMessage": ".v1", "AgentV1InjectUserMessageParams": ".v1", @@ -212,6 +218,10 @@ "AgentV1WarningParams": ".v1", "AgentV1Welcome": ".v1", "AgentV1WelcomeParams": ".v1", + "ConversationHistoryMessage": ".v1", + "ConversationHistoryMessageParams": ".v1", + "FunctionCallHistoryMessage": ".v1", + "FunctionCallHistoryMessageParams": ".v1", "v1": ".v1", } @@ -263,6 +273,7 @@ def __dir__(): "AgentV1HistoryFunctionCallsParams", "AgentV1HistoryParams", "AgentV1InjectAgentMessage", + "AgentV1InjectAgentMessageBehavior", "AgentV1InjectAgentMessageParams", "AgentV1InjectUserMessage", "AgentV1InjectUserMessageParams", @@ -339,5 +350,9 @@ def __dir__(): "AgentV1WarningParams", "AgentV1Welcome", "AgentV1WelcomeParams", + "ConversationHistoryMessage", + "ConversationHistoryMessageParams", + "FunctionCallHistoryMessage", + "FunctionCallHistoryMessageParams", "v1", ] diff --git a/src/deepgram/agent/v1/__init__.py b/src/deepgram/agent/v1/__init__.py index 084cb184..31bd1db4 100644 --- a/src/deepgram/agent/v1/__init__.py +++ b/src/deepgram/agent/v1/__init__.py @@ -21,6 +21,7 @@ AgentV1HistoryFunctionCalls, AgentV1HistoryFunctionCallsFunctionCallsItem, AgentV1InjectAgentMessage, + AgentV1InjectAgentMessageBehavior, AgentV1InjectUserMessage, AgentV1InjectionRefused, AgentV1KeepAlive, @@ -60,6 +61,8 @@ AgentV1UserStartedSpeaking, AgentV1Warning, AgentV1Welcome, + ConversationHistoryMessage, + FunctionCallHistoryMessage, ) from . import settings from .requests import ( @@ -81,8 +84,8 @@ AgentV1PromptUpdatedParams, AgentV1ReceiveFunctionCallResponseParams, AgentV1SendFunctionCallResponseParams, - AgentV1SettingsAgentContextMessagesItemContentParams, AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams, + AgentV1SettingsAgentContextMessagesItemContentParams, AgentV1SettingsAgentContextMessagesItemFunctionCallsParams, AgentV1SettingsAgentContextMessagesItemParams, AgentV1SettingsAgentContextParams, @@ -111,6 +114,8 @@ AgentV1UserStartedSpeakingParams, AgentV1WarningParams, AgentV1WelcomeParams, + ConversationHistoryMessageParams, + FunctionCallHistoryMessageParams, ) _dynamic_imports: typing.Dict[str, str] = { "AgentV1AgentAudioDone": ".types", @@ -138,6 +143,7 @@ "AgentV1HistoryFunctionCallsParams": ".requests", "AgentV1HistoryParams": ".requests", "AgentV1InjectAgentMessage": ".types", + "AgentV1InjectAgentMessageBehavior": ".types", "AgentV1InjectAgentMessageParams": ".requests", "AgentV1InjectUserMessage": ".types", "AgentV1InjectUserMessageParams": ".requests", @@ -214,6 +220,10 @@ "AgentV1WarningParams": ".requests", "AgentV1Welcome": ".types", "AgentV1WelcomeParams": ".requests", + "ConversationHistoryMessage": ".types", + "ConversationHistoryMessageParams": ".requests", + "FunctionCallHistoryMessage": ".types", + "FunctionCallHistoryMessageParams": ".requests", "settings": ".settings", } @@ -265,6 +275,7 @@ def __dir__(): "AgentV1HistoryFunctionCallsParams", "AgentV1HistoryParams", "AgentV1InjectAgentMessage", + "AgentV1InjectAgentMessageBehavior", "AgentV1InjectAgentMessageParams", "AgentV1InjectUserMessage", "AgentV1InjectUserMessageParams", @@ -341,5 +352,9 @@ def __dir__(): "AgentV1WarningParams", "AgentV1Welcome", "AgentV1WelcomeParams", + "ConversationHistoryMessage", + "ConversationHistoryMessageParams", + "FunctionCallHistoryMessage", + "FunctionCallHistoryMessageParams", "settings", ] diff --git a/src/deepgram/agent/v1/requests/__init__.py b/src/deepgram/agent/v1/requests/__init__.py index a6d338c1..6c6fc0e6 100644 --- a/src/deepgram/agent/v1/requests/__init__.py +++ b/src/deepgram/agent/v1/requests/__init__.py @@ -28,9 +28,7 @@ from .agent_v1settings_agent import AgentV1SettingsAgentParams from .agent_v1settings_agent_context import AgentV1SettingsAgentContextParams from .agent_v1settings_agent_context_messages_item import AgentV1SettingsAgentContextMessagesItemParams - from .agent_v1settings_agent_context_messages_item_content import ( - AgentV1SettingsAgentContextMessagesItemContentParams, - ) + from .agent_v1settings_agent_context_messages_item_content import AgentV1SettingsAgentContextMessagesItemContentParams from .agent_v1settings_agent_context_messages_item_function_calls import ( AgentV1SettingsAgentContextMessagesItemFunctionCallsParams, ) @@ -62,6 +60,8 @@ from .agent_v1user_started_speaking import AgentV1UserStartedSpeakingParams from .agent_v1warning import AgentV1WarningParams from .agent_v1welcome import AgentV1WelcomeParams + from .conversation_history_message import ConversationHistoryMessageParams + from .function_call_history_message import FunctionCallHistoryMessageParams _dynamic_imports: typing.Dict[str, str] = { "AgentV1AgentAudioDoneParams": ".agent_v1agent_audio_done", "AgentV1AgentStartedSpeakingParams": ".agent_v1agent_started_speaking", @@ -81,8 +81,8 @@ "AgentV1PromptUpdatedParams": ".agent_v1prompt_updated", "AgentV1ReceiveFunctionCallResponseParams": ".agent_v1receive_function_call_response", "AgentV1SendFunctionCallResponseParams": ".agent_v1send_function_call_response", - "AgentV1SettingsAgentContextMessagesItemContentParams": ".agent_v1settings_agent_context_messages_item_content", "AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams": ".agent_v1settings_agent_context_messages_item_function_calls_function_calls_item", + "AgentV1SettingsAgentContextMessagesItemContentParams": ".agent_v1settings_agent_context_messages_item_content", "AgentV1SettingsAgentContextMessagesItemFunctionCallsParams": ".agent_v1settings_agent_context_messages_item_function_calls", "AgentV1SettingsAgentContextMessagesItemParams": ".agent_v1settings_agent_context_messages_item", "AgentV1SettingsAgentContextParams": ".agent_v1settings_agent_context", @@ -111,6 +111,8 @@ "AgentV1UserStartedSpeakingParams": ".agent_v1user_started_speaking", "AgentV1WarningParams": ".agent_v1warning", "AgentV1WelcomeParams": ".agent_v1welcome", + "ConversationHistoryMessageParams": ".conversation_history_message", + "FunctionCallHistoryMessageParams": ".function_call_history_message", } @@ -154,8 +156,8 @@ def __dir__(): "AgentV1PromptUpdatedParams", "AgentV1ReceiveFunctionCallResponseParams", "AgentV1SendFunctionCallResponseParams", - "AgentV1SettingsAgentContextMessagesItemContentParams", "AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams", + "AgentV1SettingsAgentContextMessagesItemContentParams", "AgentV1SettingsAgentContextMessagesItemFunctionCallsParams", "AgentV1SettingsAgentContextMessagesItemParams", "AgentV1SettingsAgentContextParams", @@ -184,4 +186,6 @@ def __dir__(): "AgentV1UserStartedSpeakingParams", "AgentV1WarningParams", "AgentV1WelcomeParams", + "ConversationHistoryMessageParams", + "FunctionCallHistoryMessageParams", ] diff --git a/src/deepgram/agent/v1/requests/agent_v1history.py b/src/deepgram/agent/v1/requests/agent_v1history.py index 181bfdfd..a0f8a56b 100644 --- a/src/deepgram/agent/v1/requests/agent_v1history.py +++ b/src/deepgram/agent/v1/requests/agent_v1history.py @@ -2,7 +2,7 @@ import typing -from .agent_v1history_content import AgentV1HistoryContentParams -from .agent_v1history_function_calls import AgentV1HistoryFunctionCallsParams +from .conversation_history_message import ConversationHistoryMessageParams +from .function_call_history_message import FunctionCallHistoryMessageParams -AgentV1HistoryParams = typing.Union[AgentV1HistoryContentParams, AgentV1HistoryFunctionCallsParams] +AgentV1HistoryParams = typing.Union[ConversationHistoryMessageParams, FunctionCallHistoryMessageParams] diff --git a/src/deepgram/agent/v1/requests/agent_v1history_content.py b/src/deepgram/agent/v1/requests/agent_v1history_content.py index 80dca1ae..a885b9bd 100644 --- a/src/deepgram/agent/v1/requests/agent_v1history_content.py +++ b/src/deepgram/agent/v1/requests/agent_v1history_content.py @@ -1,27 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .conversation_history_message import ConversationHistoryMessageParams -import typing_extensions -from ..types.agent_v1history_content_role import AgentV1HistoryContentRole - - -class AgentV1HistoryContentParams(typing_extensions.TypedDict): - """ - Conversation text as part of the conversation history - """ - - type: typing.Literal["History"] - """ - Message type identifier for conversation text - """ - - role: AgentV1HistoryContentRole - """ - Identifies who spoke the statement - """ - - content: str - """ - The actual statement that was spoken - """ +AgentV1HistoryContentParams = ConversationHistoryMessageParams diff --git a/src/deepgram/agent/v1/requests/agent_v1history_function_calls.py b/src/deepgram/agent/v1/requests/agent_v1history_function_calls.py index 3695cfc2..21f1c817 100644 --- a/src/deepgram/agent/v1/requests/agent_v1history_function_calls.py +++ b/src/deepgram/agent/v1/requests/agent_v1history_function_calls.py @@ -1,18 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .function_call_history_message import FunctionCallHistoryMessageParams -import typing_extensions -from .agent_v1history_function_calls_function_calls_item import AgentV1HistoryFunctionCallsFunctionCallsItemParams - - -class AgentV1HistoryFunctionCallsParams(typing_extensions.TypedDict): - """ - Client-side or server-side function call request and response as part of the conversation history - """ - - type: typing.Literal["History"] - function_calls: typing.Sequence[AgentV1HistoryFunctionCallsFunctionCallsItemParams] - """ - List of function call objects - """ +AgentV1HistoryFunctionCallsParams = FunctionCallHistoryMessageParams diff --git a/src/deepgram/agent/v1/requests/agent_v1inject_agent_message.py b/src/deepgram/agent/v1/requests/agent_v1inject_agent_message.py index 8fb718bd..304cf18b 100644 --- a/src/deepgram/agent/v1/requests/agent_v1inject_agent_message.py +++ b/src/deepgram/agent/v1/requests/agent_v1inject_agent_message.py @@ -3,6 +3,7 @@ import typing import typing_extensions +from ..types.agent_v1inject_agent_message_behavior import AgentV1InjectAgentMessageBehavior class AgentV1InjectAgentMessageParams(typing_extensions.TypedDict): @@ -15,3 +16,11 @@ class AgentV1InjectAgentMessageParams(typing_extensions.TypedDict): """ The statement that the agent should say """ + + behavior: typing_extensions.NotRequired[AgentV1InjectAgentMessageBehavior] + """ + Controls how the injection interacts with any in-progress user or agent turn. + + * `default` — The agent speaks only if neither the user nor the agent is mid-turn. If a turn is in progress, the server replies with `InjectionRefused`. + * `queue` — The message is appended after any already-queued `ConversationText` without interrupting the current agent turn or think response. If nothing is queued, the message plays immediately. + """ diff --git a/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item.py b/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item.py index cf31d658..a9fd9f6b 100644 --- a/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item.py +++ b/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item.py @@ -2,11 +2,9 @@ import typing -from .agent_v1settings_agent_context_messages_item_content import AgentV1SettingsAgentContextMessagesItemContentParams -from .agent_v1settings_agent_context_messages_item_function_calls import ( - AgentV1SettingsAgentContextMessagesItemFunctionCallsParams, -) +from .conversation_history_message import ConversationHistoryMessageParams +from .function_call_history_message import FunctionCallHistoryMessageParams AgentV1SettingsAgentContextMessagesItemParams = typing.Union[ - AgentV1SettingsAgentContextMessagesItemContentParams, AgentV1SettingsAgentContextMessagesItemFunctionCallsParams + ConversationHistoryMessageParams, FunctionCallHistoryMessageParams ] diff --git a/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_content.py b/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_content.py index 1a541ffc..06512b37 100644 --- a/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_content.py +++ b/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_content.py @@ -1,29 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .conversation_history_message import ConversationHistoryMessageParams -import typing_extensions -from ..types.agent_v1settings_agent_context_messages_item_content_role import ( - AgentV1SettingsAgentContextMessagesItemContentRole, -) - - -class AgentV1SettingsAgentContextMessagesItemContentParams(typing_extensions.TypedDict): - """ - Conversation text as part of the conversation history - """ - - type: typing.Literal["History"] - """ - Message type identifier for conversation text - """ - - role: AgentV1SettingsAgentContextMessagesItemContentRole - """ - Identifies who spoke the statement - """ - - content: str - """ - The actual statement that was spoken - """ +AgentV1SettingsAgentContextMessagesItemContentParams = ConversationHistoryMessageParams diff --git a/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_function_calls.py b/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_function_calls.py index cdc5733c..2a37f1e5 100644 --- a/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_function_calls.py +++ b/src/deepgram/agent/v1/requests/agent_v1settings_agent_context_messages_item_function_calls.py @@ -1,20 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .function_call_history_message import FunctionCallHistoryMessageParams -import typing_extensions -from .agent_v1settings_agent_context_messages_item_function_calls_function_calls_item import ( - AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams, -) - - -class AgentV1SettingsAgentContextMessagesItemFunctionCallsParams(typing_extensions.TypedDict): - """ - Client-side or server-side function call request and response as part of the conversation history - """ - - type: typing.Literal["History"] - function_calls: typing.Sequence[AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams] - """ - List of function call objects - """ +AgentV1SettingsAgentContextMessagesItemFunctionCallsParams = FunctionCallHistoryMessageParams diff --git a/src/deepgram/agent/v1/requests/conversation_history_message.py b/src/deepgram/agent/v1/requests/conversation_history_message.py new file mode 100644 index 00000000..93b350d7 --- /dev/null +++ b/src/deepgram/agent/v1/requests/conversation_history_message.py @@ -0,0 +1,29 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import typing_extensions +from ..types.agent_v1settings_agent_context_messages_item_content_role import ( + AgentV1SettingsAgentContextMessagesItemContentRole, +) + + +class ConversationHistoryMessageParams(typing_extensions.TypedDict): + """ + Conversation text as part of the conversation history + """ + + type: typing.Literal["History"] + """ + Message type identifier for conversation text + """ + + role: AgentV1SettingsAgentContextMessagesItemContentRole + """ + Identifies who spoke the statement + """ + + content: str + """ + The actual statement that was spoken + """ diff --git a/src/deepgram/agent/v1/requests/function_call_history_message.py b/src/deepgram/agent/v1/requests/function_call_history_message.py new file mode 100644 index 00000000..9bc1d14e --- /dev/null +++ b/src/deepgram/agent/v1/requests/function_call_history_message.py @@ -0,0 +1,20 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import typing_extensions +from .agent_v1settings_agent_context_messages_item_function_calls_function_calls_item import ( + AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams, +) + + +class FunctionCallHistoryMessageParams(typing_extensions.TypedDict): + """ + Client-side or server-side function call request and response as part of the conversation history + """ + + type: typing.Literal["History"] + function_calls: typing.Sequence[AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItemParams] + """ + List of function call objects + """ diff --git a/src/deepgram/agent/v1/types/__init__.py b/src/deepgram/agent/v1/types/__init__.py index efadce6c..7a6da0d6 100644 --- a/src/deepgram/agent/v1/types/__init__.py +++ b/src/deepgram/agent/v1/types/__init__.py @@ -20,6 +20,7 @@ from .agent_v1history_function_calls import AgentV1HistoryFunctionCalls from .agent_v1history_function_calls_function_calls_item import AgentV1HistoryFunctionCallsFunctionCallsItem from .agent_v1inject_agent_message import AgentV1InjectAgentMessage + from .agent_v1inject_agent_message_behavior import AgentV1InjectAgentMessageBehavior from .agent_v1inject_user_message import AgentV1InjectUserMessage from .agent_v1injection_refused import AgentV1InjectionRefused from .agent_v1keep_alive import AgentV1KeepAlive @@ -67,6 +68,8 @@ from .agent_v1user_started_speaking import AgentV1UserStartedSpeaking from .agent_v1warning import AgentV1Warning from .agent_v1welcome import AgentV1Welcome + from .conversation_history_message import ConversationHistoryMessage + from .function_call_history_message import FunctionCallHistoryMessage _dynamic_imports: typing.Dict[str, str] = { "AgentV1AgentAudioDone": ".agent_v1agent_audio_done", "AgentV1AgentStartedSpeaking": ".agent_v1agent_started_speaking", @@ -82,6 +85,7 @@ "AgentV1HistoryFunctionCalls": ".agent_v1history_function_calls", "AgentV1HistoryFunctionCallsFunctionCallsItem": ".agent_v1history_function_calls_function_calls_item", "AgentV1InjectAgentMessage": ".agent_v1inject_agent_message", + "AgentV1InjectAgentMessageBehavior": ".agent_v1inject_agent_message_behavior", "AgentV1InjectUserMessage": ".agent_v1inject_user_message", "AgentV1InjectionRefused": ".agent_v1injection_refused", "AgentV1KeepAlive": ".agent_v1keep_alive", @@ -121,6 +125,8 @@ "AgentV1UserStartedSpeaking": ".agent_v1user_started_speaking", "AgentV1Warning": ".agent_v1warning", "AgentV1Welcome": ".agent_v1welcome", + "ConversationHistoryMessage": ".conversation_history_message", + "FunctionCallHistoryMessage": ".function_call_history_message", } @@ -160,6 +166,7 @@ def __dir__(): "AgentV1HistoryFunctionCalls", "AgentV1HistoryFunctionCallsFunctionCallsItem", "AgentV1InjectAgentMessage", + "AgentV1InjectAgentMessageBehavior", "AgentV1InjectUserMessage", "AgentV1InjectionRefused", "AgentV1KeepAlive", @@ -199,4 +206,6 @@ def __dir__(): "AgentV1UserStartedSpeaking", "AgentV1Warning", "AgentV1Welcome", + "ConversationHistoryMessage", + "FunctionCallHistoryMessage", ] diff --git a/src/deepgram/agent/v1/types/agent_v1history.py b/src/deepgram/agent/v1/types/agent_v1history.py index a3164360..40f2aba6 100644 --- a/src/deepgram/agent/v1/types/agent_v1history.py +++ b/src/deepgram/agent/v1/types/agent_v1history.py @@ -2,7 +2,7 @@ import typing -from .agent_v1history_content import AgentV1HistoryContent -from .agent_v1history_function_calls import AgentV1HistoryFunctionCalls +from .conversation_history_message import ConversationHistoryMessage +from .function_call_history_message import FunctionCallHistoryMessage -AgentV1History = typing.Union[AgentV1HistoryContent, AgentV1HistoryFunctionCalls] +AgentV1History = typing.Union[ConversationHistoryMessage, FunctionCallHistoryMessage] diff --git a/src/deepgram/agent/v1/types/agent_v1history_content.py b/src/deepgram/agent/v1/types/agent_v1history_content.py index 5c8a9c3a..19a388ba 100644 --- a/src/deepgram/agent/v1/types/agent_v1history_content.py +++ b/src/deepgram/agent/v1/types/agent_v1history_content.py @@ -1,38 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .conversation_history_message import ConversationHistoryMessage -import pydantic -from ....core.pydantic_utilities import IS_PYDANTIC_V2 -from ....core.unchecked_base_model import UncheckedBaseModel -from .agent_v1history_content_role import AgentV1HistoryContentRole - - -class AgentV1HistoryContent(UncheckedBaseModel): - """ - Conversation text as part of the conversation history - """ - - type: typing.Literal["History"] = pydantic.Field(default="History") - """ - Message type identifier for conversation text - """ - - role: AgentV1HistoryContentRole = pydantic.Field() - """ - Identifies who spoke the statement - """ - - content: str = pydantic.Field() - """ - The actual statement that was spoken - """ - - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow +AgentV1HistoryContent = ConversationHistoryMessage diff --git a/src/deepgram/agent/v1/types/agent_v1history_function_calls.py b/src/deepgram/agent/v1/types/agent_v1history_function_calls.py index 66f9c34f..34639051 100644 --- a/src/deepgram/agent/v1/types/agent_v1history_function_calls.py +++ b/src/deepgram/agent/v1/types/agent_v1history_function_calls.py @@ -1,29 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .function_call_history_message import FunctionCallHistoryMessage -import pydantic -from ....core.pydantic_utilities import IS_PYDANTIC_V2 -from ....core.unchecked_base_model import UncheckedBaseModel -from .agent_v1history_function_calls_function_calls_item import AgentV1HistoryFunctionCallsFunctionCallsItem - - -class AgentV1HistoryFunctionCalls(UncheckedBaseModel): - """ - Client-side or server-side function call request and response as part of the conversation history - """ - - type: typing.Literal["History"] = "History" - function_calls: typing.List[AgentV1HistoryFunctionCallsFunctionCallsItem] = pydantic.Field() - """ - List of function call objects - """ - - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow +AgentV1HistoryFunctionCalls = FunctionCallHistoryMessage diff --git a/src/deepgram/agent/v1/types/agent_v1inject_agent_message.py b/src/deepgram/agent/v1/types/agent_v1inject_agent_message.py index a2ca5886..a2a1c61d 100644 --- a/src/deepgram/agent/v1/types/agent_v1inject_agent_message.py +++ b/src/deepgram/agent/v1/types/agent_v1inject_agent_message.py @@ -5,6 +5,7 @@ import pydantic from ....core.pydantic_utilities import IS_PYDANTIC_V2 from ....core.unchecked_base_model import UncheckedBaseModel +from .agent_v1inject_agent_message_behavior import AgentV1InjectAgentMessageBehavior class AgentV1InjectAgentMessage(UncheckedBaseModel): @@ -18,6 +19,14 @@ class AgentV1InjectAgentMessage(UncheckedBaseModel): The statement that the agent should say """ + behavior: typing.Optional[AgentV1InjectAgentMessageBehavior] = pydantic.Field(default=None) + """ + Controls how the injection interacts with any in-progress user or agent turn. + + * `default` — The agent speaks only if neither the user nor the agent is mid-turn. If a turn is in progress, the server replies with `InjectionRefused`. + * `queue` — The message is appended after any already-queued `ConversationText` without interrupting the current agent turn or think response. If nothing is queued, the message plays immediately. + """ + if IS_PYDANTIC_V2: model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 else: diff --git a/src/deepgram/agent/v1/types/agent_v1inject_agent_message_behavior.py b/src/deepgram/agent/v1/types/agent_v1inject_agent_message_behavior.py new file mode 100644 index 00000000..9c610dc4 --- /dev/null +++ b/src/deepgram/agent/v1/types/agent_v1inject_agent_message_behavior.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +AgentV1InjectAgentMessageBehavior = typing.Union[typing.Literal["default", "queue"], typing.Any] diff --git a/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item.py b/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item.py index 2061fd2d..6fb14531 100644 --- a/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item.py +++ b/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item.py @@ -2,11 +2,7 @@ import typing -from .agent_v1settings_agent_context_messages_item_content import AgentV1SettingsAgentContextMessagesItemContent -from .agent_v1settings_agent_context_messages_item_function_calls import ( - AgentV1SettingsAgentContextMessagesItemFunctionCalls, -) +from .conversation_history_message import ConversationHistoryMessage +from .function_call_history_message import FunctionCallHistoryMessage -AgentV1SettingsAgentContextMessagesItem = typing.Union[ - AgentV1SettingsAgentContextMessagesItemContent, AgentV1SettingsAgentContextMessagesItemFunctionCalls -] +AgentV1SettingsAgentContextMessagesItem = typing.Union[ConversationHistoryMessage, FunctionCallHistoryMessage] diff --git a/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_content.py b/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_content.py index c1ad74ec..d2543faf 100644 --- a/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_content.py +++ b/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_content.py @@ -1,40 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .conversation_history_message import ConversationHistoryMessage -import pydantic -from ....core.pydantic_utilities import IS_PYDANTIC_V2 -from ....core.unchecked_base_model import UncheckedBaseModel -from .agent_v1settings_agent_context_messages_item_content_role import ( - AgentV1SettingsAgentContextMessagesItemContentRole, -) - - -class AgentV1SettingsAgentContextMessagesItemContent(UncheckedBaseModel): - """ - Conversation text as part of the conversation history - """ - - type: typing.Literal["History"] = pydantic.Field(default="History") - """ - Message type identifier for conversation text - """ - - role: AgentV1SettingsAgentContextMessagesItemContentRole = pydantic.Field() - """ - Identifies who spoke the statement - """ - - content: str = pydantic.Field() - """ - The actual statement that was spoken - """ - - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow +AgentV1SettingsAgentContextMessagesItemContent = ConversationHistoryMessage diff --git a/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_function_calls.py b/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_function_calls.py index dd693535..2a2f67b2 100644 --- a/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_function_calls.py +++ b/src/deepgram/agent/v1/types/agent_v1settings_agent_context_messages_item_function_calls.py @@ -1,33 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .function_call_history_message import FunctionCallHistoryMessage -import pydantic -from ....core.pydantic_utilities import IS_PYDANTIC_V2 -from ....core.unchecked_base_model import UncheckedBaseModel -from .agent_v1settings_agent_context_messages_item_function_calls_function_calls_item import ( - AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItem, -) - - -class AgentV1SettingsAgentContextMessagesItemFunctionCalls(UncheckedBaseModel): - """ - Client-side or server-side function call request and response as part of the conversation history - """ - - type: typing.Literal["History"] = "History" - function_calls: typing.List[AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItem] = ( - pydantic.Field() - ) - """ - List of function call objects - """ - - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow +AgentV1SettingsAgentContextMessagesItemFunctionCalls = FunctionCallHistoryMessage diff --git a/src/deepgram/agent/v1/types/conversation_history_message.py b/src/deepgram/agent/v1/types/conversation_history_message.py new file mode 100644 index 00000000..bce234b5 --- /dev/null +++ b/src/deepgram/agent/v1/types/conversation_history_message.py @@ -0,0 +1,40 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import pydantic +from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.unchecked_base_model import UncheckedBaseModel +from .agent_v1settings_agent_context_messages_item_content_role import ( + AgentV1SettingsAgentContextMessagesItemContentRole, +) + + +class ConversationHistoryMessage(UncheckedBaseModel): + """ + Conversation text as part of the conversation history + """ + + type: typing.Literal["History"] = pydantic.Field(default="History") + """ + Message type identifier for conversation text + """ + + role: AgentV1SettingsAgentContextMessagesItemContentRole = pydantic.Field() + """ + Identifies who spoke the statement + """ + + content: str = pydantic.Field() + """ + The actual statement that was spoken + """ + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/deepgram/agent/v1/types/function_call_history_message.py b/src/deepgram/agent/v1/types/function_call_history_message.py new file mode 100644 index 00000000..68c6e64f --- /dev/null +++ b/src/deepgram/agent/v1/types/function_call_history_message.py @@ -0,0 +1,33 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import pydantic +from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.unchecked_base_model import UncheckedBaseModel +from .agent_v1settings_agent_context_messages_item_function_calls_function_calls_item import ( + AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItem, +) + + +class FunctionCallHistoryMessage(UncheckedBaseModel): + """ + Client-side or server-side function call request and response as part of the conversation history + """ + + type: typing.Literal["History"] = "History" + function_calls: typing.List[AgentV1SettingsAgentContextMessagesItemFunctionCallsFunctionCallsItem] = ( + pydantic.Field() + ) + """ + List of function call objects + """ + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/deepgram/core/client_wrapper.py b/src/deepgram/core/client_wrapper.py index 89065f2c..80d2e267 100644 --- a/src/deepgram/core/client_wrapper.py +++ b/src/deepgram/core/client_wrapper.py @@ -28,12 +28,12 @@ def get_headers(self) -> typing.Dict[str, str]: import platform headers: typing.Dict[str, str] = { - "User-Agent": "deepgram-sdk/6.1.2", + "User-Agent": "deepgram-sdk/7.0.1", "X-Fern-Language": "Python", "X-Fern-Runtime": f"python/{platform.python_version()}", "X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}", "X-Fern-SDK-Name": "deepgram-sdk", - "X-Fern-SDK-Version": "6.1.2", + "X-Fern-SDK-Version": "7.0.1", **(self.get_custom_headers() or {}), } headers["Authorization"] = f"Token {self.api_key}" diff --git a/src/deepgram/core/http_sse/_api.py b/src/deepgram/core/http_sse/_api.py index f900b3b6..b3753991 100644 --- a/src/deepgram/core/http_sse/_api.py +++ b/src/deepgram/core/http_sse/_api.py @@ -1,8 +1,9 @@ # This file was auto-generated by Fern from our API Definition. +import codecs import re from contextlib import asynccontextmanager, contextmanager -from typing import Any, AsyncGenerator, AsyncIterator, Iterator, cast +from typing import Any, AsyncGenerator, AsyncIterator, Iterator import httpx from ._decoders import SSEDecoder @@ -45,46 +46,81 @@ def _get_charset(self) -> str: def response(self) -> httpx.Response: return self._response + @staticmethod + def _normalize_sse_line_endings(buf: str) -> str: + """Normalize line endings per the SSE spec (\\r\\n → \\n, bare \\r → \\n). + + A trailing \\r is preserved because it may pair with a leading \\n in + the next chunk to form a single \\r\\n terminator. + """ + buf = buf.replace("\r\n", "\n") + if buf.endswith("\r"): + return buf[:-1].replace("\r", "\n") + "\r" + return buf.replace("\r", "\n") + def iter_sse(self) -> Iterator[ServerSentEvent]: self._check_content_type() decoder = SSEDecoder() charset = self._get_charset() + text_decoder = codecs.getincrementaldecoder(charset)(errors="replace") - buffer = "" + buf = "" for chunk in self._response.iter_bytes(): - # Decode chunk using detected charset - text_chunk = chunk.decode(charset, errors="replace") - buffer += text_chunk - - # Process complete lines - while "\n" in buffer: - line, buffer = buffer.split("\n", 1) - line = line.rstrip("\r") + buf += text_decoder.decode(chunk) + buf = self._normalize_sse_line_endings(buf) + + while "\n" in buf: + line, buf = buf.split("\n", 1) sse = decoder.decode(line) - # when we reach a "\n\n" => line = '' - # => decoder will attempt to return an SSE Event if sse is not None: yield sse - # Process any remaining data in buffer - if buffer.strip(): - line = buffer.rstrip("\r") + # Flush any remaining bytes from the incremental decoder + buf += text_decoder.decode(b"", final=True) + buf = buf.replace("\r\n", "\n").replace("\r", "\n") + + while "\n" in buf: + line, buf = buf.split("\n", 1) sse = decoder.decode(line) if sse is not None: yield sse + if buf.strip(): + sse = decoder.decode(buf) + if sse is not None: + yield sse + async def aiter_sse(self) -> AsyncGenerator[ServerSentEvent, None]: self._check_content_type() decoder = SSEDecoder() - lines = cast(AsyncGenerator[str, None], self._response.aiter_lines()) - try: - async for line in lines: - line = line.rstrip("\n") + charset = self._get_charset() + text_decoder = codecs.getincrementaldecoder(charset)(errors="replace") + + buf = "" + async for chunk in self._response.aiter_bytes(): + buf += text_decoder.decode(chunk) + buf = self._normalize_sse_line_endings(buf) + + while "\n" in buf: + line, buf = buf.split("\n", 1) sse = decoder.decode(line) if sse is not None: yield sse - finally: - await lines.aclose() + + # Flush any remaining bytes from the incremental decoder + buf += text_decoder.decode(b"", final=True) + buf = buf.replace("\r\n", "\n").replace("\r", "\n") + + while "\n" in buf: + line, buf = buf.split("\n", 1) + sse = decoder.decode(line) + if sse is not None: + yield sse + + if buf.strip(): + sse = decoder.decode(buf) + if sse is not None: + yield sse @contextmanager diff --git a/src/deepgram/listen/v2/client.py b/src/deepgram/listen/v2/client.py index 6b7d03b9..934deb0d 100644 --- a/src/deepgram/listen/v2/client.py +++ b/src/deepgram/listen/v2/client.py @@ -14,6 +14,7 @@ from ...core.serialization import convert_and_respect_annotation_metadata from ...core.websocket_compat import InvalidWebSocketStatus, get_status_code from ...requests.listen_v2keyterm import ListenV2KeytermParams +from ...requests.listen_v2language_hint import ListenV2LanguageHintParams from ...types.listen_v2eager_eot_threshold import ListenV2EagerEotThreshold from ...types.listen_v2encoding import ListenV2Encoding from ...types.listen_v2eot_threshold import ListenV2EotThreshold @@ -57,6 +58,7 @@ def connect( eot_threshold: typing.Optional[ListenV2EotThreshold] = None, eot_timeout_ms: typing.Optional[ListenV2EotTimeoutMs] = None, keyterm: typing.Optional[ListenV2KeytermParams] = None, + language_hint: typing.Optional[ListenV2LanguageHintParams] = None, mip_opt_out: typing.Optional[ListenV2MipOptOut] = None, tag: typing.Optional[ListenV2Tag] = None, authorization: typing.Optional[str] = None, @@ -82,6 +84,8 @@ def connect( keyterm : typing.Optional[ListenV2KeytermParams] + language_hint : typing.Optional[ListenV2LanguageHintParams] + mip_opt_out : typing.Optional[ListenV2MipOptOut] tag : typing.Optional[ListenV2Tag] @@ -116,6 +120,13 @@ def connect( annotation=ListenV2KeytermParams, direction="write", ), + "language_hint": convert_and_respect_annotation_metadata( + object_=convert_and_respect_annotation_metadata( + object_=language_hint, annotation=ListenV2LanguageHintParams, direction="write" + ), + annotation=ListenV2LanguageHintParams, + direction="write", + ), "mip_opt_out": mip_opt_out, "tag": tag, **( @@ -178,6 +189,7 @@ async def connect( eot_threshold: typing.Optional[ListenV2EotThreshold] = None, eot_timeout_ms: typing.Optional[ListenV2EotTimeoutMs] = None, keyterm: typing.Optional[ListenV2KeytermParams] = None, + language_hint: typing.Optional[ListenV2LanguageHintParams] = None, mip_opt_out: typing.Optional[ListenV2MipOptOut] = None, tag: typing.Optional[ListenV2Tag] = None, authorization: typing.Optional[str] = None, @@ -203,6 +215,8 @@ async def connect( keyterm : typing.Optional[ListenV2KeytermParams] + language_hint : typing.Optional[ListenV2LanguageHintParams] + mip_opt_out : typing.Optional[ListenV2MipOptOut] tag : typing.Optional[ListenV2Tag] @@ -237,6 +251,13 @@ async def connect( annotation=ListenV2KeytermParams, direction="write", ), + "language_hint": convert_and_respect_annotation_metadata( + object_=convert_and_respect_annotation_metadata( + object_=language_hint, annotation=ListenV2LanguageHintParams, direction="write" + ), + annotation=ListenV2LanguageHintParams, + direction="write", + ), "mip_opt_out": mip_opt_out, "tag": tag, **( diff --git a/src/deepgram/listen/v2/raw_client.py b/src/deepgram/listen/v2/raw_client.py index 53d2a13a..366feb04 100644 --- a/src/deepgram/listen/v2/raw_client.py +++ b/src/deepgram/listen/v2/raw_client.py @@ -14,6 +14,7 @@ from ...core.serialization import convert_and_respect_annotation_metadata from ...core.websocket_compat import InvalidWebSocketStatus, get_status_code from ...requests.listen_v2keyterm import ListenV2KeytermParams +from ...requests.listen_v2language_hint import ListenV2LanguageHintParams from ...types.listen_v2eager_eot_threshold import ListenV2EagerEotThreshold from ...types.listen_v2encoding import ListenV2Encoding from ...types.listen_v2eot_threshold import ListenV2EotThreshold @@ -45,6 +46,7 @@ def connect( eot_threshold: typing.Optional[ListenV2EotThreshold] = None, eot_timeout_ms: typing.Optional[ListenV2EotTimeoutMs] = None, keyterm: typing.Optional[ListenV2KeytermParams] = None, + language_hint: typing.Optional[ListenV2LanguageHintParams] = None, mip_opt_out: typing.Optional[ListenV2MipOptOut] = None, tag: typing.Optional[ListenV2Tag] = None, authorization: typing.Optional[str] = None, @@ -70,6 +72,8 @@ def connect( keyterm : typing.Optional[ListenV2KeytermParams] + language_hint : typing.Optional[ListenV2LanguageHintParams] + mip_opt_out : typing.Optional[ListenV2MipOptOut] tag : typing.Optional[ListenV2Tag] @@ -104,6 +108,13 @@ def connect( annotation=ListenV2KeytermParams, direction="write", ), + "language_hint": convert_and_respect_annotation_metadata( + object_=convert_and_respect_annotation_metadata( + object_=language_hint, annotation=ListenV2LanguageHintParams, direction="write" + ), + annotation=ListenV2LanguageHintParams, + direction="write", + ), "mip_opt_out": mip_opt_out, "tag": tag, **( @@ -155,6 +166,7 @@ async def connect( eot_threshold: typing.Optional[ListenV2EotThreshold] = None, eot_timeout_ms: typing.Optional[ListenV2EotTimeoutMs] = None, keyterm: typing.Optional[ListenV2KeytermParams] = None, + language_hint: typing.Optional[ListenV2LanguageHintParams] = None, mip_opt_out: typing.Optional[ListenV2MipOptOut] = None, tag: typing.Optional[ListenV2Tag] = None, authorization: typing.Optional[str] = None, @@ -180,6 +192,8 @@ async def connect( keyterm : typing.Optional[ListenV2KeytermParams] + language_hint : typing.Optional[ListenV2LanguageHintParams] + mip_opt_out : typing.Optional[ListenV2MipOptOut] tag : typing.Optional[ListenV2Tag] @@ -214,6 +228,13 @@ async def connect( annotation=ListenV2KeytermParams, direction="write", ), + "language_hint": convert_and_respect_annotation_metadata( + object_=convert_and_respect_annotation_metadata( + object_=language_hint, annotation=ListenV2LanguageHintParams, direction="write" + ), + annotation=ListenV2LanguageHintParams, + direction="write", + ), "mip_opt_out": mip_opt_out, "tag": tag, **( diff --git a/src/deepgram/manage/v1/projects/keys/client.py b/src/deepgram/manage/v1/projects/keys/client.py index 698bf841..0e089c5b 100644 --- a/src/deepgram/manage/v1/projects/keys/client.py +++ b/src/deepgram/manage/v1/projects/keys/client.py @@ -4,7 +4,7 @@ from .....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .....core.request_options import RequestOptions -from .....types.create_key_v1request_one import CreateKeyV1RequestOne +from .....requests.create_key_v1request import CreateKeyV1RequestParams from .....types.create_key_v1response import CreateKeyV1Response from .....types.delete_project_key_v1response import DeleteProjectKeyV1Response from .....types.get_project_key_v1response import GetProjectKeyV1Response @@ -76,7 +76,7 @@ def create( self, project_id: str, *, - request: CreateKeyV1RequestOne, + request: CreateKeyV1RequestParams, request_options: typing.Optional[RequestOptions] = None, ) -> CreateKeyV1Response: """ @@ -87,7 +87,7 @@ def create( project_id : str The unique identifier of the project - request : CreateKeyV1RequestOne + request : CreateKeyV1RequestParams request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -255,7 +255,7 @@ async def create( self, project_id: str, *, - request: CreateKeyV1RequestOne, + request: CreateKeyV1RequestParams, request_options: typing.Optional[RequestOptions] = None, ) -> CreateKeyV1Response: """ @@ -266,7 +266,7 @@ async def create( project_id : str The unique identifier of the project - request : CreateKeyV1RequestOne + request : CreateKeyV1RequestParams request_options : typing.Optional[RequestOptions] Request-specific configuration. diff --git a/src/deepgram/manage/v1/projects/keys/raw_client.py b/src/deepgram/manage/v1/projects/keys/raw_client.py index 05acd81c..2ce690c1 100644 --- a/src/deepgram/manage/v1/projects/keys/raw_client.py +++ b/src/deepgram/manage/v1/projects/keys/raw_client.py @@ -9,9 +9,10 @@ from .....core.jsonable_encoder import encode_path_param from .....core.parse_error import ParsingError from .....core.request_options import RequestOptions +from .....core.serialization import convert_and_respect_annotation_metadata from .....core.unchecked_base_model import construct_type from .....errors.bad_request_error import BadRequestError -from .....types.create_key_v1request_one import CreateKeyV1RequestOne +from .....requests.create_key_v1request import CreateKeyV1RequestParams from .....types.create_key_v1response import CreateKeyV1Response from .....types.delete_project_key_v1response import DeleteProjectKeyV1Response from .....types.get_project_key_v1response import GetProjectKeyV1Response @@ -96,7 +97,7 @@ def create( self, project_id: str, *, - request: CreateKeyV1RequestOne, + request: CreateKeyV1RequestParams, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[CreateKeyV1Response]: """ @@ -107,7 +108,7 @@ def create( project_id : str The unique identifier of the project - request : CreateKeyV1RequestOne + request : CreateKeyV1RequestParams request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -121,7 +122,9 @@ def create( f"v1/projects/{encode_path_param(project_id)}/keys", base_url=self._client_wrapper.get_environment().base, method="POST", - json=request, + json=convert_and_respect_annotation_metadata( + object_=request, annotation=CreateKeyV1RequestParams, direction="write" + ), headers={ "content-type": "application/json", }, @@ -348,7 +351,7 @@ async def create( self, project_id: str, *, - request: CreateKeyV1RequestOne, + request: CreateKeyV1RequestParams, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[CreateKeyV1Response]: """ @@ -359,7 +362,7 @@ async def create( project_id : str The unique identifier of the project - request : CreateKeyV1RequestOne + request : CreateKeyV1RequestParams request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -373,7 +376,9 @@ async def create( f"v1/projects/{encode_path_param(project_id)}/keys", base_url=self._client_wrapper.get_environment().base, method="POST", - json=request, + json=convert_and_respect_annotation_metadata( + object_=request, annotation=CreateKeyV1RequestParams, direction="write" + ), headers={ "content-type": "application/json", }, diff --git a/src/deepgram/requests/__init__.py b/src/deepgram/requests/__init__.py index a2dbf463..78cd5f29 100644 --- a/src/deepgram/requests/__init__.py +++ b/src/deepgram/requests/__init__.py @@ -27,6 +27,8 @@ from .cartesia import CartesiaParams from .cartesia_speak_provider_voice import CartesiaSpeakProviderVoiceParams from .create_agent_configuration_v1response import CreateAgentConfigurationV1ResponseParams + from .create_key_v1request import CreateKeyV1RequestParams + from .create_key_v1request_one import CreateKeyV1RequestOneParams from .create_key_v1response import CreateKeyV1ResponseParams from .create_project_distribution_credentials_v1response import CreateProjectDistributionCredentialsV1ResponseParams from .create_project_distribution_credentials_v1response_distribution_credentials import ( @@ -145,6 +147,7 @@ ListenV1ResponseResultsUtterancesItemWordsItemParams, ) from .listen_v2keyterm import ListenV2KeytermParams + from .listen_v2language_hint import ListenV2LanguageHintParams from .open_ai_speak_provider import OpenAiSpeakProviderParams from .open_ai_think_provider import OpenAiThinkProviderParams from .project_request_response import ProjectRequestResponseParams @@ -234,6 +237,8 @@ "CartesiaParams": ".cartesia", "CartesiaSpeakProviderVoiceParams": ".cartesia_speak_provider_voice", "CreateAgentConfigurationV1ResponseParams": ".create_agent_configuration_v1response", + "CreateKeyV1RequestParams": ".create_key_v1request", + "CreateKeyV1RequestOneParams": ".create_key_v1request_one", "CreateKeyV1ResponseParams": ".create_key_v1response", "CreateProjectDistributionCredentialsV1ResponseDistributionCredentialsParams": ".create_project_distribution_credentials_v1response_distribution_credentials", "CreateProjectDistributionCredentialsV1ResponseMemberParams": ".create_project_distribution_credentials_v1response_member", @@ -318,6 +323,7 @@ "ListenV1ResponseResultsUtterancesItemWordsItemParams": ".listen_v1response_results_utterances_item_words_item", "ListenV1ResponseResultsUtterancesParams": ".listen_v1response_results_utterances", "ListenV2KeytermParams": ".listen_v2keyterm", + "ListenV2LanguageHintParams": ".listen_v2language_hint", "OpenAiSpeakProviderParams": ".open_ai_speak_provider", "OpenAiThinkProviderParams": ".open_ai_think_provider", "ProjectRequestResponseParams": ".project_request_response", @@ -423,6 +429,8 @@ def __dir__(): "CartesiaParams", "CartesiaSpeakProviderVoiceParams", "CreateAgentConfigurationV1ResponseParams", + "CreateKeyV1RequestParams", + "CreateKeyV1RequestOneParams", "CreateKeyV1ResponseParams", "CreateProjectDistributionCredentialsV1ResponseDistributionCredentialsParams", "CreateProjectDistributionCredentialsV1ResponseMemberParams", @@ -507,6 +515,7 @@ def __dir__(): "ListenV1ResponseResultsUtterancesItemWordsItemParams", "ListenV1ResponseResultsUtterancesParams", "ListenV2KeytermParams", + "ListenV2LanguageHintParams", "OpenAiSpeakProviderParams", "OpenAiThinkProviderParams", "ProjectRequestResponseParams", diff --git a/src/deepgram/requests/create_key_v1request.py b/src/deepgram/requests/create_key_v1request.py new file mode 100644 index 00000000..39196158 --- /dev/null +++ b/src/deepgram/requests/create_key_v1request.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +CreateKeyV1RequestParams = typing.Union[typing.Any] diff --git a/src/deepgram/requests/create_key_v1request_one.py b/src/deepgram/requests/create_key_v1request_one.py new file mode 100644 index 00000000..34d149b7 --- /dev/null +++ b/src/deepgram/requests/create_key_v1request_one.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +from .create_key_v1request import CreateKeyV1RequestParams + +CreateKeyV1RequestOneParams = CreateKeyV1RequestParams diff --git a/src/deepgram/requests/listen_v2language_hint.py b/src/deepgram/requests/listen_v2language_hint.py new file mode 100644 index 00000000..be0e1b53 --- /dev/null +++ b/src/deepgram/requests/listen_v2language_hint.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ListenV2LanguageHintParams = typing.Union[str, typing.Sequence[str]] diff --git a/src/deepgram/types/__init__.py b/src/deepgram/types/__init__.py index 44266edb..ce56377d 100644 --- a/src/deepgram/types/__init__.py +++ b/src/deepgram/types/__init__.py @@ -37,6 +37,7 @@ from .cartesia_speak_provider_model_id import CartesiaSpeakProviderModelId from .cartesia_speak_provider_voice import CartesiaSpeakProviderVoice from .create_agent_configuration_v1response import CreateAgentConfigurationV1Response + from .create_key_v1request import CreateKeyV1Request from .create_key_v1request_one import CreateKeyV1RequestOne from .create_key_v1response import CreateKeyV1Response from .create_project_distribution_credentials_v1response import CreateProjectDistributionCredentialsV1Response @@ -194,6 +195,7 @@ from .listen_v2eot_threshold import ListenV2EotThreshold from .listen_v2eot_timeout_ms import ListenV2EotTimeoutMs from .listen_v2keyterm import ListenV2Keyterm + from .listen_v2language_hint import ListenV2LanguageHint from .listen_v2mip_opt_out import ListenV2MipOptOut from .listen_v2model import ListenV2Model from .listen_v2sample_rate import ListenV2SampleRate @@ -304,6 +306,7 @@ "CartesiaSpeakProviderModelId": ".cartesia_speak_provider_model_id", "CartesiaSpeakProviderVoice": ".cartesia_speak_provider_voice", "CreateAgentConfigurationV1Response": ".create_agent_configuration_v1response", + "CreateKeyV1Request": ".create_key_v1request", "CreateKeyV1RequestOne": ".create_key_v1request_one", "CreateKeyV1Response": ".create_key_v1response", "CreateProjectDistributionCredentialsV1Response": ".create_project_distribution_credentials_v1response", @@ -429,6 +432,7 @@ "ListenV2EotThreshold": ".listen_v2eot_threshold", "ListenV2EotTimeoutMs": ".listen_v2eot_timeout_ms", "ListenV2Keyterm": ".listen_v2keyterm", + "ListenV2LanguageHint": ".listen_v2language_hint", "ListenV2MipOptOut": ".listen_v2mip_opt_out", "ListenV2Model": ".listen_v2model", "ListenV2SampleRate": ".listen_v2sample_rate", @@ -557,6 +561,7 @@ def __dir__(): "CartesiaSpeakProviderModelId", "CartesiaSpeakProviderVoice", "CreateAgentConfigurationV1Response", + "CreateKeyV1Request", "CreateKeyV1RequestOne", "CreateKeyV1Response", "CreateProjectDistributionCredentialsV1Response", @@ -682,6 +687,7 @@ def __dir__(): "ListenV2EotThreshold", "ListenV2EotTimeoutMs", "ListenV2Keyterm", + "ListenV2LanguageHint", "ListenV2MipOptOut", "ListenV2Model", "ListenV2SampleRate", diff --git a/src/deepgram/types/create_key_v1request.py b/src/deepgram/types/create_key_v1request.py new file mode 100644 index 00000000..6e566877 --- /dev/null +++ b/src/deepgram/types/create_key_v1request.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +CreateKeyV1Request = typing.Union[typing.Any] diff --git a/src/deepgram/types/create_key_v1request_one.py b/src/deepgram/types/create_key_v1request_one.py index 0a5d546a..827b04dc 100644 --- a/src/deepgram/types/create_key_v1request_one.py +++ b/src/deepgram/types/create_key_v1request_one.py @@ -1,5 +1,5 @@ # This file was auto-generated by Fern from our API Definition. -import typing +from .create_key_v1request import CreateKeyV1Request -CreateKeyV1RequestOne = typing.Any +CreateKeyV1RequestOne = CreateKeyV1Request diff --git a/src/deepgram/types/listen_v2language_hint.py b/src/deepgram/types/listen_v2language_hint.py new file mode 100644 index 00000000..50773afa --- /dev/null +++ b/src/deepgram/types/listen_v2language_hint.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ListenV2LanguageHint = typing.Union[str, typing.List[str]] diff --git a/tests/custom/test_agent_history.py b/tests/custom/test_agent_history.py index d9cac591..01db274b 100644 --- a/tests/custom/test_agent_history.py +++ b/tests/custom/test_agent_history.py @@ -1,5 +1,5 @@ from deepgram.agent.v1.socket_client import V1SocketClientResponse -from deepgram.agent.v1.types import AgentV1HistoryContent, AgentV1HistoryFunctionCalls +from deepgram.agent.v1.types import ConversationHistoryMessage, FunctionCallHistoryMessage from deepgram.core.unchecked_base_model import construct_type @@ -9,7 +9,7 @@ def test_agent_history_content_parses_from_socket_union() -> None: object_={"type": "History", "role": "user", "content": "hello"}, ) - assert isinstance(parsed, AgentV1HistoryContent) + assert isinstance(parsed, ConversationHistoryMessage) assert parsed.type == "History" assert parsed.role == "user" assert parsed.content == "hello" @@ -32,7 +32,7 @@ def test_agent_history_function_calls_parse_from_socket_union() -> None: }, ) - assert isinstance(parsed, AgentV1HistoryFunctionCalls) + assert isinstance(parsed, FunctionCallHistoryMessage) assert parsed.type == "History" assert len(parsed.function_calls) == 1 diff --git a/tests/custom/test_compat_aliases.py b/tests/custom/test_compat_aliases.py new file mode 100644 index 00000000..1e1315f9 --- /dev/null +++ b/tests/custom/test_compat_aliases.py @@ -0,0 +1,145 @@ +from deepgram import CreateKeyV1Request as RootCreateKeyV1Request +from deepgram import CreateKeyV1RequestOne +from deepgram.agent import AgentV1HistoryContent as AgentHistoryContentFromAgent +from deepgram.agent import AgentV1HistoryContentParams as AgentHistoryContentParamsFromAgent +from deepgram.agent import AgentV1HistoryFunctionCalls as AgentHistoryFunctionCallsFromAgent +from deepgram.agent import AgentV1HistoryFunctionCallsParams as AgentHistoryFunctionCallsParamsFromAgent +from deepgram.agent import AgentV1SettingsAgentContextMessagesItemContent as AgentContextContentFromAgent +from deepgram.agent import AgentV1SettingsAgentContextMessagesItemContentParams as AgentContextContentParamsFromAgent +from deepgram.agent import AgentV1SettingsAgentContextMessagesItemFunctionCalls as AgentContextFunctionCallsFromAgent +from deepgram.agent import ( + AgentV1SettingsAgentContextMessagesItemFunctionCallsParams as AgentContextFunctionCallsParamsFromAgent, +) +from deepgram.agent.v1 import AgentV1HistoryContent as AgentHistoryContentFromV1 +from deepgram.agent.v1 import AgentV1HistoryContentParams as AgentHistoryContentParamsFromV1 +from deepgram.agent.v1 import AgentV1HistoryFunctionCalls as AgentHistoryFunctionCallsFromV1 +from deepgram.agent.v1 import AgentV1HistoryFunctionCallsParams as AgentHistoryFunctionCallsParamsFromV1 +from deepgram.agent.v1 import AgentV1SettingsAgentContextMessagesItemContent as AgentContextContentFromV1 +from deepgram.agent.v1 import AgentV1SettingsAgentContextMessagesItemContentParams as AgentContextContentParamsFromV1 +from deepgram.agent.v1 import AgentV1SettingsAgentContextMessagesItemFunctionCalls as AgentContextFunctionCallsFromV1 +from deepgram.agent.v1 import ( + AgentV1SettingsAgentContextMessagesItemFunctionCallsParams as AgentContextFunctionCallsParamsFromV1, +) +from deepgram.agent.v1.requests import ( + AgentV1HistoryContentParams, + AgentV1HistoryFunctionCallsParams, + AgentV1SettingsAgentContextMessagesItemContentParams, + AgentV1SettingsAgentContextMessagesItemFunctionCallsParams, + ConversationHistoryMessageParams, + FunctionCallHistoryMessageParams, +) +from deepgram.agent.v1.requests.agent_v1history_content import AgentV1HistoryContentParams as ModuleHistoryContentParams +from deepgram.agent.v1.requests.agent_v1history_function_calls import ( + AgentV1HistoryFunctionCallsParams as ModuleHistoryFunctionCallsParams, +) +from deepgram.agent.v1.requests.agent_v1settings_agent_context_messages_item_content import ( + AgentV1SettingsAgentContextMessagesItemContentParams as ModuleContextContentParams, +) +from deepgram.agent.v1.requests.agent_v1settings_agent_context_messages_item_function_calls import ( + AgentV1SettingsAgentContextMessagesItemFunctionCallsParams as ModuleContextFunctionCallsParams, +) +from deepgram.agent.v1.types import ( + AgentV1HistoryContent, + AgentV1HistoryFunctionCalls, + AgentV1SettingsAgentContextMessagesItemContent, + AgentV1SettingsAgentContextMessagesItemFunctionCalls, + ConversationHistoryMessage, + FunctionCallHistoryMessage, +) +from deepgram.agent.v1.types.agent_v1history_content import AgentV1HistoryContent as ModuleHistoryContent +from deepgram.agent.v1.types.agent_v1history_function_calls import ( + AgentV1HistoryFunctionCalls as ModuleHistoryFunctionCalls, +) +from deepgram.agent.v1.types.agent_v1settings_agent_context_messages_item_content import ( + AgentV1SettingsAgentContextMessagesItemContent as ModuleContextContent, +) +from deepgram.agent.v1.types.agent_v1settings_agent_context_messages_item_function_calls import ( + AgentV1SettingsAgentContextMessagesItemFunctionCalls as ModuleContextFunctionCalls, +) +from deepgram.requests import CreateKeyV1RequestOneParams, CreateKeyV1RequestParams +from deepgram.requests.create_key_v1request_one import CreateKeyV1RequestOneParams as ModuleCreateKeyV1RequestOneParams +from deepgram.types import CreateKeyV1Request +from deepgram.types import CreateKeyV1RequestOne as CreateKeyV1RequestOneType +from deepgram.types.create_key_v1request_one import CreateKeyV1RequestOne as ModuleCreateKeyV1RequestOne + + +def test_old_agent_history_type_aliases_resolve_to_new_models() -> None: + assert AgentV1HistoryContent is ConversationHistoryMessage + assert ModuleHistoryContent is ConversationHistoryMessage + assert AgentHistoryContentFromV1 is ConversationHistoryMessage + assert AgentHistoryContentFromAgent is ConversationHistoryMessage + + assert AgentV1HistoryFunctionCalls is FunctionCallHistoryMessage + assert ModuleHistoryFunctionCalls is FunctionCallHistoryMessage + assert AgentHistoryFunctionCallsFromV1 is FunctionCallHistoryMessage + assert AgentHistoryFunctionCallsFromAgent is FunctionCallHistoryMessage + + assert AgentV1SettingsAgentContextMessagesItemContent is ConversationHistoryMessage + assert ModuleContextContent is ConversationHistoryMessage + assert AgentContextContentFromV1 is ConversationHistoryMessage + assert AgentContextContentFromAgent is ConversationHistoryMessage + + assert AgentV1SettingsAgentContextMessagesItemFunctionCalls is FunctionCallHistoryMessage + assert ModuleContextFunctionCalls is FunctionCallHistoryMessage + assert AgentContextFunctionCallsFromV1 is FunctionCallHistoryMessage + assert AgentContextFunctionCallsFromAgent is FunctionCallHistoryMessage + + +def test_old_agent_history_request_aliases_resolve_to_new_params() -> None: + assert AgentV1HistoryContentParams is ConversationHistoryMessageParams + assert ModuleHistoryContentParams is ConversationHistoryMessageParams + assert AgentHistoryContentParamsFromV1 is ConversationHistoryMessageParams + assert AgentHistoryContentParamsFromAgent is ConversationHistoryMessageParams + + assert AgentV1HistoryFunctionCallsParams is FunctionCallHistoryMessageParams + assert ModuleHistoryFunctionCallsParams is FunctionCallHistoryMessageParams + assert AgentHistoryFunctionCallsParamsFromV1 is FunctionCallHistoryMessageParams + assert AgentHistoryFunctionCallsParamsFromAgent is FunctionCallHistoryMessageParams + + assert AgentV1SettingsAgentContextMessagesItemContentParams is ConversationHistoryMessageParams + assert ModuleContextContentParams is ConversationHistoryMessageParams + assert AgentContextContentParamsFromV1 is ConversationHistoryMessageParams + assert AgentContextContentParamsFromAgent is ConversationHistoryMessageParams + + assert AgentV1SettingsAgentContextMessagesItemFunctionCallsParams is FunctionCallHistoryMessageParams + assert ModuleContextFunctionCallsParams is FunctionCallHistoryMessageParams + assert AgentContextFunctionCallsParamsFromV1 is FunctionCallHistoryMessageParams + assert AgentContextFunctionCallsParamsFromAgent is FunctionCallHistoryMessageParams + + +def test_old_key_request_aliases_resolve_to_new_request_type() -> None: + assert CreateKeyV1RequestOneType is CreateKeyV1Request + assert ModuleCreateKeyV1RequestOne is CreateKeyV1Request + assert CreateKeyV1RequestOne is RootCreateKeyV1Request + + assert CreateKeyV1RequestOneParams is CreateKeyV1RequestParams + assert ModuleCreateKeyV1RequestOneParams is CreateKeyV1RequestParams + + +def test_old_agent_history_type_aliases_can_be_instantiated() -> None: + history_content = AgentV1HistoryContent(type="History", role="user", content="hello") + assert isinstance(history_content, ConversationHistoryMessage) + assert history_content.role == "user" + assert history_content.content == "hello" + + context_content = AgentV1SettingsAgentContextMessagesItemContent(type="History", role="assistant", content="hi") + assert isinstance(context_content, ConversationHistoryMessage) + assert context_content.role == "assistant" + assert context_content.content == "hi" + + function_call = { + "id": "fc_123", + "name": "lookup_weather", + "client_side": True, + "arguments": '{"city":"London"}', + "response": "sunny", + } + history_function_calls = AgentV1HistoryFunctionCalls(type="History", function_calls=[function_call]) + assert isinstance(history_function_calls, FunctionCallHistoryMessage) + assert history_function_calls.function_calls[0].name == "lookup_weather" + + context_function_calls = AgentV1SettingsAgentContextMessagesItemFunctionCalls( + type="History", function_calls=[function_call] + ) + assert isinstance(context_function_calls, FunctionCallHistoryMessage) + assert context_function_calls.function_calls[0].response == "sunny" diff --git a/tests/typecheck/compat_aliases.py b/tests/typecheck/compat_aliases.py new file mode 100644 index 00000000..a2db4059 --- /dev/null +++ b/tests/typecheck/compat_aliases.py @@ -0,0 +1,32 @@ +from typing import assert_type + +from deepgram.agent.v1.requests import ( + AgentV1HistoryContentParams, + AgentV1HistoryFunctionCallsParams, + ConversationHistoryMessageParams, + FunctionCallHistoryMessageParams, +) +from deepgram.requests import CreateKeyV1RequestOneParams, CreateKeyV1RequestParams + +create_key_request: CreateKeyV1RequestOneParams = {"key": "value"} +history_content: AgentV1HistoryContentParams = { + "type": "History", + "role": "user", + "content": "hello", +} +history_function_calls: AgentV1HistoryFunctionCallsParams = { + "type": "History", + "function_calls": [ + { + "id": "fc_123", + "name": "lookup_weather", + "client_side": True, + "arguments": '{"city":"London"}', + "response": "sunny", + } + ], +} + +assert_type(create_key_request, CreateKeyV1RequestParams) +assert_type(history_content, ConversationHistoryMessageParams) +assert_type(history_function_calls, FunctionCallHistoryMessageParams) diff --git a/tests/wire/test_manage_v1_projects_keys.py b/tests/wire/test_manage_v1_projects_keys.py index 7976bf7d..cf232369 100644 --- a/tests/wire/test_manage_v1_projects_keys.py +++ b/tests/wire/test_manage_v1_projects_keys.py @@ -1,5 +1,7 @@ from .conftest import get_client, verify_request_count +from deepgram.requests import CreateKeyV1RequestOneParams + def test_manage_v1_projects_keys_list_() -> None: """Test list endpoint with WireMock""" @@ -23,6 +25,18 @@ def test_manage_v1_projects_keys_create() -> None: verify_request_count(test_id, "POST", "/v1/projects/project_id/keys", None, 1) +def test_manage_v1_projects_keys_create_with_old_request_alias() -> None: + """Test create endpoint with the legacy request alias""" + test_id = "manage.v1.projects.keys.create.compat" + client = get_client(test_id) + request: CreateKeyV1RequestOneParams = {"key": "value"} + client.manage.v1.projects.keys.create( + project_id="project_id", + request=request, + ) + verify_request_count(test_id, "POST", "/v1/projects/project_id/keys", None, 1) + + def test_manage_v1_projects_keys_get() -> None: """Test get endpoint with WireMock""" test_id = "manage.v1.projects.keys.get.0" diff --git a/tests/wire/test_read_v1_text.py b/tests/wire/test_read_v1_text.py index 88af46fe..9d8decbd 100644 --- a/tests/wire/test_read_v1_text.py +++ b/tests/wire/test_read_v1_text.py @@ -1,7 +1,5 @@ from .conftest import get_client, verify_request_count -from deepgram import ReadV1RequestUrl - def test_read_v1_text_analyze() -> None: """Test analyze endpoint with WireMock""" @@ -20,9 +18,7 @@ def test_read_v1_text_analyze() -> None: custom_intent=["custom_intent"], custom_intent_mode="extended", language="language", - request=ReadV1RequestUrl( - url="url", - ), + request={"url": "url"}, ) verify_request_count( test_id,