From 41e48497cd70be62556ae2afe260d8c470c5dc18 Mon Sep 17 00:00:00 2001 From: mrq Date: Mon, 1 May 2023 05:47:35 +0000 Subject: [PATCH] more tunes --- README.md | 4 +- src/ext/generative_agent.py | 73 ++++---- src/ext/memory.py | 2 +- src/ext/prompts.py | 344 +++++++++++++----------------------- src/main.py | 33 ++-- src/utils.py | 29 ++- 6 files changed, 198 insertions(+), 287 deletions(-) diff --git a/README.md b/README.md index aeb8df8..6797f52 100755 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ I ***do not*** plan on making this uber-user friendly like [mrq/ai-voice-cloning A local LM is quite slow. -Even using one that's more instruction-tuned like Vicuna (with a `SYSTEM:\nUSER:\nASSISTANT:` structure of prompts) is still inconsistent. +Even using one that's more instruction-tuned like Vicuna (with a `SYSTEM:\nUSER:\nASSISTANT:` structure of prompts), it's still inconsistent. -However, I seem to be getting consistent results with SuperCOT 33B, it's just, well, slow. +However, I seem to be getting consistent results with SuperCOT 33B, it's just, well, slow. SuperCOT 13B seems to be giving better answers over Vicuna-1.1 13B, so. GPT4 seems to Just Work, unfortunately. \ No newline at end of file diff --git a/src/ext/generative_agent.py b/src/ext/generative_agent.py index 67efd2c..7c0c724 100755 --- a/src/ext/generative_agent.py +++ b/src/ext/generative_agent.py @@ -41,6 +41,9 @@ class GenerativeAgent(BaseModel): name: str """The character's name.""" + + sex: str + """The character's sex.""" age: Optional[int] = None """The optional age of the character.""" @@ -53,7 +56,7 @@ class GenerativeAgent(BaseModel): llm: BaseLanguageModel """The underlying language model.""" verbose: bool = True - summary: str = "" #: :meta private: + summary: str = "N/A" #: :meta private: """Stateful self-summary generated via reflection on the character's memory.""" summary_refresh_seconds: int = 3600 #: :meta private: @@ -62,7 +65,7 @@ class GenerativeAgent(BaseModel): last_refreshed: datetime = Field(default_factory=datetime.now) # : :meta private: """The last time the character's summary was regenerated.""" - daily_summaries: List[str] = Field(default_factory=list) # : :meta private: + summaries: List[str] = Field(default_factory=list) # : :meta private: """Summary of the events in the plan that the agent took.""" class Config: @@ -96,23 +99,21 @@ class GenerativeAgent(BaseModel): print(response) return response + def get_most_recent_memories(self, last_k: int = 4) -> str: + memories = self.memory.memory_retriever.memory_stream[-last_k:] + return [ document.page_content for document in memories ] + def summarize_related_memories(self, observation: str) -> str: """Summarize memories that are most relevant to an observation.""" prompt = PromptTemplate.from_template(get_prompt('summarize_related_memories')) entity_name = self._get_entity_from_observation(observation).split("\n")[0].strip() q1 = f"What is the relationship between {self.name} and {entity_name}" - if self.name.strip() == entity_name: - return "" + if self.name.strip() in entity_name: + return "N/A" - # this is unused, so ignore for now - """ entity_action = self._get_entity_action(observation, entity_name) q2 = f"{entity_name} is {entity_action}" summary = self.chain(prompt=prompt).run(q1=q1, queries=[q1, q2]).strip() - """ - summary = self.chain(prompt=prompt).run(q1=q1, queries=[q1]).strip() - if self.verbose: - print(summary) return summary #return self.chain(prompt=prompt).run(q1=q1, q2=q2).strip() @@ -122,22 +123,25 @@ class GenerativeAgent(BaseModel): prompt = PromptTemplate.from_template( get_prompt('generate_reaction').replace("{suffix}", suffix) ) - agent_summary_description = self.get_summary() - relevant_memories_str = self.summarize_related_memories(observation) + summary = self.get_summary() + relevant_memories = self.summarize_related_memories(observation) + + # I think relevant_memories is suppose to only provide context for a relationship between agent and observer, as suggested with the query + # but the original implementation seems to just leverage it to further filter relevant memories, per the name + if relevant_memories and relevant_memories != "N/A": + memory = relevant_memories + else: + memory = "\n".join(self.get_most_recent_memories()) current_time_str = datetime.now().strftime("%B %d, %Y, %I:%M %p") kwargs: Dict[str, Any] = dict( - agent_summary_description=agent_summary_description, current_time=current_time_str, - relevant_memories=relevant_memories_str, - agent_name=self.name, - observation=observation, - agent_status=self.status, + name=self.name, + status=self.status if self.status else "N/A", + summary=summary if summary else "N/A", + memory=memory if memory else "N/A", + observation=observation if observation else "N/A", ) - formatted_prompt = prompt.format(most_recent_memories="", **kwargs) - consumed_tokens = self.llm.get_num_tokens(formatted_prompt) - - kwargs[self.memory.most_recent_memories_token_key] = consumed_tokens reaction = self.chain(prompt=prompt).run(**kwargs).strip() if self.verbose: print(reaction) @@ -160,7 +164,7 @@ class GenerativeAgent(BaseModel): candidate = candidate.strip().replace("React:", "REACT:").replace("Say:", "SAY:") results.append(f'{candidate}'.replace("SAY:", "said").replace(f"REACT: {self.name}", "").replace("REACT:", "")) if len(results) > 0: - response = "and".join(results).strip().replace(" ", " ") + response = " and ".join(results).strip().replace(" ", " ") valid = True else: response = f"did not react in a relevant way" @@ -170,7 +174,7 @@ class GenerativeAgent(BaseModel): self.memory.save_context( {}, { - self.memory.add_memory_key: f"{self.name} observed {observation} and {response}" + self.memory.add_memory_key: f"{self.name} observed: {observation}; {self.name}'s reaction: {response}" }, ) @@ -197,8 +201,7 @@ class GenerativeAgent(BaseModel): self.memory.save_context( {}, { - self.memory.add_memory_key: f"{self.name} observed " - f"{observation} and said {farewell}" + self.memory.add_memory_key: f"{self.name} observed: {observation}; {self.name}'s farewell response: {farewell}" }, ) return False, f"{self.name} said {farewell}" @@ -207,8 +210,7 @@ class GenerativeAgent(BaseModel): self.memory.save_context( {}, { - self.memory.add_memory_key: f"{self.name} observed " - f"{observation} and said {response_text}" + self.memory.add_memory_key: f"{self.name} observed: {observation}; {self.name}'s response: {response_text}" }, ) return True, f"{self.name} said {response_text}" @@ -225,7 +227,7 @@ class GenerativeAgent(BaseModel): """""" # The agent seeks to think about their core characteristics. prompt = PromptTemplate.from_template(get_prompt('compute_agent_summary')) - summary = self.chain(prompt).run(name=self.name, queries=[f"{self.name}'s core characteristics"]).strip() + summary = self.chain(prompt).run(name=self.name, summary=self.summaries[-1] if len(self.summaries) else self.summary, queries=[f"{self.name}'s core characteristics"]).strip() if self.verbose: print(summary) return summary @@ -240,13 +242,16 @@ class GenerativeAgent(BaseModel): or force_refresh ): self.summary = self._compute_agent_summary() + self.summaries.append(self.summary) self.last_refreshed = current_time - age = self.age if self.age is not None else "N/A" - return ( - f"Name: {self.name} (age: {age})" - + f"\nInnate traits: {self.traits}" - + f"\n{self.summary.strip()}" - ) + + values = [ + f"Name: {self.name} (sex: {self.sex}, age: {self.age if self.age is not None else 'N/A'})", + f"\nInnate traits: {self.traits}", + f"\nStatus: {self.status}" + ] + + return "\n".join([ value for value in values if value[-3:] != "N/A" ]) + f"\n{self.summary.strip()}" def get_full_header(self, force_refresh: bool = False) -> str: """Return a full header of the agent's status, summary, and current time.""" diff --git a/src/ext/memory.py b/src/ext/memory.py index 678c1a2..320f710 100755 --- a/src/ext/memory.py +++ b/src/ext/memory.py @@ -172,7 +172,7 @@ class GenerativeAgentMemory(BaseMemory): return "\n".join([f"{mem}" for mem in content]) def format_memories_simple(self, relevant_memories: List[Document]) -> str: - return "; ".join([f"{mem.page_content}" for mem in relevant_memories]) + return "; ".join([f"{mem.page_content}" for mem in relevant_memories]).replace(".;", ";") def _get_memories_until_limit(self, consumed_tokens: int) -> str: """Reduce the number of tokens in the documents.""" diff --git a/src/ext/prompts.py b/src/ext/prompts.py index b9f8555..ce6a31c 100755 --- a/src/ext/prompts.py +++ b/src/ext/prompts.py @@ -1,234 +1,128 @@ import os -LLM_PROMPT_TUNE = os.environ.get('LLM_PROMPT_TUNE', "vicuna") # oai, vicuna +LLM_PROMPT_TUNE = os.environ.get('LLM_PROMPT_TUNE') # oai, vicuna, supercot +STOP_TOKEN_HINT = "" # "\nWrite \"END\" afterwards." -# split because I can't prematurely end on the END token like I can with a local LM -if LLM_PROMPT_TUNE == "oai": - PROMPTS = { - "entity_from_observation": { - "system": ( - "What is the observed entity in the following observation?" - " ONLY report one object and write one sentence." - ), - "user": ( - "Observation: {observation}" - ), - "assistant": "Entity=", - }, - "entity_action": { - "system": ( - "What is `{entity}` doing in the following observation?" - " ONLY report one object and write one sentence." - ), - "user": ( - "Observation: {observation}" - ), - "assistant": "`{entity}` is ", - }, - "summarize_related_memories": { - "system": ( - "Given the following context, answer the following question in four sentences or less. Summarize the answer as well." - ), - "user": ( - "{q1}?" - "\nContext: {relevant_memories_simple}" - ), - "assistant": "Summary of relevant context: ", - }, - "compute_agent_summary": { - "system": ( - "Given the following statements, how would you summarize {name}'s core characteristics?" - " Do not embellish under any circumstances." - ), - "user": ( - "Statements: {relevant_memories_simple}" - ), - "assistant": "Summary: ", - }, - "topic_of_reflection": { - "system": ( - "Given only the following information, what are the 3 most salient" - " high-level questions we can answer about the subjects in the statements?" - " Provide each question on a new line." - ), - "user": ( - "Information: {observations}" - ), - "assistant": "", - }, - "insights_on_topic": { - "system": ( - "Given the following statements about {topic}," - " what 5 high-level insights can you infer?" - " (example format: insight (because of 1, 5, 3))" - ), - "user": ( - "Statements: {related_statements}" - ), - "assistant": "", - }, - "memory_importance": { - "system": ( - "On the scale of 1 to 10, where 1 is purely mundane" - " (e.g., brushing teeth, making bed) and 10 is extremely poignant" - " (e.g., a break up, college acceptance)," - " rate the likely poignancy of the following piece of memory." - " Respond with only a single integer." - ), - "user": ( - "Memory: {memory_content}" - ), - "assistant": "Rating: ", - }, - "generate_reaction": { - "system": ( - "It is {current_time}." - " The following is a description of {agent_name}:" - "\n{agent_summary_description}" - "\n{agent_name}'s status: {agent_status}" - "\nSummary of relevant context from {agent_name}'s memory: {relevant_memories}" - "\nMost recent observations: {most_recent_memories}" - "\n\n{suffix}" - ), - "user": ( - "Observation: {observation}" - ), - "assistant": "" - }, +USE_STOP_HINT = [ "llama" ] - # - "context": ( # insert your JB here - "" +PROMPTS = { + "entity_from_observation": { + "system": ( + "What is the observed entity in the following observation?" + " ONLY report one object and write one sentence." + f'{STOP_TOKEN_HINT}' ), - "suffix_generate_reaction": ( - "Given the following observation, in one sentence, how would {agent_name} appropriately react?" - "\nWrite 1 reply only in internet RP style, italicize actions, and avoid quotation marks. Use markdown. Be proactive, creative, and drive the plot and conversation forward. Write no less than six sentences each. Always stay in character and avoid repetition." - "\nIf the action is to engage in dialogue, write `SAY: \"what to say\"`." - "\nOtherwise, write `REACT: {agent_name}'s reaction`." + "user": ( + "Observation: {observation}" ), - "suffix_generate_dialogue_response": ( - "\nWrite 1 reply only in internet RP style, italicize actions, and avoid quotation marks. Use markdown. Be proactive, creative, and drive the plot and conversation forward. Write no less than six sentences each. Always stay in character and avoid repetition." - "Given the following observation, in one sentence, what would {agent_name} say?" - "\nTo continue the conversation, write: `SAY: \"what to say\"`." - "\nOtherwise, to end the conversation, write: `GOODBYE: \"what to say\"`." + "assistant": "Entity=", + }, + "entity_action": { + "system": ( + "What is the following entity doing in the following observation?" + " ONLY write one sentence." + f'{STOP_TOKEN_HINT}' ), - } -else: - PROMPTS = { - "entity_from_observation": { - "system": ( - "What is the observed entity in the following observation?" - " ONLY report one object and write one sentence." - " Write `END` afterwards." - ), - "user": ( - "Observation: {observation}" - ), - "assistant": "Entity=", - }, - "entity_action": { - "system": ( - "What is `{entity}` doing in the following observation?" - " ONLY report one object and write one sentence." - " Write `END` afterwards." - ), - "user": ( - "Observation: {observation}" - ), - "assistant": "`{entity}` is ", - }, - "summarize_related_memories": { - "system": ( - "Given the following context, answer the following question in four sentences or less. Summarize the answer as well." - " Write `END` afterwards." - "\nContext: {relevant_memories_simple}" - ), - "user": ( - "{q1}?" - ), - "assistant": "Summary of relevant context: ", - }, - "compute_agent_summary": { - "system": ( - "Given the following statements, how would you summarize {name}'s core characteristics?" - " Do not embellish under any circumstances." - " Write `END` afterwards." - ), - "user": ( - "Statements: {relevant_memories_simple}" - ), - "assistant": "Summary: ", - }, - "topic_of_reflection": { - "system": ( - "Given only the following information, what are the 3 most salient" - " high-level questions we can answer about the subjects in the statements?" - " Provide each question on a new line." - ), - "user": ( - "Information: {observations}" - ), - "assistant": "", - }, - "insights_on_topic": { - "system": ( - "Given the following statements about {topic}," - " what 5 high-level insights can you infer?" - " (example format: insight (because of 1, 5, 3))" - ), - "user": ( - "Statements: {related_statements}" - ), - "assistant": "", - }, - "memory_importance": { - "system": ( - "On the scale of 1 to 10, where 1 is purely mundane" - " (e.g., brushing teeth, making bed) and 10 is extremely poignant" - " (e.g., a break up, college acceptance)," - " rate the likely poignancy of the following piece of memory." - " Respond with only a single integer followed by 'END'." - ), - "user": ( - "Memory: {memory_content}" - ), - "assistant": "Rating: ", - }, - "generate_reaction": { - "system": ( - "It is {current_time}." - " The following is a description of {agent_name}:" - "\n{agent_summary_description}" - "\n{agent_name}'s status: {agent_status}" - "\nSummary of relevant context from {agent_name}'s memory: {relevant_memories}" - "\nMost recent observations: {most_recent_memories}" - "\n\n{suffix}" - ), - "user": ( - "Observation: {observation}" - ), - "assistant": "" - }, + "user": ( + "Entity: {entity}" + "\nObservation: {observation}" + ), + "assistant": "`{entity}` is ", + }, + "summarize_related_memories": { + "system": ( + "Given the following context, answer the following question." + f'{STOP_TOKEN_HINT}' + ), + "user": ( + "Context: {relevant_memories_simple}" + "\nQuestion: {q1}?" + ), + "assistant": "Summary of relevant context: ", + }, + "compute_agent_summary": { + "system": ( + "Given the following previous summary and the following statements, how would you summarize {name}'s core characteristics?" + " Do not embellish under any circumstances." + f'{STOP_TOKEN_HINT}' + ), + "user": ( + "Previous summary: {summary}\n" + "Statements: {relevant_memories_simple}" + ), + "assistant": "Summary: ", + }, + "topic_of_reflection": { + "system": ( + "Given only the following information, what are the 3 most salient" + " high-level questions we can answer about the subjects in the statements?" + " Provide each question on a new line." + f'{STOP_TOKEN_HINT}' + ), + "user": ( + "Information: {observations}" + ), + "assistant": "", + }, + "insights_on_topic": { + "system": ( + "Given the following statements about {topic}," + " what 5 high-level insights can you infer?" + " (example format: insight (because of 1, 5, 3))" + f'{STOP_TOKEN_HINT}' + ), + "user": ( + "Statements: {related_statements}" + ), + "assistant": "", + }, + "memory_importance": { + "system": ( + "On the scale of 1 to 10, where 1 is purely mundane" + " (e.g., brushing teeth, making bed) and 10 is extremely poignant" + " (e.g., a break up, college acceptance)," + " rate the likely poignancy of the following event." + "\nRespond with only a single integer." + f"{STOP_TOKEN_HINT}" + ), + "user": ( + "Event: {memory_content}" + ), + "assistant": "Rating: ", + }, + "generate_reaction": { + "system": ( + "It is {current_time}." + "\n{summary}" + "\n{memory}" + "\n\n{suffix}" + f"{STOP_TOKEN_HINT}" + ), + "user": ( + "Observation: {observation}" + ), + "assistant": "" + }, - # - "context": ( - "" # insert your JB here - ), - "suffix_generate_reaction": ( - "Given the following observation, in one sentence, how would {agent_name} appropriately react?" - "\nWrite 1 reply only in internet RP style, italicize actions, and avoid quotation marks. Use markdown. Be proactive, creative, and drive the plot and conversation forward. Write no less than six sentences each. Always stay in character and avoid repetition." - "\nIf the action is to engage in dialogue, write `SAY: \"what to say\"`." - "\nOtherwise, write `REACT: {agent_name}'s reaction`." - "\nWrite 'END' afterwards." - ), - "suffix_generate_dialogue_response": ( - "Given the following observation, in one sentence, what would {agent_name} say?" - "\nWrite 1 reply only in internet RP style, italicize actions, and avoid quotation marks. Use markdown. Be proactive, creative, and drive the plot and conversation forward. Write no less than six sentences each. Always stay in character and avoid repetition." - "\nTo continue the conversation, write: `SAY: \"what to say\"`." - "\nOtherwise, to end the conversation, write: `GOODBYE: \"what to say\"`." - "\nWrite \"END\" afterwards." - ), - } + # + "context": ( # insert your JB here + "" + ), + "suffix_generate_reaction": ( + "Given the following observation, how would {name} appropriately react?" + "\nIf the action is to engage in dialogue, only write `SAY: \"what to say\"`." + "\nOr otherwise, only write `REACT: how to react`." + "\nWrite ONLY one line, one sentence." + #"\nBe proactive, creative, and drive the plot and conversation forward." + ), + "suffix_generate_dialogue_response": ( + "Given the following observation, what would {name} say?" + "\nTo continue the conversation, only write: `SAY: \"what to say\"`." + "\nOr otherwise, to end the conversation, only write: `GOODBYE: \"what to say\"`." + "\nWrite ONLY one line, one sentence." + #"\nBe proactive, creative, and drive the plot and conversation forward." + ), +} PROMPT_TUNES = { "default": "{query}", @@ -292,6 +186,10 @@ def get_prompt( key, tune=LLM_PROMPT_TUNE ): roles = PROMPT_ROLES[tune] if role in roles: role = roles[role] + + # remove stop token hinting if we're using OAI since I don't have control over early terminating + if STOP_TOKEN_HINT in query and tune in USE_STOP_HINT: + query = query.replace(STOP_TOKEN_HINT, "") output = f'{PROMPT_TUNES[tune]}' output = output.replace("{role}", role) diff --git a/src/main.py b/src/main.py index a978a8f..bbcb176 100755 --- a/src/main.py +++ b/src/main.py @@ -8,27 +8,22 @@ webui = None AGENTS = {} -def create_agent_proxy(name, age, traits, status, daily_summaries=None): +def create_agent_proxy(name, age, sex, traits, status, summary=""): kwargs = locals() - if "daily_summaries" in kwargs: - summaries = kwargs["daily_summaries"].split("\n") - kwargs["daily_summaries"] = [ ( summary ) for summary in summaries ] agent = create_agent(**kwargs) AGENTS[agent.name] = agent return ( f"Agent created: {agent.name}", - update_agents_list() + update_saved_agents_list(), + update_agents_list(), ) -def edit_agent( name, age, traits, status, daily_summaries=None ): - if daily_summaries is not None: - summaries = daily_summaries.split("\n") - daily_summaries = [ ( summary ) for summary in summaries ] - +def edit_agent( name, age, sex, traits, status, summary="" ): AGENTS[name].age = age + AGENTS[name].sex = sex AGENTS[name].traits = traits AGENTS[name].status = status - AGENTS[name].daily_summaries = daily_summaries + AGENTS[name].summary = summary return f"Agent updated: {name}" @@ -152,10 +147,13 @@ def setup_webui(share=False): with gr.Tab("Create Agent"): with gr.Row(): with gr.Column(): - AGENT_SETTINGS["name"] = gr.Textbox(lines=1, label="Name", value="Adam") - AGENT_SETTINGS["age"] = gr.Number(label="Age") - AGENT_SETTINGS["traits"] = gr.Textbox(lines=1, label="Traits", value="N/A") - AGENT_SETTINGS["status"] = gr.Textbox(lines=1, label="Status", value="N/A") + AGENT_SETTINGS["name"] = gr.Textbox(lines=1, label="Name", value="") + with gr.Row(): + AGENT_SETTINGS["age"] = gr.Number(label="Age") + AGENT_SETTINGS["sex"] = gr.Textbox(lines=1, label="Sex", value="") + with gr.Row(): + AGENT_SETTINGS["traits"] = gr.Textbox(lines=1, label="Traits", value="N/A") + AGENT_SETTINGS["status"] = gr.Textbox(lines=1, label="Status", value="N/A") AGENT_SETTINGS["daily_summaries"] = gr.Textbox(lines=4, label="Summary", value="") ACTIONS["add_agent"] = gr.Button(value="Add Agent") @@ -223,6 +221,7 @@ def setup_webui(share=False): inputs=list(AGENT_SETTINGS.values()), outputs=[ CONSOLE_OUTPUTS["create_agent"], + SAVELOAD_SETTINGS["agent"], OBSERVE_SETTINGS["agent"], ] ) @@ -257,9 +256,7 @@ if __name__ == "__main__": age=34, traits="curious, helpful", # You can add more persistent traits here status="N/A", # When connected to a virtual world, we can have the characters update their status - daily_summaries = [ - ("{name} started her new job as a career counselor last week and received her first assignment, a client named Tommie.") - ], + summary = ("{name} started her new job as a career counselor last week and received her first assignment, a client named Tommie.") ) # We can add memories directly to the memory object diff --git a/src/utils.py b/src/utils.py index 937fa5a..3d5a7ee 100755 --- a/src/utils.py +++ b/src/utils.py @@ -21,21 +21,30 @@ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain.vectorstores import FAISS # shit I can shove behind an env var -os.environ['LLM_PROMPT_TUNE'] = "supercot" LLM_TYPE = os.environ.get('LLM_TYPE', "llamacpp") # options: llamacpp, oai LLM_LOCAL_MODEL = os.environ.get('LLM_MODEL', #"./models/ggml-vicuna-13b-1.1/ggml-vic13b-uncensored-q4_2.bin" - #"./models/llama-13b-supercot-ggml/ggml-model-q4_0.bin" + #"./models/llama-13b-supercot-ggml/ggml-model-q4_2.bin" "./models/llama-33b-supercot-ggml/ggml-model-q4_2.bin" ) LLM_CONTEXT = int(os.environ.get('LLM_CONTEXT', '2048')) LLM_THREADS = int(os.environ.get('LLM_THREADS', '6')) EMBEDDING_TYPE = os.environ.get("LLM_EMBEDDING_TYPE", "hf") # options: llamacpp, oai, hf +# deduce a default given a model path if LLM_TYPE=="oai": - os.environ['LLM_PROMPT_TUNE'] = "oai" -LLM_PROMPT_TUNE = os.environ.get('LLM_PROMPT_TUNE', "supercot") + LLM_PROMPT_TUNE_DEFAULT = "oai" +else: + if "supercot" in LLM_LOCAL_MODEL.lower(): + LLM_PROMPT_TUNE_DEFAULT = "supercot" + elif "vicuna" in LLM_LOCAL_MODEL.lower(): + LLM_PROMPT_TUNE_DEFAULT = "vicuna" + else: + LLM_PROMPT_TUNE_DEFAULT = "llama" + +LLM_PROMPT_TUNE = os.environ.get('LLM_PROMPT_TUNE', LLM_PROMPT_TUNE_DEFAULT) +os.environ['LLM_PROMPT_TUNE'] = LLM_PROMPT_TUNE # sync it back to prompts callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]) # unncessesary but whatever @@ -142,6 +151,7 @@ def create_agent(**kwargs): settings = { "llm": LLM, "verbose": True, + "sex": "Male", "memory": _create_new_memories(), } settings.update(kwargs) @@ -156,9 +166,11 @@ def save_agent( agent ): obj = { "name": agent.name, "age": agent.age, + "sex": agent.sex, "traits": agent.traits, "status": agent.status, "summary": agent.summary, + "summaries": agent.summaries, "memory_retriever": agent.memory.memory_retriever, } path = f"./agents/{agent.name}.pth" @@ -194,12 +206,11 @@ def interview_agent(agent: GenerativeAgent, message: str, username: str = "Perso return agent.generate_dialogue_response(new_message) -def run_conversation(agents: List[GenerativeAgent], initial_observation: str, limit: int = 0, p_reaction: float = 0.7 ) -> None: +def run_conversation(agents: List[GenerativeAgent], observation: str, limit: int = 0, p_reaction: float = 1 ) -> None: """Runs a conversation between agents.""" - print(colored("[Conversation]", "magenta"), initial_observation) - _, observation = agents[0].generate_reaction(initial_observation) - print(colored("[Conversation]", "magenta"), observation) - + print(colored("[Conversation]", "magenta")) + agent_observes( agents[0], [observation] ) + dialogue = [] while True: break_dialogue = False