Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
7d56735
1
Parent(s):
9672e77
Update other_function.py
Browse files- other_function.py +10 -0
other_function.py
CHANGED
@@ -30,6 +30,16 @@ def generate_response(query):
|
|
30 |
if chunk.choices[0].delta.content:
|
31 |
response += chunk.choices[0].delta.content
|
32 |
return response.replace("###", '').replace('\nUser:','')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
def predict_pest(filepath):
|
|
|
30 |
if chunk.choices[0].delta.content:
|
31 |
response += chunk.choices[0].delta.content
|
32 |
return response.replace("###", '').replace('\nUser:','')
|
33 |
+
class ConversationBufferMemory:
|
34 |
+
def __init__(self, memory_key="chat_history"):
|
35 |
+
self.memory_key = memory_key
|
36 |
+
self.buffer = []
|
37 |
+
|
38 |
+
def add_to_memory(self, interaction):
|
39 |
+
self.buffer.append(interaction)
|
40 |
+
|
41 |
+
def get_memory(self):
|
42 |
+
return "\n".join([f"Human: {entry['user']}\nAssistant: {entry['assistant']}" for entry in self.buffer])
|
43 |
|
44 |
|
45 |
def predict_pest(filepath):
|