llama-index

Форк
0
109 строк · 3.5 Кб
1
"""Prompts for ChatGPT."""
2

3
from llama_index.legacy.core.llms.types import ChatMessage, MessageRole
4
from llama_index.legacy.prompts.base import ChatPromptTemplate
5

6
# text qa prompt
7
TEXT_QA_SYSTEM_PROMPT = ChatMessage(
8
    content=(
9
        "You are an expert Q&A system that is trusted around the world.\n"
10
        "Always answer the query using the provided context information, "
11
        "and not prior knowledge.\n"
12
        "Some rules to follow:\n"
13
        "1. Never directly reference the given context in your answer.\n"
14
        "2. Avoid statements like 'Based on the context, ...' or "
15
        "'The context information ...' or anything along "
16
        "those lines."
17
    ),
18
    role=MessageRole.SYSTEM,
19
)
20

21
TEXT_QA_PROMPT_TMPL_MSGS = [
22
    TEXT_QA_SYSTEM_PROMPT,
23
    ChatMessage(
24
        content=(
25
            "Context information is below.\n"
26
            "---------------------\n"
27
            "{context_str}\n"
28
            "---------------------\n"
29
            "Given the context information and not prior knowledge, "
30
            "answer the query.\n"
31
            "Query: {query_str}\n"
32
            "Answer: "
33
        ),
34
        role=MessageRole.USER,
35
    ),
36
]
37

38
CHAT_TEXT_QA_PROMPT = ChatPromptTemplate(message_templates=TEXT_QA_PROMPT_TMPL_MSGS)
39

40
# Tree Summarize
41
TREE_SUMMARIZE_PROMPT_TMPL_MSGS = [
42
    TEXT_QA_SYSTEM_PROMPT,
43
    ChatMessage(
44
        content=(
45
            "Context information from multiple sources is below.\n"
46
            "---------------------\n"
47
            "{context_str}\n"
48
            "---------------------\n"
49
            "Given the information from multiple sources and not prior knowledge, "
50
            "answer the query.\n"
51
            "Query: {query_str}\n"
52
            "Answer: "
53
        ),
54
        role=MessageRole.USER,
55
    ),
56
]
57

58
CHAT_TREE_SUMMARIZE_PROMPT = ChatPromptTemplate(
59
    message_templates=TREE_SUMMARIZE_PROMPT_TMPL_MSGS
60
)
61

62

63
# Refine Prompt
64
CHAT_REFINE_PROMPT_TMPL_MSGS = [
65
    ChatMessage(
66
        content=(
67
            "You are an expert Q&A system that strictly operates in two modes "
68
            "when refining existing answers:\n"
69
            "1. **Rewrite** an original answer using the new context.\n"
70
            "2. **Repeat** the original answer if the new context isn't useful.\n"
71
            "Never reference the original answer or context directly in your answer.\n"
72
            "When in doubt, just repeat the original answer."
73
            "New Context: {context_msg}\n"
74
            "Query: {query_str}\n"
75
            "Original Answer: {existing_answer}\n"
76
            "New Answer: "
77
        ),
78
        role=MessageRole.USER,
79
    )
80
]
81

82

83
CHAT_REFINE_PROMPT = ChatPromptTemplate(message_templates=CHAT_REFINE_PROMPT_TMPL_MSGS)
84

85

86
# Table Context Refine Prompt
87
CHAT_REFINE_TABLE_CONTEXT_TMPL_MSGS = [
88
    ChatMessage(content="{query_str}", role=MessageRole.USER),
89
    ChatMessage(content="{existing_answer}", role=MessageRole.ASSISTANT),
90
    ChatMessage(
91
        content=(
92
            "We have provided a table schema below. "
93
            "---------------------\n"
94
            "{schema}\n"
95
            "---------------------\n"
96
            "We have also provided some context information below. "
97
            "{context_msg}\n"
98
            "---------------------\n"
99
            "Given the context information and the table schema, "
100
            "refine the original answer to better "
101
            "answer the question. "
102
            "If the context isn't useful, return the original answer."
103
        ),
104
        role=MessageRole.USER,
105
    ),
106
]
107
CHAT_REFINE_TABLE_CONTEXT_PROMPT = ChatPromptTemplate(
108
    message_templates=CHAT_REFINE_TABLE_CONTEXT_TMPL_MSGS
109
)
110

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.