This commit is contained in:
ziming 2023-09-26 13:41:35 +08:00
parent e1d399e24c
commit e2af76fb08
3 changed files with 11 additions and 12 deletions

View file

@ -13,7 +13,7 @@ import json
# Meomry_basic 类
class Meomry_basic:
class Memory_basic:
def __init__(
self, created_time, accessed_time,
description,
@ -48,7 +48,7 @@ class Agent_memory(object):
def __init__(self, name: str, iss: str,
memory_forget: float = 0.99,
memories_list: list[Meomry_basic] = [], memory_path: str = None) -> None:
memories_list: list[Memory_basic] = [], memory_path: str = None) -> None:
'''
定义Agent,替换原有Agent使用需要其他人根据需求补全功能
Attributes:
@ -81,7 +81,7 @@ class Agent_memory(object):
memory_data = [mem.__dict__ for mem in self.memories_list]
json.dump(memory_data, file)
def memory_load(self, PATH: str) -> list[Meomry_basic]:
def memory_load(self, PATH: str) -> list[Memory_basic]:
"""
将Memory从指定路径的JSON文件中Load出来,返回一个记忆列表;如果load失败返回一个空列表
Args:
@ -92,7 +92,7 @@ class Agent_memory(object):
try:
with open(PATH, 'r') as file:
memory_data = json.load(file)
self.memories_list = [Meomry_basic(
self.memories_list = [Memory_basic(
**mem) for mem in memory_data]
return self.memories_list
except OSError:
@ -121,7 +121,7 @@ if __name__ == "__main__":
memory = run_gpt_random_concept()
curr_time = time.time()
poignancy = run_gpt_prompt_chat_poignancy(John, memory)
M = Meomry_basic(curr_time, curr_time, memory, poignancy)
M = Memory_basic(curr_time, curr_time, memory, poignancy)
John.memories_list.append(M)
John.memory_save(John.memory_path)

View file

@ -75,7 +75,7 @@ def prompt_generate(curr_input, prompt_lib_file):
RETURNS:
a str prompt that will be sent to OpenAI's GPT server.
"""
if type(curr_input) == type("string"):
if type(curr_input) is type("string"):
curr_input = [curr_input]
curr_input = [str(i) for i in curr_input]

View file

@ -4,11 +4,8 @@ from logging import Logger
import time
from gpt_structure import final_response
import run_gpt
from GA_memory_storage import Agent_memory, Meomry_basic
from GA_memory_storage import Agent_memory, Memory_basic
from retrive import agent_retrive
'''
首先
'''
def agent_reflect(agent):
@ -35,7 +32,9 @@ def generate_focus_point(memories_list, n=3):
try:
poi_dict = json.loads(out)
return (poi_dict['output'])
except:
except ValueError:
print(out)
Logger.error('无法返回正常结果')
return out
@ -57,7 +56,7 @@ def generate_insights_and_evidence(agent, memories_list, question, n=5):
try:
insight_list = json.loads(ret)
for insight, index in insight_list:
agent.memory_list.append(Meomry_basic(
agent.memory_list.append(Memory_basic(
time.time(), None, insight, None, None))
return (insight_list)
except: