File size: 2,537 Bytes
eb88ab8
 
2ca300b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb88ab8
 
 
 
 
 
 
 
 
 
 
 
 
 
e7481b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
# utils.py

import re 
from dotenv import load_dotenv
import re 
import os 
from globalvars import tasks

def load_env_variables():
    # Load the .env file
    load_dotenv()

    # Retrieve the environment variables
    hf_token = os.getenv('HF_TOKEN')
    yi_token = os.getenv('YI_TOKEN')

    return hf_token, yi_token

def parse_and_route(example_output: str):  
    # Regex pattern to match the true task  
    pattern = r'"(\w+)":\s?true'  
  
    # Find the true task  
    match = re.search(pattern, example_output)  
  
    if match:  
        true_task = match.group(1)  
        if true_task in tasks:  
            return {true_task: tasks[true_task]}  
        else:  
            return {true_task: "Task description not found"}  
    else:  
        return "No true task found in the example output" 
    
import json  
  
def escape_special_characters(text: str) -> str:  
    """  
    Escapes special characters in the given text for JSON and cURL compatibility.  
    """  
    escaped_text = json.dumps(text)[1:-1]   
    curl_escaped_text = escaped_text.replace(" ", "\\ ")  
    curl_escaped_text = curl_escaped_text.replace("&", "\\&")  
    curl_escaped_text = curl_escaped_text.replace(";", "\\;")  
    curl_escaped_text = curl_escaped_text.replace("(", "\\(")  
    curl_escaped_text = curl_escaped_text.replace(")", "\\)")  
    curl_escaped_text = curl_escaped_text.replace("$", "\\$")  
    curl_escaped_text = curl_escaped_text.replace("`", "\\`")  
    curl_escaped_text = curl_escaped_text.replace("|", "\\|")  
    curl_escaped_text = curl_escaped_text.replace("*", "\\*")  
    curl_escaped_text = curl_escaped_text.replace("?", "\\?")  
    curl_escaped_text = curl_escaped_text.replace("<", "\\<")  
    curl_escaped_text = curl_escaped_text.replace(">", "\\>")  
    curl_escaped_text = curl_escaped_text.replace("!", "\\!")  
    curl_escaped_text = curl_escaped_text.replace("{", "\\{")  
    curl_escaped_text = curl_escaped_text.replace("}", "\\}")  
    curl_escaped_text = curl_escaped_text.replace("[", "\\[")  
    curl_escaped_text = curl_escaped_text.replace("]", "\\]")  
    curl_escaped_text = curl_escaped_text.replace("#", "\\#")  
    curl_escaped_text = curl_escaped_text.replace("%", "\\%")  
    curl_escaped_text = curl_escaped_text.replace("^", "\\^")  
    curl_escaped_text = curl_escaped_text.replace("=", "\\=")  
    curl_escaped_text = curl_escaped_text.replace("~", "\\~")  
    curl_escaped_text = curl_escaped_text.replace("'", "\\'")  
  
    return curl_escaped_text