henryhyunwookim
commited on
Commit
•
6c3ea70
1
Parent(s):
ad89d13
Update utils/utils.py
Browse fileschange function name and resulting language from Japanese to the query language
- utils/utils.py +24 -22
utils/utils.py
CHANGED
@@ -1,51 +1,53 @@
|
|
1 |
from langchain_core.messages import HumanMessage, SystemMessage
|
2 |
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
for result in search_output["organic_results"]:
|
7 |
-
# This is to handle search results without a snippet
|
8 |
try:
|
9 |
snippet = result["snippet"]
|
10 |
except KeyError:
|
11 |
snippet = ""
|
12 |
-
|
13 |
result_dict = {
|
14 |
"rank": result["position"],
|
15 |
"title": result["title"],
|
16 |
"URL": result["link"],
|
17 |
"snippet": snippet
|
18 |
}
|
19 |
-
|
20 |
-
return
|
21 |
|
22 |
|
23 |
-
def get_prompt(user_query,
|
24 |
-
system_message =
|
25 |
-
You will
|
26 |
-
|
27 |
-
The user input
|
|
|
28 |
|
|
|
29 |
Your aswer should follow the below format:
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
(A list of top three sources with URLs from the search result that you refer to. For each item in the list, just mention the title and URL.)
|
35 |
|
36 |
|
37 |
Here is an example of your answer when the user query was "ecu test":
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
- ecu.test(https://www.tracetronic.com/products/ecu-test/)
|
43 |
-
- ECU-TEST(https://en.wikipedia.org/wiki/ECU-TEST)
|
44 |
"""
|
45 |
|
46 |
user_message = f"""
|
47 |
-
[
|
48 |
-
[
|
49 |
"""
|
50 |
|
51 |
prompt = [
|
|
|
1 |
from langchain_core.messages import HumanMessage, SystemMessage
|
2 |
|
3 |
|
4 |
+
def get_top_results(search_output: dict) -> list:
|
5 |
+
top_results = []
|
6 |
for result in search_output["organic_results"]:
|
|
|
7 |
try:
|
8 |
snippet = result["snippet"]
|
9 |
except KeyError:
|
10 |
snippet = ""
|
11 |
+
|
12 |
result_dict = {
|
13 |
"rank": result["position"],
|
14 |
"title": result["title"],
|
15 |
"URL": result["link"],
|
16 |
"snippet": snippet
|
17 |
}
|
18 |
+
top_results.append(result_dict)
|
19 |
+
return top_results
|
20 |
|
21 |
|
22 |
+
def get_prompt(user_query, top_results):
|
23 |
+
system_message = """
|
24 |
+
You will receive a user query and its top search results on Google,
|
25 |
+
and return a concise summary of them with the most relevant resources that you referred to when generating the summary.
|
26 |
+
The user input might be in a non-English language but you must keep the original language, meaning your response will be in English if the user query is in English.
|
27 |
+
The user input is the user's query and the Google search result returned by the user query.
|
28 |
|
29 |
+
|
30 |
Your aswer should follow the below format:
|
31 |
+
***
|
32 |
+
{Your response to the user query in a single paragraph.}
|
33 |
|
34 |
+
[Primary resources]
|
35 |
+
{A list of top three sources with URLs from the search result that you refer to. For each item in the list, just mention the title and URL.}
|
36 |
+
***
|
|
|
37 |
|
38 |
|
39 |
Here is an example of your answer when the user query was "ecu test":
|
40 |
+
|
41 |
+
ecu.test is a software tool by tracetronic GmbH for testing and validating embedded systems, particularly automotive software. It supports test automation and multiple test tools, catering to various testing levels, including model, software, and hardware in the loop. ecu.test offers a user-friendly interface, simplifies test case creation, and integrates with existing test processes. It also generates intuitive test reports and operates in distributed test environments.
|
42 |
|
43 |
+
[Primary Resources]
|
44 |
+
- ecu.test (https://www.tracetronic.com/products/ecu-test/)
|
45 |
+
- ECU-TEST (https://en.wikipedia.org/wiki/ECU-TEST)
|
|
|
|
|
46 |
"""
|
47 |
|
48 |
user_message = f"""
|
49 |
+
[User query]:{user_query}
|
50 |
+
[Search result]:{top_results}
|
51 |
"""
|
52 |
|
53 |
prompt = [
|