File tree Expand file tree Collapse file tree 4 files changed +106
-0
lines changed
app-backend/templates/tools Expand file tree Collapse file tree 4 files changed +106
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2024 Intel Corporation
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ search_knowledge_base :
5
+ description : Search a knowledge base for a given query. Returns text related to the query.
6
+ callable_api : tools.py:search_knowledge_base
7
+ args_schema :
8
+ query :
9
+ type : str
10
+ description : query
11
+ return_output : retrieved_data
12
+
13
+ search_sql_database :
14
+ description : Search a SQL database with a natural language query. Returns text related to the query.
15
+ callable_api : tools.py:search_sql_database
16
+ args_schema :
17
+ query :
18
+ type : str
19
+ description : natural language query
20
+ return_output : retrieved_data
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2024 Intel Corporation
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ import os
5
+ import requests
6
+
7
+
8
+ def search_knowledge_base (query : str ) -> str :
9
+ """Search a knowledge base about music and singers for a given query.
10
+
11
+ Returns text related to the query.
12
+ """
13
+ url = os .environ .get ("WORKER_AGENT_URL" )
14
+ print (url )
15
+ proxies = {"http" : "" }
16
+ payload = {
17
+ "messages" : query ,
18
+ }
19
+ response = requests .post (url , json = payload , proxies = proxies )
20
+ return response .json ()["text" ]
21
+
22
+
23
+ def search_sql_database (query : str ) -> str :
24
+ """Search a SQL database on artists and their music with a natural language query.
25
+
26
+ Returns text related to the query.
27
+ """
28
+ url = os .environ .get ("SQL_AGENT_URL" )
29
+ print (url )
30
+ proxies = {"http" : "" }
31
+ payload = {
32
+ "messages" : query ,
33
+ }
34
+ response = requests .post (url , json = payload , proxies = proxies )
35
+ return response .json ()["text" ]
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2024 Intel Corporation
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ import os
5
+ import requests
6
+
7
+ def search_knowledge_base (query : str ) -> str :
8
+ """Search the knowledge base for a specific query."""
9
+ url = os .environ .get ("RETRIEVAL_TOOL_URL" )
10
+ print (url )
11
+ proxies = {"http" : "" }
12
+ payload = {
13
+ "text" : query ,
14
+ }
15
+ response = requests .post (url , json = payload , proxies = proxies )
16
+ print (response )
17
+ if "documents" in response .json ():
18
+ docs = response .json ()["documents" ]
19
+ context = ""
20
+ for i , doc in enumerate (docs ):
21
+ if i == 0 :
22
+ context = doc
23
+ else :
24
+ context += "\n " + doc
25
+ # print(context)
26
+ return context
27
+ elif "text" in response .json ():
28
+ return response .json ()["text" ]
29
+ elif "reranked_docs" in response .json ():
30
+ docs = response .json ()["reranked_docs" ]
31
+ context = ""
32
+ for i , doc in enumerate (docs ):
33
+ if i == 0 :
34
+ context = doc ["text" ]
35
+ else :
36
+ context += "\n " + doc ["text" ]
37
+ # print(context)
38
+ return context
39
+ else :
40
+ return "Error parsing response from the knowledge base."
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2024 Intel Corporation
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ search_knowledge_base :
5
+ description : Search knowledge base for a given query. Returns text related to the query.
6
+ callable_api : worker_agent_tools.py:search_knowledge_base
7
+ args_schema :
8
+ query :
9
+ type : str
10
+ description : query
11
+ return_output : retrieved_data
You can’t perform that action at this time.
0 commit comments