henryhyunwookim commited on
Commit
6c3ea70
1 Parent(s): ad89d13

Update utils/utils.py

Browse files

change function name and resulting language from Japanese to the query language

Files changed (1) hide show
  1. 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 summarize_search_result(search_output: dict) -> list:
5
- search_results = []
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
- search_results.append(result_dict)
20
- return search_results
21
 
22
 
23
- def get_prompt(user_query, search_summary):
24
- system_message = f"""
25
- You will provide a factual and concise answer based on the user input.
26
- The user input might be in a non-Japansee language but your answer must be in Japanese.
27
- The user input are [ユーザークエリ], which is the user's question, and [検索結果], which is the google search result based on the user query.
 
28
 
 
29
  Your aswer should follow the below format:
 
 
30
 
31
- (Your response to the user query in a single paragraph.)
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
- ecu.testは、自動車のデータを読み取り、処理することができるソフトウェアツールです。ARXML、DBC、A2L、ODXなど、ほとんどの自動車関連のフォーマットに対応しています。ecu.testは、tracetronic GmbHがドイツのドレスデンに拠点を置いて開発したソフトウェアツールであり、組み込みシステムのテストと検証に使用されます。
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
- [ユーザークエリ]:{user_query}
48
- [検索結果]:{search_summary}
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 = [