|
from langchain_core.messages import HumanMessage, SystemMessage |
|
|
|
|
|
def summarize_search_result(search_output: dict) -> list: |
|
search_results = [] |
|
for result in search_output["organic_results"]: |
|
|
|
try: |
|
snippet = result["snippet"] |
|
except KeyError: |
|
snippet = "" |
|
|
|
result_dict = { |
|
"rank": result["position"], |
|
"title": result["title"], |
|
"URL": result["link"], |
|
"snippet": snippet |
|
} |
|
search_results.append(result_dict) |
|
return search_results |
|
|
|
|
|
def get_prompt(user_query, search_summary): |
|
system_message = f""" |
|
You will provide a factual and concise answer based on the user input. |
|
The user input might be in a non-Japansee language but your answer must be in Japanese. |
|
The user input are [ユーザークエリ], which is the user's question, and [検索結果], which is the google search result based on the user query. |
|
|
|
Your aswer should follow the below format: |
|
|
|
(Your response to the user query in a single paragraph.) |
|
|
|
[重要情報源] |
|
(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.) |
|
|
|
|
|
Here is an example of your answer when the user query was "ecu test": |
|
|
|
ecu.testは、自動車のデータを読み取り、処理することができるソフトウェアツールです。ARXML、DBC、A2L、ODXなど、ほとんどの自動車関連のフォーマットに対応しています。ecu.testは、tracetronic GmbHがドイツのドレスデンに拠点を置いて開発したソフトウェアツールであり、組み込みシステムのテストと検証に使用されます。 |
|
|
|
[重要情報源] |
|
- ecu.test(https://www.tracetronic.com/products/ecu-test/) |
|
- ECU-TEST(https://en.wikipedia.org/wiki/ECU-TEST) |
|
""" |
|
|
|
user_message = f""" |
|
[ユーザークエリ]:{user_query} |
|
[検索結果]:{search_summary} |
|
""" |
|
|
|
prompt = [ |
|
SystemMessage(content=system_message), |
|
HumanMessage(content=user_message) |
|
] |
|
|
|
return prompt |