File size: 2,329 Bytes
8d2b389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
GEN_SYS_PROMPT = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
PRE_SYS_PROMPT = "You are a helpful assistant that performs time series prediction. The user will provide a sequence and you will predict the sequence."
ANA_SYS_PROMPT = "You are a helpful assistant that performs time series analysis. The user will provide a sequence and you will respond to the questions based on this sequence."

PRE_INST_PROMPT = "Please predict the following sequence carefully."
PRE_INST_PROMPT_TEXT = "Please predict the following sequence carefully. Context knowledge you may consider: {}"
ANA_INST_PROMPT_TEXT = "Please answer the following question carefully after analyzing the sequence: {}"

TEMPLATE = """{}

### Instruction:
{}

### Input:
{}

### Response:
{}"""


def getPrompt(flag, instruction=None, input=None, response=None, context=None):
    if flag == "general":  # instruction, [input], [response]
        system = GEN_SYS_PROMPT
        if instruction is None:
            raise ValueError("Instruction must be provided for general tasks.")
        else:
            instruction = instruction
        input = "" if input is None else input
        response = "" if response is None else response

    elif flag == "prediction":  # [context], input, [response]
        system = PRE_SYS_PROMPT
        instruction = PRE_INST_PROMPT if context is None else PRE_INST_PROMPT_TEXT.format(context)
        if input is None:
            raise ValueError("Input must be provided for prediction tasks.")
        else:
            input = input
        response = "" if response is None else response

    elif flag == "analysis":  # instruction, input, [response]
        system = ANA_SYS_PROMPT
        if instruction is None:
            raise ValueError("Instruction must be provided for analysis tasks.")
        else:
            instruction = ANA_INST_PROMPT_TEXT.format(instruction)
        if input is None:
            raise ValueError("Input must be provided for analysis tasks.")
        else:
            input = input
        response = "" if response is None else response

    else:
        raise ValueError("Flag must be one of 'general', 'prediction', or 'analysis'.")

    prompt = TEMPLATE.format(system, instruction, input, response)

    return prompt