Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
WuJunde committed Dec 9, 2023
1 parent d6b005d commit d40a128
Show file tree
Hide file tree
Showing 3 changed files with 1,390 additions and 12 deletions.
4 changes: 3 additions & 1 deletion creat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import networkx as nx
import math
import faiss
import numpy as np

from langchain.docstore import InMemoryDocstore
from langchain.embeddings import HuggingFaceEmbeddings
Expand Down Expand Up @@ -43,7 +44,8 @@ def relevance_score_fn(score: float) -> float:
# This function converts the euclidean norm of normalized embeddings
# (0 is most similar, sqrt(2) most dissimilar)
# to a similarity function (0 to 1)
return 1.0 - score / math.sqrt(2)
# return 1.0 - score / math.sqrt(2)
return 1 - 1 / (1 + np.exp(score))


def create_new_memory_retriever():
Expand Down
24 changes: 13 additions & 11 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
back_know = []
for i in town_people.keys(): # generate bk knowledge for everyone
back_know.append(i+': '+ agents[i].get_summary(force_refresh=False))
# print("get sum success")
# bk = [x for x in back_know]
for i in town_people.keys(): # add to people mem
agents[i].memory.add_memory(back_know)
action_results[i] = i + 'is' + town_people[i]["status"]
agents[i].memory.add_memory(' You know the following about people: ' + '. '.join(back_know))
# print("mem add success")
action_results[i] = i + ' is ' + town_people[i]["status"]

global_time = 0
for repeats in range(5):
Expand All @@ -37,21 +40,20 @@
people.append(i)
people_description.append(action_results[i])

# for name in people:
# prompt = "You are {}. Your plans are: {}. You are currently in {} with the following description: {}. Your memories are: {}. It is currently {}:00. The following people are in this area: {}. You can interact with them.".format(name, plans[name], location, town_areas[location], '\n'.join(compressed_memories_all[name][-5:]), str(global_time), ', '.join(people))
# for i in people:
# if i not in action_results: # initialize action results as the status, and add agent mem with description
# action_results[i] = agents[i].get_summary(force_refresh=False)
for i in people: # add observation to memory and react
print("Mind Tree of people: ", i)

others = [x for x in people if x != i]
observation = "You are {}.You are currently in {} with the following description: {}. \
It is currently {}:00. The following people are in this area: {}. You can interact with them.". \
format(i, location, town_areas[location], str(global_time), ', '.join(others))

# observation = "You are {}.You are currently in {} with the following description: {}. \
# It is currently {}:00. The following people are in this area: {}. You can interact with them.". \
# format(i, location, town_areas[location], str(global_time), ', '.join(others))

# others_des = [x for x in people_description if i+': ' not in x]
# observation += ' You know the following about people: ' + '. '.join(others_des)

others_des = [x for x in people_description if i+': ' not in x]
observation += ' You know the following about people: ' + '. '.join(others_des)
observation = ' '.join(others_des)

print("For people %s, The observation is: %s \n" % (i, observation))

Expand Down
Loading

0 comments on commit d40a128

Please sign in to comment.