File size: 1,475 Bytes
c8b8544
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/python3
## Author: Raeid Saqur

### -------- CONSTANTS -------- ###

LABELS = ["Fall", "Neutral", "Rise"]
LABEL_MAP = {"Rise": 2, "Neutral": 1, "Fall": 0}
NUMERIC_LABEL_MAP = {v: k for k, v in LABEL_MAP.items()}
SEEDS = [0, 13, 42]

SYSTEM_ROLE_DEF_1 = "You are a helpful assistant and a financial technical analyst."
SYSTEM_ROLE_DEF_2 = ("You are a helpful financial market technical analyst. "
                     "You specialize in financial stock and equities market, a top expert in assessing market index movement direction from events and news. ")


def get_truncated_user_prompt_for_nifty(user_prompt: str, drop_percent: float = 0.5) -> str:
    """Keeps instruction and context unchanged, drops p% of news headlines randomly
    Usage e.g.:
        user_prompt = get_truncated_user_prompt_for_nifty(user_prompt, drop_percent=drop_percent)
    """
    import random

    splits = user_prompt.split("\n\n")
    context, news = splits[:-1], splits[-1]
    news_headlines = news.split("\n")
    news_headlines, suffix = news_headlines[:-1], news_headlines[-1]
    N = len(news_headlines)
    N_truncated = int(N * drop_percent)
    random.shuffle(news_headlines)
    truncated_news_headlines = news_headlines[:N_truncated] + [suffix]
    truncated_news_string = "\n".join(truncated_news_headlines)
    truncated_user_prompt = context + [truncated_news_string]
    truncated_user_prompt = "\n\n".join(truncated_user_prompt)

    return truncated_user_prompt