Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
from typing import List, Dict,
|
|
|
|
|
|
|
3 |
|
4 |
# Azure AI Agents SDK (API key auth)
|
5 |
from azure.core.credentials import AzureKeyCredential
|
@@ -11,16 +14,36 @@ from azure.ai.agents.models import (
|
|
11 |
MessageRole,
|
12 |
)
|
13 |
|
14 |
-
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# ---------- Core Agent Helpers ----------
|
18 |
|
19 |
-
def init_agent(
|
20 |
-
endpoint: str,
|
21 |
-
api_key: str,
|
22 |
-
model_deployment: str,
|
23 |
-
) -> dict:
|
24 |
"""
|
25 |
Initialize an Azure AI Agent with a custom FunctionTool.
|
26 |
Returns a session dict containing client, agent_id, thread_id, etc.
|
@@ -37,7 +60,6 @@ def init_agent(
|
|
37 |
functions_tool = FunctionTool(user_functions)
|
38 |
toolset = ToolSet()
|
39 |
toolset.add(functions_tool)
|
40 |
-
|
41 |
client.enable_auto_function_calls(toolset)
|
42 |
|
43 |
# Create the agent
|
|
|
1 |
import gradio as gr
|
2 |
+
from typing import List, Dict, Set, Callable, Any
|
3 |
+
import json
|
4 |
+
import uuid
|
5 |
+
from pathlib import Path
|
6 |
|
7 |
# Azure AI Agents SDK (API key auth)
|
8 |
from azure.core.credentials import AzureKeyCredential
|
|
|
14 |
MessageRole,
|
15 |
)
|
16 |
|
17 |
+
# ---------- Inline custom function(s) so no separate user_functions.py is needed ----------
|
18 |
|
19 |
+
def submit_support_ticket(email_address: str, description: str) -> str:
|
20 |
+
"""
|
21 |
+
Generates a ticket number and saves a support ticket as a text file
|
22 |
+
in the current app directory. Returns a small JSON message string.
|
23 |
+
"""
|
24 |
+
script_dir = Path(__file__).parent
|
25 |
+
ticket_number = str(uuid.uuid4()).replace("-", "")[:6]
|
26 |
+
file_name = f"ticket-{ticket_number}.txt"
|
27 |
+
file_path = script_dir / file_name
|
28 |
+
|
29 |
+
text = (
|
30 |
+
f"Support ticket: {ticket_number}\n"
|
31 |
+
f"Submitted by: {email_address}\n"
|
32 |
+
f"Description:\n{description}\n"
|
33 |
+
)
|
34 |
+
file_path.write_text(text, encoding="utf-8")
|
35 |
+
|
36 |
+
message_json = json.dumps({
|
37 |
+
"message": f"Support ticket {ticket_number} submitted. The ticket file is saved as {file_name}"
|
38 |
+
})
|
39 |
+
return message_json
|
40 |
+
|
41 |
+
# Define the callable tool set
|
42 |
+
user_functions: Set[Callable[..., Any]] = { submit_support_ticket }
|
43 |
|
44 |
# ---------- Core Agent Helpers ----------
|
45 |
|
46 |
+
def init_agent(endpoint: str, api_key: str, model_deployment: str) -> dict:
|
|
|
|
|
|
|
|
|
47 |
"""
|
48 |
Initialize an Azure AI Agent with a custom FunctionTool.
|
49 |
Returns a session dict containing client, agent_id, thread_id, etc.
|
|
|
60 |
functions_tool = FunctionTool(user_functions)
|
61 |
toolset = ToolSet()
|
62 |
toolset.add(functions_tool)
|
|
|
63 |
client.enable_auto_function_calls(toolset)
|
64 |
|
65 |
# Create the agent
|