Spaces:
Paused
Paused
frdel commited on
Commit ·
c1c3e54
1
Parent(s): 80b971d
v0.7 cleanup
Browse filesremoved leftovers, added .gitkeeps
python/extensions/monologue_end/zero_memorize_history.py_
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
from agent import Agent
|
| 2 |
-
from python.helpers.extension import Extension
|
| 3 |
-
from python.helpers.files import read_file
|
| 4 |
-
from python.helpers.vector_db import get_or_create
|
| 5 |
-
import json
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
class MemorizeHistory(Extension):
|
| 9 |
-
|
| 10 |
-
async def execute(self, **kwargs):
|
| 11 |
-
if self.agent.number != 0:
|
| 12 |
-
return # only agent 0 will memorize chat history with user
|
| 13 |
-
|
| 14 |
-
self.agent.context.log.log(
|
| 15 |
-
type="info", content="Memorizing chat history...", temp=True
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
# get system message and chat history for util llm
|
| 19 |
-
system = self.agent.read_prompt("fw.memory.hist_sum.sys.md")
|
| 20 |
-
# msgs = []
|
| 21 |
-
# for msg in self.agent.history:
|
| 22 |
-
# content = msg.get("content", "")
|
| 23 |
-
# if content:
|
| 24 |
-
# msgs.append(content)
|
| 25 |
-
# msgs_text = json.dumps(msgs)
|
| 26 |
-
msgs_text = self.agent.concat_messages(self.agent.history)
|
| 27 |
-
|
| 28 |
-
# call util llm to summarize conversation
|
| 29 |
-
summary = await self.agent.call_utility_llm(
|
| 30 |
-
system=system, msg=msgs_text, output_label=""
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
# save chat history
|
| 34 |
-
vdb = get_or_create(
|
| 35 |
-
logger=self.agent.context.log,
|
| 36 |
-
embeddings_model=self.agent.config.embeddings_model,
|
| 37 |
-
memory_dir="./memory/history",
|
| 38 |
-
knowledge_dir="",
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
vdb.insert_text(text=summary, metadata={"full": msgs_text})
|
| 42 |
-
|
| 43 |
-
self.agent.context.log.log(
|
| 44 |
-
type="info", content="Chat history memorized.", temp=True
|
| 45 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
python/extensions/monologue_start/.gitkeep
ADDED
|
File without changes
|
python/extensions/msg_loop_break/.gitkeep
ADDED
|
File without changes
|
python/extensions/msg_loop_end/.gitkeep
ADDED
|
File without changes
|