Skip to content

Commit

Permalink
reverts FunctionCallingMessage to FunctionCalling
Browse files Browse the repository at this point in the history
  • Loading branch information
jpvajda committed Jan 27, 2025
1 parent 764c249 commit c64c37d
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down
2 changes: 1 addition & 1 deletion deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down
4 changes: 2 additions & 2 deletions deepgram/clients/agent/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ConversationTextResponse as LatestConversationTextResponse,
UserStartedSpeakingResponse as LatestUserStartedSpeakingResponse,
AgentThinkingResponse as LatestAgentThinkingResponse,
FunctionCallingMessage as LatestFunctionCallingMessage,
FunctionCalling as LatestFunctionCalling,
FunctionCallRequest as LatestFunctionCallRequest,
AgentStartedSpeakingResponse as LatestAgentStartedSpeakingResponse,
AgentAudioDoneResponse as LatestAgentAudioDoneResponse,
Expand Down Expand Up @@ -69,7 +69,7 @@
ConversationTextResponse = LatestConversationTextResponse
UserStartedSpeakingResponse = LatestUserStartedSpeakingResponse
AgentThinkingResponse = LatestAgentThinkingResponse
FunctionCallingMessage = LatestFunctionCallingMessage
FunctionCalling = LatestFunctionCalling
FunctionCallRequest = LatestFunctionCallRequest
AgentStartedSpeakingResponse = LatestAgentStartedSpeakingResponse
AgentAudioDoneResponse = LatestAgentAudioDoneResponse
Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/agent/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AgentWebSocketEvents(StrEnum):
ConversationText: str = "ConversationText"
UserStartedSpeaking: str = "UserStartedSpeaking"
AgentThinking: str = "AgentThinking"
FunctionCallingMessage: str = "FunctionCallingMessage"
FunctionCalling: str = "FunctionCalling"
FunctionCallRequest: str = "FunctionCallRequest"
AgentStartedSpeaking: str = "AgentStartedSpeaking"
AgentAudioDone: str = "AgentAudioDone"
Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/agent/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/agent/v1/websocket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down
8 changes: 4 additions & 4 deletions deepgram/clients/agent/v1/websocket/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down Expand Up @@ -429,11 +429,11 @@ async def _process_text(self, message: str) -> None:
**dict(cast(Dict[Any, Any], self._kwargs)),
)
case AgentWebSocketEvents.FunctionCalling:
function_calling_result: FunctionCallingMessage = (
FunctionCallingMessage.from_json(message)
function_calling_result: FunctionCalling = (
FunctionCalling.from_json(message)
)
self._logger.verbose(
"FunctionCallingMessage: %s", function_calling_result
"FunctionCalling: %s", function_calling_result
)
await self._emit(
AgentWebSocketEvents(AgentWebSocketEvents.FunctionCalling),
Expand Down
8 changes: 4 additions & 4 deletions deepgram/clients/agent/v1/websocket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ConversationTextResponse,
UserStartedSpeakingResponse,
AgentThinkingResponse,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
AgentStartedSpeakingResponse,
AgentAudioDoneResponse,
Expand Down Expand Up @@ -424,11 +424,11 @@ def _process_text(self, message: str) -> None:
**dict(cast(Dict[Any, Any], self._kwargs)),
)
case AgentWebSocketEvents.FunctionCalling:
function_calling_result: FunctionCallingMessage = (
FunctionCallingMessage.from_json(message)
function_calling_result: FunctionCalling = (
FunctionCalling.from_json(message)
)
self._logger.verbose(
"FunctionCallingMessage: %s", function_calling_result
"FunctionCalling: %s", function_calling_result
)
self._emit(
AgentWebSocketEvents(AgentWebSocketEvents.FunctionCalling),
Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/agent/v1/websocket/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AgentThinkingResponse(BaseResponse):


@dataclass
class FunctionCallingMessage(BaseResponse):
class FunctionCalling(BaseResponse):
"""
The server will sometimes send FunctionCalling messages when making function calls to help the client developer debug function calling workflows.
"""
Expand Down
54 changes: 39 additions & 15 deletions examples/agent/simple/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@
DeepgramClientOptions,
AgentWebSocketEvents,
SettingsConfigurationOptions,
FunctionCallingMessage,
FunctionCalling,
FunctionCallRequest,
FunctionCallResponse,
)

# Add debug prints for imports
print("Checking imports...")
try:
from deepgram import FunctionCallRequest
print("Successfully imported FunctionCallRequest")
except ImportError as e:
print(f"Failed to import FunctionCallRequest: {e}")

try:
from deepgram import FunctionCallResponse
print("Successfully imported FunctionCallResponse")
except ImportError as e:
print(f"Failed to import FunctionCallResponse: {e}")

TTS_TEXT = "Hello, this is a text to speech example using Deepgram."

global warning_notice
Expand All @@ -21,7 +36,7 @@

def main():
try:
# example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM
print("Starting main function...")
config: DeepgramClientOptions = DeepgramClientOptions(
options={
"keepalive": "true",
Expand All @@ -30,10 +45,13 @@ def main():
},
# verbose=verboselogs.DEBUG,
)
print("Created DeepgramClientOptions...")

deepgram: DeepgramClient = DeepgramClient("", config)
print("Created DeepgramClient...")

# Create a websocket connection to Deepgram
dg_connection = deepgram.agent.websocket.v("1")
print("Created WebSocket connection...")

def on_open(self, open, **kwargs):
print(f"\n\n{open}\n\n")
Expand Down Expand Up @@ -64,17 +82,19 @@ def on_user_started_speaking(self, user_started_speaking, **kwargs):
def on_agent_thinking(self, agent_thinking, **kwargs):
print(f"\n\n{agent_thinking}\n\n")

def on_function_calling(self, function_calling: FunctionCallingMessage, **kwargs):
print(f"\n\nFunction Calling Message: {function_calling}\n\n")
def on_function_calling(self, function_calling: FunctionCalling, **kwargs):
print(f"\n\nFunction Calling Debug: {function_calling}\n\n")

def on_function_call_request(self, function_call_request, **kwargs):
def on_function_call_request(self, function_call_request: FunctionCallRequest, **kwargs):
print(f"\n\nFunction Call Request: {function_call_request}\n\n")
# Send a response back
response = FunctionCallResponse(
function_call_id=function_call_request.function_call_id,
output="Function response here"
)
dg_connection.send_function_call_response(response)
try:
response = FunctionCallResponse(
function_call_id=function_call_request.function_call_id,
output="Function response here"
)
dg_connection.send_function_call_response(response)
except Exception as e:
print(f"Error in function call: {e}")

def on_agent_started_speaking(self, agent_started_speaking, **kwargs):
print(f"\n\n{agent_started_speaking}\n\n")
Expand Down Expand Up @@ -132,10 +152,14 @@ def on_unhandled(self, unhandled, **kwargs):

print("Finished")

except ValueError as e:
print(f"Invalid value encountered: {e}")
except ImportError as e:
print(f"Import Error Details: {e}")
print(f"Error occurred in module: {getattr(e, 'name', 'unknown')}")
print(f"Path that failed: {getattr(e, 'path', 'unknown')}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
print(f"Unexpected error type: {type(e)}")
print(f"Error message: {str(e)}")
print(f"Error occurred in: {__file__}")


if __name__ == "__main__":
Expand Down

0 comments on commit c64c37d

Please sign in to comment.