File size: 2,203 Bytes
77bf585
 
 
 
 
 
ad89d13
 
 
 
 
 
77bf585
 
 
 
ad89d13
77bf585
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from langchain_core.messages import HumanMessage, SystemMessage


def summarize_search_result(search_output: dict) -> list:
    search_results = []
    for result in search_output["organic_results"]:
        # This is to handle search results without a snippet
        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