1
+ import argparse
1
2
import asyncio
3
+ import json
4
+ import logging
5
+ from typing import Any , Dict
2
6
from autogen_agentchat .messages import TextMessage
3
- from autogen_ext .models .openai import AzureOpenAIChatCompletionClient
4
7
from autogen_ext .tools .graphrag import (
5
8
GlobalSearchTool ,
6
9
LocalSearchTool ,
7
10
)
8
- from azure .identity import DefaultAzureCredential , get_bearer_token_provider
9
11
from autogen_agentchat .agents import AssistantAgent
10
12
from autogen_agentchat .conditions import TextMentionTermination , MaxMessageTermination
11
13
from autogen_agentchat .teams import RoundRobinGroupChat
14
+ from autogen_core .models import ChatCompletionClient
12
15
13
16
14
- async def main ():
15
- # Initialize the OpenAI client
16
- openai_client = AzureOpenAIChatCompletionClient (
17
- model = "gpt-4o-mini" ,
18
- azure_endpoint = "https://<resource-name>.openai.azure.com" ,
19
- azure_deployment = "gpt-4o-mini" ,
20
- api_version = "2024-08-01-preview" ,
21
- azure_ad_token_provider = get_bearer_token_provider (DefaultAzureCredential (), "https://cognitiveservices.azure.com/.default" )
22
- )
17
+ async def main (model_config : Dict [str , Any ]) -> None :
18
+ # Initialize the model client from config
19
+ model_client = ChatCompletionClient .load_component (model_config )
23
20
24
21
# Set up global search tool
25
22
global_tool = GlobalSearchTool .from_settings (
26
23
settings_path = "./settings.yaml"
27
24
)
28
25
29
-
30
26
local_tool = LocalSearchTool .from_settings (
31
27
settings_path = "./settings.yaml"
32
28
)
@@ -35,7 +31,7 @@ async def main():
35
31
assistant_agent = AssistantAgent (
36
32
name = "search_assistant" ,
37
33
tools = [global_tool , local_tool ],
38
- model_client = openai_client ,
34
+ model_client = model_client ,
39
35
system_message = (
40
36
"You are a tool selector AI assistant using the GraphRAG framework. "
41
37
"Your primary task is to determine the appropriate search tool to call based on the user's query. "
@@ -63,5 +59,18 @@ async def main():
63
59
64
60
65
61
if __name__ == "__main__" :
66
- asyncio .run (main ())
62
+ parser = argparse .ArgumentParser (description = "Run a GraphRAG search with an agent." )
63
+ parser .add_argument ("--verbose" , action = "store_true" , help = "Enable verbose logging." )
64
+ parser .add_argument (
65
+ "--model-config" , type = str , help = "Path to the model configuration file." , default = "model_config.json"
66
+ )
67
+ args = parser .parse_args ()
68
+ if args .verbose :
69
+ logging .basicConfig (level = logging .WARNING )
70
+ logging .getLogger ("autogen_core" ).setLevel (logging .DEBUG )
71
+ handler = logging .FileHandler ("graphrag_search.log" )
72
+ logging .getLogger ("autogen_core" ).addHandler (handler )
67
73
74
+ with open (args .model_config , "r" ) as f :
75
+ model_config = json .load (f )
76
+ asyncio .run (main (model_config ))
0 commit comments