|
6 | 6 | import os
|
7 | 7 | from dotenv import load_dotenv
|
8 | 8 | from azure.identity import DefaultAzureCredential as SyncDefaultAzureCredential
|
9 |
| -from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatPromptExecutionSettings |
| 9 | +from semantic_kernel.connectors.ai.open_ai import ( |
| 10 | + AzureChatCompletion, |
| 11 | + OpenAIChatPromptExecutionSettings, |
| 12 | +) |
10 | 13 |
|
11 | 14 | # Load environment variables
|
12 | 15 | load_dotenv()
|
13 | 16 |
|
14 | 17 | # Azure configuration
|
15 |
| -TENANT_ID = "52b39610-0746-4c25-a83d-d4f89fadedfe" |
16 |
| -CLIENT_ID = "7a95e70b-062e-4cd3-a88c-603fc70e1c73" |
| 18 | +TENANT_ID = "" |
| 19 | +CLIENT_ID = "" |
| 20 | + |
17 | 21 |
|
18 | 22 | class AzureConfig:
|
19 | 23 | """Azure OpenAI and authentication configuration."""
|
20 |
| - |
| 24 | + |
21 | 25 | def __init__(self):
|
22 | 26 | self.endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
|
23 | 27 | self.reasoning_model = os.getenv("REASONING_MODEL_NAME", "o3")
|
24 | 28 | self.standard_model = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4")
|
25 | 29 | self.bing_connection_name = os.getenv("BING_CONNECTION_NAME")
|
26 |
| - |
| 30 | + |
27 | 31 | # Create credential
|
28 | 32 | self.credential = SyncDefaultAzureCredential()
|
29 |
| - |
| 33 | + |
30 | 34 | def get_azure_token(self):
|
31 | 35 | """Get Azure token for authentication."""
|
32 |
| - token = self.credential.get_token("https://cognitiveservices.azure.com/.default") |
| 36 | + token = self.credential.get_token( |
| 37 | + "https://cognitiveservices.azure.com/.default" |
| 38 | + ) |
33 | 39 | return token.token
|
34 |
| - |
| 40 | + |
35 | 41 | def create_chat_completion_service(self, use_reasoning_model=False):
|
36 | 42 | """Create Azure Chat Completion service."""
|
37 |
| - model_name = self.reasoning_model if use_reasoning_model else self.standard_model |
38 |
| - |
| 43 | + model_name = ( |
| 44 | + self.reasoning_model if use_reasoning_model else self.standard_model |
| 45 | + ) |
| 46 | + |
39 | 47 | return AzureChatCompletion(
|
40 | 48 | deployment_name=model_name,
|
41 | 49 | endpoint=self.endpoint,
|
42 |
| - ad_token_provider=self.get_azure_token |
| 50 | + ad_token_provider=self.get_azure_token, |
43 | 51 | )
|
44 |
| - |
| 52 | + |
45 | 53 | def create_execution_settings(self):
|
46 | 54 | """Create execution settings for OpenAI."""
|
47 |
| - return OpenAIChatPromptExecutionSettings( |
48 |
| - max_tokens=4000, |
49 |
| - temperature=0.1 |
50 |
| - ) |
| 55 | + return OpenAIChatPromptExecutionSettings(max_tokens=4000, temperature=0.1) |
| 56 | + |
51 | 57 |
|
52 | 58 | class MCPConfig:
|
53 | 59 | """MCP server configuration."""
|
54 |
| - |
| 60 | + |
55 | 61 | def __init__(self):
|
56 | 62 | self.url = "http://127.0.0.1:8000/mcp/"
|
57 | 63 | self.name = "MCPGreetingServer"
|
58 | 64 | self.description = "MCP server with greeting and planning tools"
|
59 |
| - |
| 65 | + |
60 | 66 | def get_headers(self, token):
|
61 | 67 | """Get MCP headers with authentication token."""
|
62 |
| - return { |
63 |
| - "Authorization": f"Bearer {token}", |
64 |
| - "Content-Type": "application/json" |
65 |
| - } if token else {} |
| 68 | + return ( |
| 69 | + {"Authorization": f"Bearer {token}", "Content-Type": "application/json"} |
| 70 | + if token |
| 71 | + else {} |
| 72 | + ) |
| 73 | + |
66 | 74 |
|
67 | 75 | # Global config instances
|
68 | 76 | azure_config = AzureConfig()
|
|
0 commit comments