Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update on rag #190

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d4731d0
new testing code
FredericW Apr 11, 2024
9b4b060
test the idea that using two agents to analyze different aspects of c…
FredericW Apr 11, 2024
7551c2f
handle irrelevant question and simplify the setting first
ZiTao-Li Apr 15, 2024
86fac88
fix dir
ZiTao-Li Apr 15, 2024
0687138
function added for persisting the index.
FredericW Apr 16, 2024
c598310
Merge pull request #1 from FredericW/testing
FredericW Apr 16, 2024
ddddbe4
Merge branch 'modelscope:main' into main
FredericW Apr 16, 2024
2b1617b
json files are deleted.
FredericW Apr 16, 2024
8afab8f
Merge branch 'modelscope:main' into main
FredericW Apr 16, 2024
6c11924
Merge branch 'modelscope:main' into testing
FredericW Apr 16, 2024
dc5b3e5
Merge branch 'main' into testing
FredericW Apr 16, 2024
fc9066c
Merge pull request #2 from FredericW/testing
FredericW Apr 16, 2024
8daaf4b
Delete rag_storage directory
FredericW Apr 16, 2024
47a9e22
Merge pull request #3 from FredericW/main
ZiTao-Li Apr 16, 2024
a890ac1
merge
ZiTao-Li Apr 16, 2024
702c5c0
add mention function
ZiTao-Li Apr 16, 2024
1e4b4c5
add ui
ZiTao-Li Apr 16, 2024
70bb7bb
fix bugs
ZiTao-Li Apr 16, 2024
484fb4d
runnable ui with flask
ZiTao-Li Apr 18, 2024
99d5a73
The agent dialog flow is modified. We remove the summary agent, and a…
Apr 18, 2024
b3011b1
add docstring agent
ZiTao-Li Apr 18, 2024
449c4dc
update info
ZiTao-Li Apr 18, 2024
e55be4a
Changes are made to improve the performance
Apr 19, 2024
133dbc9
Changes are made to improve the performance
Apr 19, 2024
0fc5e16
Merge pull request #1 from ZiTao-Li/zitao/dev_copilot
ZiTao-Li Apr 19, 2024
5d6c0fe
config modified
Apr 19, 2024
dd0d328
Merge pull request #5 from FredericW/dev_copilot_zitao
ZiTao-Li Apr 19, 2024
3d80561
Merge branch 'main' into zitao/dev_copilot
ZiTao-Li Apr 19, 2024
ccc5b46
add file
ZiTao-Li Apr 19, 2024
ec3d8c0
add api assistant
ZiTao-Li Apr 19, 2024
3007809
New feature added: now we allow user to load and index multiple files…
Apr 22, 2024
d7ae87c
Changes made: To reorganize the work flow, we made the following chan…
Apr 25, 2024
1f37b96
Changes made: the major components of init_rag is now moved to rag_ag…
Apr 25, 2024
a55eaf0
Merge pull request #6 from FredericW/dev/as_copilot
ZiTao-Li Apr 26, 2024
85401a8
Changes made: refactor the load_data method in LlamaIndexRAG, now the…
Apr 26, 2024
b8c6eac
Changes made: new method load_index for load stored index from persis…
Apr 26, 2024
06d9ebb
reformat code
ZiTao-Li Apr 26, 2024
2ab69fa
Merge branch 'main' into zitao/dev_copilot
ZiTao-Li Apr 26, 2024
f9f912c
Merge branch 'main' into zitao/dev_copilot
ZiTao-Li Apr 28, 2024
986e1b6
fix merge
ZiTao-Li Apr 28, 2024
fc91107
fix
ZiTao-Li Apr 28, 2024
df7a79e
Merge branch 'main' into dev/as_copilot
ZiTao-Li Apr 28, 2024
82eff0c
Merge branch 'dev/as_copilot' into zitao/dev_copilot
ZiTao-Li Apr 28, 2024
32adc04
Merge pull request #7 from ZiTao-Li/zitao/dev_copilot
ZiTao-Li Apr 28, 2024
3dc828e
fix langchain_rag.py
ZiTao-Li Apr 28, 2024
130c235
Merge pull request #8 from ZiTao-Li/zitao/dev_copilot
ZiTao-Li Apr 28, 2024
a414a7c
Merge branch 'modelscope:main' into dev/as_copilot_index_manage
FredericW Apr 28, 2024
d41b3f8
Changes made: new method refresh_index, _insert_docs_to_index, and _d…
Apr 29, 2024
f533612
Quick fix: re-enable modules in rag_example.py
Apr 29, 2024
e89591c
Merge branch 'main' into dev/as_copilot
ZiTao-Li Apr 29, 2024
421e021
Merge branch 'modelscope:main' into dev/as_copilot_index_manage
FredericW Apr 29, 2024
c9902a5
sync with dev/as_copilot
Apr 29, 2024
07480d5
comments and docstrings are updated.
Apr 29, 2024
1640146
comments and docstrings are updated.
Apr 29, 2024
0895b10
Merge pull request #10 from FredericW/dev/as_copilot_index_manage
ZiTao-Li Apr 29, 2024
3ee3266
add knowledge bank
ZiTao-Li Apr 29, 2024
83f5aec
fix configs, add docstring, modify names
ZiTao-Li Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/conversation_with_RAG_agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ capability can be used to build easily.
* **Cloning repo:** This example requires cloning the whole AgentScope repo to local.
* **Packages:** This example is built on the LlamaIndex package. Thus, some packages need to be installed before running the example.
```bash
pip install llama-index tree_sitter tree-sitter-languages
pip install llama-index llama-index-readers-docstring-walker tree_sitter tree-sitter-languages
```
* **Model APIs:** This example uses Dashscope APIs. Thus, we also need an API key for DashScope.
```bash
Expand Down
79 changes: 0 additions & 79 deletions examples/conversation_with_RAG_agents/agent_config.json

This file was deleted.

77 changes: 77 additions & 0 deletions examples/conversation_with_RAG_agents/configs/agent_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[
{
"class": "LlamaIndexAgent",
"args": {
"name": "Tutorial-Assistant",
"description": "Tutorial-Assistant is an agent that can provide answer based on English tutorial material, mainly the markdown files. It can answer general questions about AgentScope.",
"sys_prompt": "You're an assistant helping new users to use AgentScope. The language style is helpful and cheerful. You generate answers based on the provided context. The answer is expected to be no longer than 100 words. If the key words of the question can be found in the provided context, the answer should contain the section name which contains the answer. For example, 'You may refer to SECTION_NAME for more details.'",
"model_config_name": "qwen_config",
"emb_model_config_name": "qwen_emb_config",
"rag_config": {
"knowledge_id": "agentscope_tutorial_rag",
"similarity_top_k": 5,
"log_retrieval": false,
"recent_n_mem": 1
}
}
},
{
"class": "LlamaIndexAgent",
"args": {
"name": "Code-Search-Assistant",
"description": "Code-Search-Assistant is an agent that can provide answer based on AgentScope code base. It can answer questions about specific modules in AgentScope.",
"sys_prompt": "You're a coding assistant of AgentScope. The answer starts with appreciation for the question, then provide details regarding the functionality and features of the modules mentioned in the question. The language should be in a professional and simple style. The answer is limited to be less than 100 words.",
"model_config_name": "qwen_config",
"emb_model_config_name": "qwen_emb_config",
"rag_config": {
"knowledge_id": "agentscope_code_rag",
"similarity_top_k": 5,
"log_retrieval": false,
"recent_n_mem": 1
}
}
},
{
"class": "LlamaIndexAgent",
"args": {
"name": "API-Assistant",
"description": "API-Assistant is an agent that can answer questions about APIs in AgentScope. It can answer general questions about AgentScope.",
"sys_prompt": "You're an assistant providing answers to the questions related to APIs (functions and classes) in AgentScope. The language style is helpful and cheerful. You generate answers based on the provided context. The answer is expected to be no longer than 200 words. If the key words of the question can be found in the provided context, the answer should contain the module of the API. For example, 'You may refer to MODULE_NAME for more details.'",
"model_config_name": "qwen_config",
"emb_model_config_name": "qwen_emb_config",
"rag_config": {
"knowledge_id": "agentscope_api_rag",
"similarity_top_k": 3,
"log_retrieval": true,
"recent_n_mem": 1
}
}
},
{
"class": "LlamaIndexAgent",
"args": {
"name": "Searching-Assistant",
"description": "Search-Assistant is an agent that can provide answer based on AgentScope code and tutorial. It can answer questions about everything in AgentScope codes and tutorials.",
"sys_prompt": "You're a helpful assistant of AgentScope. The answer starts with appreciation for the question, then provide output the location of the code or section that the most relevant to the question. The answer is limited to be less than 50 words.",
"model_config_name": "qwen_config",
"emb_model_config_name": "qwen_emb_config",
"rag_config": {
"knowledge_id": "agentscope_global_rag",
"similarity_top_k": 5,
"log_retrieval": false,
"recent_n_mem": 1,
"persist_dir": "./rag_storage/searching_assist"
}
}
},
{
"class": "DialogAgent",
"args": {
"name": "Agent-Guiding-Assistant",
"description": "Agent-Guiding-Assistant is an agent that decide which agent should provide the answer next. It can answer questions about specific functions and classes in AgentScope.",
"sys_prompt": "You're an assistant guiding the user to specific agent for help. The answer is in a cheerful styled language. The output starts with appreciation for the question. Next, rephrase the question in a simple declarative Sentence for example, 'I think you are asking...'. Last, if the question is about detailed code or example in AgentScope Framework, output '@ Code-Search-Assistant you might be suitable for answering the question'; if the question is about API or function calls (Example: 'Is there function related...' or 'how can I initialize ...' ) in AgentScope, output '@ API-Assistant, I think you are more suitable for the question, please tell us more about it'; if question is about where to find some context (Example:'where can I find...'), output '@ Searching-Assistant, we need your help', otherwise, output '@ Tutorial-Assistant, I think you are more suitable for the question, can you tell us more about it?'. The answer is expected to be only one sentence",
"model_config_name": "qwen_config",
"use_memory": false
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[
{
"knowledge_id": "agentscope_code_rag",
"persist_dir": "./rag_storage/code_assist",
"chunk_size": 2048,
"chunk_overlap": 40,
"data_processing": [
{
"load_data": {
"loader": {
"create_object": true,
"module": "llama_index.core",
"class": "SimpleDirectoryReader",
"init_args": {
"input_dir": "../../src/agentscope",
"recursive": true,
"required_exts": [
".py"
]
}
}
},
"store_and_index": {
"transformations": [
{
"create_object": true,
"module": "llama_index.core.node_parser",
"class": "CodeSplitter",
"init_args": {
"language": "python",
"chunk_lines": 100
}
}
]
}
}
]
},
{
"knowledge_id": "agentscope_api_rag",
"persist_dir": "./rag_storage/api_assist",
"chunk_size": 2048,
"chunk_overlap": 40,
"data_processing": [
{
"load_data": {
"loader": {
"create_object": true,
"module": "llama_index.core",
"class": "SimpleDirectoryReader",
"init_args": {
"input_dir": "../../docs/docstring_html/",
"required_exts": [
".html"
]
}
}
}
}
]
},
{
"knowledge_id": "agentscope_global_rag",
"persist_dir": "./rag_storage/searching_assist",
"chunk_size": 2048,
"chunk_overlap": 40,
"data_processing": [
{
"load_data": {
"loader": {
"create_object": true,
"module": "llama_index.core",
"class": "SimpleDirectoryReader",
"init_args": {
"input_dir": "../../docs/sphinx_doc/en/source/tutorial",
"required_exts": [
".md"
]
}
}
}
},
{
"load_data": {
"loader": {
"create_object": true,
"module": "llama_index.core",
"class": "SimpleDirectoryReader",
"init_args": {
"input_dir": "../../src/agentscope",
"recursive": true,
"required_exts": [
".py"
]
}
}
},
"store_and_index": {
"transformations": [
{
"create_object": true,
"module": "llama_index.core.node_parser",
"class": "CodeSplitter",
"init_args": {
"language": "python",
"chunk_lines": 100
}
}
]
}
}
]
}
]
27 changes: 27 additions & 0 deletions examples/conversation_with_RAG_agents/configs/model_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"model_type": "post_api_chat",
"config_name": "gpt_postapi_config",
"api_url": "http://47.88.8.18:8088/api/ask",
"headers": {
"Content-Type": "application/json",
"Authorization": ""
},
"messages_key": "messages",
"json_args": {
"model": "gpt-4"
}
},
{
"model_type": "dashscope_text_embedding",
"config_name": "qwen_emb_config",
"model_name": "text-embedding-v2",
"api_key": ""
},
{
"model_type": "dashscope_chat",
"config_name": "qwen_config",
"model_name": "qwen-max",
"api_key": ""
}
]
37 changes: 37 additions & 0 deletions examples/conversation_with_RAG_agents/groupchat_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
""" Group chat utils."""
import re
from typing import Sequence


def select_next_one(agents: Sequence, rnd: int) -> Sequence:
"""
Select next agent.
"""
return agents[rnd % len(agents)]


def filter_agents(string: str, agents: Sequence) -> Sequence:
"""
This function filters the input string for occurrences of the given names
prefixed with '@' and returns a list of the found names.
"""
if len(agents) == 0:
return []

# Create a pattern that matches @ followed by any of the candidate names
pattern = (
r"@(" + "|".join(re.escape(agent.name) for agent in agents) + r")\b"
)

# Find all occurrences of the pattern in the string
matches = re.findall(pattern, string)

# Create a dictionary mapping agent names to agent objects for quick lookup
agent_dict = {agent.name: agent for agent in agents}

# Return the list of matched agent objects preserving the order
ordered_agents = [
agent_dict[name] for name in matches if name in agent_dict
]
return ordered_agents
Loading
Loading