-
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathtools.py
More file actions
161 lines (143 loc) · 4.96 KB
/
tools.py
File metadata and controls
161 lines (143 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
Definition of the tools avaialable to the Agent.
"""
from typing import Optional
from types import MappingProxyType
from api.models.embedding_model import EMBEDDING_MODEL
from api.tools.utils import (
filter_retrieved_data,
is_valid_plugin,
retrieve_documents,
extract_top_chunks
)
from api.config.loader import CONFIG
retrieval_config = CONFIG["retrieval"]
def search_plugin_docs(query: str, keywords: str, logger, plugin_name: Optional[str] = None) -> str:
"""
Search tool for the plugin docs. Exploits both a sparse and dense search, resulting in a
hybrid search.
Args:
query (str): The user query.
keywords (str): Keywords extracted from the user query.
plugin_name (Optional[str]): The refered plugin name in the query (if available).
Returns:
str: The result of the research of the plugin search tool.
"""
source_name = CONFIG["tool_names"]["plugins"]
data_retrieved_semantic, scores_semantic, data_retrieved_keyword, scores_keyword = (
retrieve_documents(
query=query,
keywords=keywords,
logger=logger,
source_name=source_name,
embedding_model=EMBEDDING_MODEL
)
)
if plugin_name and is_valid_plugin(plugin_name):
data_retrieved_semantic, data_retrieved_keyword = filter_retrieved_data(
data_retrieved_semantic,
data_retrieved_keyword,
plugin_name
)
return extract_top_chunks(
data_retrieved_semantic,
scores_semantic,
data_retrieved_keyword,
scores_keyword,
top_k=retrieval_config["top_k_plugins"],
logger=logger
)
def search_jenkins_docs(query: str, keywords: str, logger) -> str:
"""
Search tool for the Jenkins docs. Exploits both a sparse and dense search, resulting in a
hybrid search.
Args:
query (str): The user query.
keywords (str): Keywords extracted from the user query.
Returns:
str: The result of the research of the docs search tool.
"""
source_name = CONFIG["tool_names"]["jenkins_docs"]
data_retrieved_semantic, scores_semantic, data_retrieved_keyword, scores_keyword = (
retrieve_documents(
query=query,
keywords=keywords,
logger=logger,
source_name=source_name,
embedding_model=EMBEDDING_MODEL
)
)
return extract_top_chunks(
data_retrieved_semantic,
scores_semantic,
data_retrieved_keyword,
scores_keyword,
top_k=retrieval_config["top_k_docs"],
logger=logger
)
#-> third change
def search_stackoverflow_threads(query: str, keywords: str, logger) -> str:
"""
Search tool for Stack Overflow threads. Exploits both a sparse and dense
search, resulting in a hybrid search.
Args:
query (str): The user query.
keywords (str): Keywords extracted from the user query.
logger: Logger object.
Returns:
str: The result of the Stack Overflow search tool.
"""
source_name = CONFIG["tool_names"]["stackoverflow"]
data_retrieved_semantic, scores_semantic, data_retrieved_keyword, scores_keyword = (
retrieve_documents(
query=query,
keywords=keywords,
logger=logger,
source_name=source_name,
embedding_model=EMBEDDING_MODEL
)
)
return extract_top_chunks(
data_retrieved_semantic,
scores_semantic,
data_retrieved_keyword,
scores_keyword,
top_k=retrieval_config["top_k_stackoverflow"],
logger=logger
)
def search_community_threads(query: str, keywords: str, logger) -> str:
"""
Search tool for the community discourse threads. Exploits both a sparse and
dense search, resulting in a hybrid search. In this case a higher weight is
given to the results that come from the semantic search
Args:
query (str): The user query.
keywords (str): Keywords extracted from the user query.
Returns:
str: The result of the research of the docs search tool.
"""
source_name = CONFIG["tool_names"]["community_threads"]
data_retrieved_semantic, scores_semantic, data_retrieved_keyword, scores_keyword = (
retrieve_documents(
query=query,
keywords=keywords,
logger=logger,
source_name=source_name,
embedding_model=EMBEDDING_MODEL
)
)
return extract_top_chunks(
data_retrieved_semantic,
scores_semantic,
data_retrieved_keyword,
scores_keyword,
top_k=retrieval_config["top_k_discourse"],
logger=logger,
semantic_weight=0.7
)
TOOL_REGISTRY = MappingProxyType({
"search_plugin_docs": search_plugin_docs,
"search_jenkins_docs": search_jenkins_docs,
"search_stackoverflow_threads": search_stackoverflow_threads,
"search_community_threads": search_community_threads,
})