Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -39,6 +39,13 @@ class MyClient(discord.Client):
|
|
39 |
def __init__(self, *args, **kwargs):
|
40 |
super().__init__(*args, **kwargs)
|
41 |
self.is_processing = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
async def on_ready(self):
|
44 |
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
@@ -70,7 +77,7 @@ async def generate_response(message):
|
|
70 |
user_mention = message.author.mention
|
71 |
|
72 |
# μ μ¬ν λ°μ΄ν° μ°ΎκΈ°
|
73 |
-
most_similar_data = find_most_similar_data(user_input)
|
74 |
|
75 |
system_message = f"{user_mention}, DISCORDμμ μ¬μ©μλ€μ κ΄κ³ μΉ΄νΌλΌμ΄ν
μμ²μ λ΅νλ μ΄μμ€ν΄νΈμ
λλ€."
|
76 |
system_prefix = """
|
@@ -110,11 +117,10 @@ async def generate_response(message):
|
|
110 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
111 |
return f"{user_mention}, {full_response_text}"
|
112 |
|
113 |
-
def find_most_similar_data(query):
|
114 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
115 |
-
all_embeddings = model.encode(all_datasets['text'].tolist(), convert_to_tensor=True)
|
116 |
|
117 |
-
cosine_scores = util.pytorch_cos_sim(query_embedding, all_embeddings)
|
118 |
best_match_index = torch.argmax(cosine_scores).item()
|
119 |
|
120 |
if cosine_scores[0][best_match_index] > 0.5: # μ μ¬λ μκ³κ° μ€μ
|
|
|
39 |
def __init__(self, *args, **kwargs):
|
40 |
super().__init__(*args, **kwargs)
|
41 |
self.is_processing = False
|
42 |
+
self.all_embeddings = None
|
43 |
+
self.initialize_embeddings()
|
44 |
+
|
45 |
+
def initialize_embeddings(self):
|
46 |
+
global all_datasets, model
|
47 |
+
text_data = all_datasets['text'].fillna('').astype(str).tolist()
|
48 |
+
self.all_embeddings = model.encode(text_data, convert_to_tensor=True)
|
49 |
|
50 |
async def on_ready(self):
|
51 |
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
|
|
77 |
user_mention = message.author.mention
|
78 |
|
79 |
# μ μ¬ν λ°μ΄ν° μ°ΎκΈ°
|
80 |
+
most_similar_data = find_most_similar_data(user_input, message.client)
|
81 |
|
82 |
system_message = f"{user_mention}, DISCORDμμ μ¬μ©μλ€μ κ΄κ³ μΉ΄νΌλΌμ΄ν
μμ²μ λ΅νλ μ΄μμ€ν΄νΈμ
λλ€."
|
83 |
system_prefix = """
|
|
|
117 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
118 |
return f"{user_mention}, {full_response_text}"
|
119 |
|
120 |
+
def find_most_similar_data(query, client):
|
121 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
|
|
122 |
|
123 |
+
cosine_scores = util.pytorch_cos_sim(query_embedding, client.all_embeddings)
|
124 |
best_match_index = torch.argmax(cosine_scores).item()
|
125 |
|
126 |
if cosine_scores[0][best_match_index] > 0.5: # μ μ¬λ μκ³κ° μ€μ
|