henryhyunwookim commited on
Commit
77bf585
·
verified ·
1 Parent(s): e54820e

Create utils/utils.py

Browse files
Files changed (1) hide show
  1. utils/utils.py +50 -0
utils/utils.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ result_dict = {
8
+ "rank": result["position"],
9
+ "title": result["title"],
10
+ "URL": result["link"],
11
+ "snippet": result["snippet"]
12
+ }
13
+ search_results.append(result_dict)
14
+ return search_results
15
+
16
+
17
+ def get_prompt(user_query, search_summary):
18
+ system_message = f"""
19
+ You will provide a factual and concise answer based on the user input.
20
+ The user input might be in a non-Japansee language but your answer must be in Japanese.
21
+ The user input are [ユーザークエリ], which is the user's question, and [検索結果], which is the google search result based on the user query.
22
+
23
+ Your aswer should follow the below format:
24
+
25
+ (Your response to the user query in a single paragraph.)
26
+
27
+ [重要情報源]
28
+ (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.)
29
+
30
+
31
+ Here is an example of your answer when the user query was "ecu test":
32
+
33
+ ecu.testは、自動車のデータを読み取り、処理することができるソフトウェアツールです。ARXML、DBC、A2L、ODXなど、ほとんどの自動車関連のフォーマットに対応しています。ecu.testは、tracetronic GmbHがドイツのドレスデンに拠点を置いて開発したソフトウェアツールであり、組み込みシステムのテストと検証に使用されます。
34
+
35
+ [重要情報源]
36
+ - ecu.test(https://www.tracetronic.com/products/ecu-test/)
37
+ - ECU-TEST(https://en.wikipedia.org/wiki/ECU-TEST)
38
+ """
39
+
40
+ user_message = f"""
41
+ [ユーザークエリ]:{user_query}
42
+ [検索結果]:{search_summary}
43
+ """
44
+
45
+ prompt = [
46
+ SystemMessage(content=system_message),
47
+ HumanMessage(content=user_message)
48
+ ]
49
+
50
+ return prompt