forked from nakhimchea/custom_chatgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore_service.py
54 lines (45 loc) · 2.19 KB
/
firestore_service.py
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
import firebase_admin
from firebase_admin import credentials, firestore
from file_operator import *
import time
# Application Default credentials are automatically created.
cred = credentials.Certificate('serviceAccount.json')
app = firebase_admin.initialize_app(cred)
db = firestore.client()
class FireStore:
@staticmethod
def failed_faq(input_text: str):
print("Pushing not trained question...")
db.collection('cxBots').document('wingGPT').collection('new').document(str(time.time_ns()//1000000)).set({'qEn': input_text}, merge=False)
print("Done Pushing not trained question.")
@staticmethod
def write_faqs(dataframe: DataFrame):
print("Writing to Firestore")
counts = 0
content = []
faqs = []
for i in range(len(dataframe)):
iq_en = dataframe.loc[i, 'Question EN']
iq_km = dataframe.loc[i, 'Question KM']
ir_en = dataframe.loc[i, 'Response EN'] + ' explained in part ' + str(counts) + '.'
content.append(ir_en)
data = {
'qEn': iq_en,
'qKm': iq_km,
'rEn': ir_en,
'aEn': dataframe.loc[i, 'Answer EN'],
'aKm': dataframe.loc[i, 'Answer KM']
}
faqs.append(data)
counts += 1
data = {
'qEn': 'How to contact you?',
'qKm': 'តើយើងអាចទាក់ទងអ្នកដោយរបៀបណា?',
'rEn': 'the way to contact us explained in part {0}.'.format(counts),
'aEn': 'Pardon, please contact the Customer Support team via [email protected] or 023999989 or 012999489.',
'aKm': 'សូមអធ្យាស្រ័យ! សូមទាក់ទងមកកាន់ក្រុមបម្រើអតិថិជនតាមអ៉ីម៉ែល [email protected] រឺតាមរយៈលេខទូរសព្ទ 023999989 ឬ 012999489។',
}
faqs.append(data)
db.collection('cxBots').document('wingGPT').set({'faqs': faqs}, merge=True)
FileOperator.write_to_text('knowledge/knowledge.txt', content)
print("Done Writing to Firestore")