Skip to content

Commit d3ddb40

Browse files
authored
Add missing code to samples\agents_tools\sample_agents_auto_function_call.py to set sys.path (#42856)
1 parent 7721eed commit d3ddb40

9 files changed

+46
-34
lines changed

sdk/ai/azure-ai-agents/samples/agents_async/utils/user_async_functions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from azure.ai.agents.telemetry import trace_function
1414

1515

16-
# Add parent directory to sys.path to import user_functions
16+
# Add package directory to sys.path to import user_functions
1717
current_dir = os.path.dirname(os.path.abspath(__file__))
18-
parent_dir = os.path.abspath(os.path.join(current_dir, "..", "..", ".."))
19-
if parent_dir not in sys.path:
20-
sys.path.insert(0, parent_dir)
21-
from samples.utils.user_functions import fetch_current_datetime, fetch_weather, send_email
18+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir, os.pardir))
19+
if package_dir not in sys.path:
20+
sys.path.insert(0, package_dir)
21+
from samples.utils.user_functions import fetch_weather, send_email
2222

2323

2424
async def send_email_async(recipient: str, subject: str, body: str) -> str:

sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
)
4141
from azure.identity import DefaultAzureCredential
4242

43-
current_path = os.path.dirname(__file__)
44-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
45-
if root_path not in sys.path:
46-
sys.path.insert(0, root_path)
43+
# Add package directory to sys.path to import user_functions
44+
current_dir = os.path.dirname(os.path.abspath(__file__))
45+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
46+
if package_dir not in sys.path:
47+
sys.path.insert(0, package_dir)
4748
from samples.utils.user_functions import user_functions
4849

4950
project_client = AIProjectClient(

sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_toolset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
import os, sys
3939
from typing import Any
4040

41-
current_path = os.path.dirname(__file__)
42-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
43-
if root_path not in sys.path:
44-
sys.path.insert(0, root_path)
41+
# Add package directory to sys.path to import user_functions
42+
current_dir = os.path.dirname(os.path.abspath(__file__))
43+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
44+
if package_dir not in sys.path:
45+
sys.path.insert(0, package_dir)
4546
from samples.utils.user_functions import user_functions
4647

4748
project_client = AIProjectClient(

sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141
)
4242
from azure.identity import DefaultAzureCredential
4343

44-
current_path = os.path.dirname(__file__)
45-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
46-
if root_path not in sys.path:
47-
sys.path.insert(0, root_path)
44+
# Add package directory to sys.path to import user_functions
45+
current_dir = os.path.dirname(os.path.abspath(__file__))
46+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
47+
if package_dir not in sys.path:
48+
sys.path.insert(0, package_dir)
4849
from samples.utils.user_functions import user_functions
4950

5051
project_client = AIProjectClient(

sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_toolset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
from azure.ai.agents.models import FunctionTool, ToolSet
3636
from azure.identity import DefaultAzureCredential
3737

38-
current_path = os.path.dirname(__file__)
39-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
40-
if root_path not in sys.path:
41-
sys.path.insert(0, root_path)
38+
# Add package directory to sys.path to import user_functions
39+
current_dir = os.path.dirname(os.path.abspath(__file__))
40+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
41+
if package_dir not in sys.path:
42+
sys.path.insert(0, package_dir)
4243
from samples.utils.user_functions import user_functions
4344

4445
project_client = AIProjectClient(

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_auto_function_call.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
from azure.ai.projects import AIProjectClient
2828
from azure.identity import DefaultAzureCredential
2929
from azure.ai.agents.models import FunctionTool
30+
31+
# Add package directory to sys.path to import user_functions
32+
current_dir = os.path.dirname(os.path.abspath(__file__))
33+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
34+
if package_dir not in sys.path:
35+
sys.path.insert(0, package_dir)
3036
from samples.utils.user_functions import user_functions
3137

3238
project_client = AIProjectClient(

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
ToolOutput,
3333
)
3434

35-
current_path = os.path.dirname(__file__)
36-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
37-
if root_path not in sys.path:
38-
sys.path.insert(0, root_path)
35+
# Add package directory to sys.path to import user_functions
36+
current_dir = os.path.dirname(os.path.abspath(__file__))
37+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
38+
if package_dir not in sys.path:
39+
sys.path.insert(0, package_dir)
3940
from samples.utils.user_functions import user_functions
4041

4142
project_client = AIProjectClient(

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_logic_apps.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
from azure.ai.agents.models import ToolSet, FunctionTool
4545
from azure.identity import DefaultAzureCredential
4646

47-
# Example user function
48-
current_path = os.path.dirname(__file__)
49-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
50-
if root_path not in sys.path:
51-
sys.path.insert(0, root_path)
47+
# Add package directory to sys.path to import user_functions
48+
current_dir = os.path.dirname(os.path.abspath(__file__))
49+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
50+
if package_dir not in sys.path:
51+
sys.path.insert(0, package_dir)
5252
from samples.utils.user_functions import fetch_current_datetime
5353

5454
# Import AzureLogicAppTool and the function factory from user_logic_apps

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_run_with_toolset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
from azure.identity import DefaultAzureCredential
2828
from azure.ai.agents.models import FunctionTool, ToolSet, CodeInterpreterTool
2929

30-
current_path = os.path.dirname(__file__)
31-
root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir))
32-
if root_path not in sys.path:
33-
sys.path.insert(0, root_path)
30+
# Add package directory to sys.path to import user_functions
31+
current_dir = os.path.dirname(os.path.abspath(__file__))
32+
package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir))
33+
if package_dir not in sys.path:
34+
sys.path.insert(0, package_dir)
3435
from samples.utils.user_functions import user_functions
3536

3637
project_client = AIProjectClient(

0 commit comments

Comments
 (0)