File size: 2,793 Bytes
a495cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import json
import os
import re


# env variables
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
PINECONE_KEY = os.getenv("PINECONE_KEY")
PINECONE_ENV = os.getenv("PINECONE_ENV")
FIREBASE_ENV = os.getenv("FIREBASE_SERVICE_ACCOUNT_TEST3_83FFC")

# proxy for imap access from hugging face.
PROXY_IP = os.getenv("PROXY_IP")
PROXY_PORT = os.getenv("PROXY_PORT")

# swagger
swagger_destination_path = "./src/static/swagger.json"
SWAGGER_URL = "/api/docs"  # URL for exposing Swagger UI (without trailing '/')
API_URL = "http://localhost:5000/file/swagger.json"

# firebase
FIREBASE_STORAGE_ROOT = "images/"
FIREBASE_STORAGE_BUCKET = "test3-83ffc.appspot.com"
FIREBASE_REALTIME_DATABASE = "https://test3-83ffc-default-rtdb.firebaseio.com/"

# pinecone
PINECONE_NAMESPACE = "risinglangchain-namespace"
PINECONE_INDEX_NAME = "risinglangchain-index"

# open ai
DEFAULT_GPT_MODEL = "gpt-4"

# AI Agent name
AGENT_NAME = "RisingBrain Assistant"

# indexes of relatedness of embedding
COMMAND_SMS_INDEXES = ["pWDrks5DO1bEPLlUtQ1f", "LEpAhmFi8tAOQUE7LHZZ"]  # 4, 5
COMMAND_BROWSER_OPEN = ["taVNeDINonUqJWXBlESU"]  # 10

# Twilio
ACCOUNT_SID = os.getenv("TWILIO_ACCOUNT_SID")
AUTH_TOKEN = os.getenv("TWILIO_AUTH_TOKEN")
# HuggingFace
HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")


# actions flag :True -> Directly with Category_prompt
ACTION_FLAG = True


class ProgramType:
    BROWSER = "browser"
    ALERT = "alert"
    IMAGE = "image"
    SMS = "sms"
    CONTACT = "contact"
    MESSAGE = "message"
    AUTO_TASK = "autotask"
    RAILS_OFF_TOPIC = "rails_off_topic"


# validate json format
def validateJSON(jsonData):
    try:
        json.loads(jsonData)
    except ValueError as err:
        return False
    return True


def parseJsonFromCompletion(data: str) -> json:
    result = data[1:-1]
    array = result.split('\\"')
    # fmt: off
    if len(array) > 1:
        array[0] = array[0].replace("'", '"')
        result = array[0] + '"' + array[1] + '"' + array[2]
    else:
        result = result.replace("{'", '{"')
        result = result.replace("'}", '"}')
        result = result.replace("': '", '": "')
        result = result.replace("': \\\"", '": \"')
        result = result.replace("', '", '", "')
        result = result.replace("':", '":')

        substring = '\\"}'
        replacement = '\"}'

        index = result.rfind(substring)

        if index == len(result) - 3:
            result = result[:index] + replacement + result[index + len(substring):]
    # fmt: on
    try:
        return json.loads(result)
    except Exception as e:
        return result


def parseUrlFromStr(text: str) -> str:
    # Search for the link using regex
    link = re.search(r"(https?://\S+)", text)

    if link:
        return link.group(0)
    else:
        return ""