-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aee22d
commit 9f9f2ad
Showing
4 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
from typing import Any | ||
from realtime_agent.tools import ToolContext | ||
|
||
# Function calling Example | ||
# This is an example of how to add a new function to the agent tools. | ||
|
||
class AgentTools(ToolContext): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
# create multiple functions here as per requirement | ||
self.register_function( | ||
name="get_avg_temp", | ||
description="Returns average temperature of a country", | ||
parameters={ | ||
"type": "object", | ||
"properties": { | ||
"country": { | ||
"type": "string", | ||
"description": "Name of country", | ||
}, | ||
}, | ||
"required": ["country"], | ||
}, | ||
fn=self._get_avg_temperature_by_country_name, | ||
) | ||
|
||
async def _get_avg_temperature_by_country_name( | ||
self, | ||
country: str, | ||
) -> dict[str, Any]: | ||
try: | ||
result = "24 degree C" # Dummy data (Get the Required value here, like a DB call or API call) | ||
return { | ||
"status": "success", | ||
"message": f"Average temperature of {country} is {result}", | ||
"result": result, | ||
} | ||
except Exception as e: | ||
return { | ||
"status": "error", | ||
"message": f"Failed to get : {str(e)}", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters