@@ -4,6 +4,8 @@ authors: thinkall
4
4
tags : [LLM, RAG]
5
5
---
6
6
7
+ * Last update: April 4, 2024; AutoGen version: v0.2.21*
8
+
7
9
![ RAG Architecture] ( img/retrievechat-arch.png )
8
10
9
11
** TL;DR:**
@@ -57,10 +59,17 @@ pip install "pyautogen[retrievechat]"
57
59
RetrieveChat can handle various types of documents. By default, it can process
58
60
plain text and PDF files, including formats such as 'txt', 'json', 'csv', 'tsv',
59
61
'md', 'html', 'htm', 'rtf', 'rst', 'jsonl', 'log', 'xml', 'yaml', 'yml' and 'pdf'.
60
- If you install [ unstructured] ( https://unstructured-io.github.io/unstructured/installation/full_installation.html )
61
- ( ` pip install "unstructured[all-docs]" ` ), additional document types such as 'docx',
62
+ If you install [ unstructured] ( https://unstructured-io.github.io/unstructured/installation/full_installation.html ) ,
63
+ additional document types such as 'docx',
62
64
'doc', 'odt', 'pptx', 'ppt', 'xlsx', 'eml', 'msg', 'epub' will also be supported.
63
65
66
+ - Install ` unstructured ` in ubuntu
67
+ ``` bash
68
+ sudo apt-get update
69
+ sudo apt-get install -y tesseract-ocr poppler-utils
70
+ pip install unstructured[all-docs]
71
+ ```
72
+
64
73
You can find a list of all supported document types by using ` autogen.retrieve_utils.TEXT_FORMATS ` .
65
74
66
75
1 . Import Agents
@@ -90,7 +99,7 @@ ragproxyagent = RetrieveUserProxyAgent(
90
99
3 . Initialize Chat and ask a question
91
100
``` python
92
101
assistant.reset()
93
- ragproxyagent.initiate_chat(assistant, problem = " What is autogen?" )
102
+ ragproxyagent.initiate_chat(assistant, message = ragproxyagent.message_generator, problem = " What is autogen?" )
94
103
```
95
104
96
105
Output is like:
@@ -283,28 +292,6 @@ However, you may want to initialize the chat with another agent in some cases. T
283
292
you'll need to call it from a function.
284
293
285
294
``` python
286
- llm_config = {
287
- " functions" : [
288
- {
289
- " name" : " retrieve_content" ,
290
- " description" : " retrieve content for code generation and question answering." ,
291
- " parameters" : {
292
- " type" : " object" ,
293
- " properties" : {
294
- " message" : {
295
- " type" : " string" ,
296
- " description" : " Refined message which keeps the original meaning and can be used to retrieve content for code generation and question answering." ,
297
- }
298
- },
299
- " required" : [" message" ],
300
- },
301
- },
302
- ],
303
- " config_list" : config_list,
304
- " timeout" : 60 ,
305
- " seed" : 42 ,
306
- }
307
-
308
295
boss = autogen.UserProxyAgent(
309
296
name = " Boss" ,
310
297
is_termination_msg = termination_msg,
@@ -328,46 +315,58 @@ coder = AssistantAgent(
328
315
name = " Senior_Python_Engineer" ,
329
316
is_termination_msg = termination_msg,
330
317
system_message = " You are a senior python engineer. Reply `TERMINATE` in the end when everything is done." ,
331
- llm_config = llm_config ,
318
+ llm_config = { " config_list " : config_list, " timeout " : 60 , " temperature " : 0 } ,
332
319
)
333
320
334
321
pm = autogen.AssistantAgent(
335
322
name = " Product_Manager" ,
336
323
is_termination_msg = termination_msg,
337
324
system_message = " You are a product manager. Reply `TERMINATE` in the end when everything is done." ,
338
- llm_config = llm_config ,
325
+ llm_config = { " config_list " : config_list, " timeout " : 60 , " temperature " : 0 } ,
339
326
)
340
327
341
328
reviewer = autogen.AssistantAgent(
342
329
name = " Code_Reviewer" ,
343
330
is_termination_msg = termination_msg,
344
331
system_message = " You are a code reviewer. Reply `TERMINATE` in the end when everything is done." ,
345
- llm_config = llm_config ,
332
+ llm_config = { " config_list " : config_list, " timeout " : 60 , " temperature " : 0 } ,
346
333
)
347
334
348
- def retrieve_content (message , n_results = 3 ):
349
- boss_aid.n_results = n_results # Set the number of results to be retrieved.
350
- # Check if we need to update the context.
351
- update_context_case1, update_context_case2 = boss_aid._check_update_context(message)
352
- if (update_context_case1 or update_context_case2) and boss_aid.update_context:
353
- boss_aid.problem = message if not hasattr (boss_aid, " problem" ) else boss_aid.problem
354
- _, ret_msg = boss_aid._generate_retrieve_user_reply(message)
355
- else :
356
- _context = {" problem" : message, " n_results" : n_results}
357
- ret_msg = boss_aid.message_generator(boss_aid, None , _context)
358
- return ret_msg if ret_msg else message
359
-
360
- for agent in [boss, coder, pm, reviewer]:
361
- # register functions for all agents.
362
- agent.register_function(
363
- function_map = {
364
- " retrieve_content" : retrieve_content,
365
- }
366
- )
335
+ def retrieve_content (
336
+ message : Annotated[
337
+ str ,
338
+ " Refined message which keeps the original meaning and can be used to retrieve content for code generation and question answering." ,
339
+ ],
340
+ n_results : Annotated[int , " number of results" ] = 3 ,
341
+ ) -> str :
342
+ boss_aid.n_results = n_results # Set the number of results to be retrieved.
343
+ # Check if we need to update the context.
344
+ update_context_case1, update_context_case2 = boss_aid._check_update_context(message)
345
+ if (update_context_case1 or update_context_case2) and boss_aid.update_context:
346
+ boss_aid.problem = message if not hasattr (boss_aid, " problem" ) else boss_aid.problem
347
+ _, ret_msg = boss_aid._generate_retrieve_user_reply(message)
348
+ else :
349
+ _context = {" problem" : message, " n_results" : n_results}
350
+ ret_msg = boss_aid.message_generator(boss_aid, None , _context)
351
+ return ret_msg if ret_msg else message
352
+
353
+ for caller in [pm, coder, reviewer]:
354
+ d_retrieve_content = caller.register_for_llm(
355
+ description = " retrieve content for code generation and question answering." , api_style = " function"
356
+ )(retrieve_content)
357
+
358
+ for executor in [boss, pm]:
359
+ executor.register_for_execution()(d_retrieve_content)
367
360
368
361
groupchat = autogen.GroupChat(
369
- agents = [boss, coder, pm, reviewer], messages = [], max_round = 12
362
+ agents = [boss, pm, coder, reviewer],
363
+ messages = [],
364
+ max_round = 12 ,
365
+ speaker_selection_method = " round_robin" ,
366
+ allow_repeat_speaker = False ,
370
367
)
368
+
369
+ llm_config = {" config_list" : config_list, " timeout" : 60 , " temperature" : 0 }
371
370
manager = autogen.GroupChatManager(groupchat = groupchat, llm_config = llm_config)
372
371
373
372
# Start chatting with the boss as this is the user proxy agent.
0 commit comments