Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yxjiang committed May 4, 2024
1 parent 4f598cc commit 54205c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
9 changes: 8 additions & 1 deletion polymind/core/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LinearMemory(Memory):
"""

memory_list: List[str] = Field(default=[], description="The list of memory stored in the memory.")
capacity: int = Field(default=100, description="The capacity of the memory.")

def set_memory(self, piece: str, **kwargs) -> None:
"""Set the memory.
Expand All @@ -29,9 +30,15 @@ def set_memory(self, piece: str, **kwargs) -> None:
piece (str): The piece of memory to store.
"""
self.memory_list.append(piece)
if len(self.memory_list) > self.capacity:
self.memory_list.pop(0)

def get_memory(self, last_k: int = 5, **kwargs) -> str:
"""Get the last k pieces of memory."""
"""Get the last k pieces of memory.
Args:
last_k (int): The number of last pieces of memory to retrieve.
"""
if last_k == 0 or last_k > len(self.memory_list):
return "\n".join(self.memory_list)
else:
Expand Down
36 changes: 21 additions & 15 deletions polymind/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ class AtomTask(BaseTask):
Example inputs:
1.
---
'{{"context": "I\'m unable to provide real-time data."}}'
'{{"context": "I\'m unable to connect the Internet.", "answer": "Please check the network connection}}'
---
2.
---
'{{"question": "\n\n what's the biggest news about AI today?\n\t\t\t\n\n.", "answer": "OpenAI has released GPT-10."}}'
'{{"context": "\n what's the biggest news about AI today?\n\t\t\n\n.", "answer": "OpenAI released GPT-10."}}'
---
Corresponding outputs:
1.
```
{{
"output": "I'm unable to provide real-time data."
"output": "If unable to provide real-time data, please check the network connection."
}}
```
2.
Expand All @@ -161,12 +161,11 @@ class AtomTask(BaseTask):
}}
```
The real input is as below:
---
The real input is available in the below json blob.
Please consolidate and convert the info into the ```json blob```, and the key should be "output".
```json
{input}
---
Please extract and post-process the result into the ```json blob```, and the key should be "output".
```
"""

def __init__(self, tool_manager: ToolManager, tool_retriever: RetrieveTool, **kwargs):
Expand Down Expand Up @@ -266,10 +265,10 @@ async def _execute(self, input: Message) -> Message:
input.content[
"input"
] = f"""
Context:
Context:
Output of the previous steps:
------
{memory_context}
[{memory_context}]
------
{input_field}
Objective: {self.task_name}
Expand Down Expand Up @@ -303,7 +302,8 @@ async def _execute(self, input: Message) -> Message:
response = await self._use_tool(objective=self.task_name, tool_description=answer_blob["action"])
self._logger.task_log(f"Output of task {self.task_name}: {response.content}")
# Add the objective and output to the memory.
self.memory.set_memory(piece=f"{self.task_name}: {response.content}")
response_output = response.content["output"]
self.memory.set_memory(piece=f"{self.task_name}: {response_output}")
return response


Expand Down Expand Up @@ -344,11 +344,17 @@ async def _execute(self, input: Message) -> Message:
Message: The result of the composite task carried in a message.
"""
message = input
updated_message = self._update_context(input=message)
task = self._get_next_task(updated_message)
# updated_message = self._update_context(input=message)
# task = self._get_next_task(updated_message)
# while task:
# task_result_message = await task(input=updated_message)
# output_message = self._update_context(input=task_result_message)
# task = self._get_next_task(output_message)
self._update_context(input=message)
task = self._get_next_task(message)
while task:
task_result_message = await task(input=updated_message)
output_message = self._update_context(input=task_result_message)
message = await task(message)
output_message = self._update_context(input=message)
task = self._get_next_task(output_message)
return output_message

Expand Down

0 comments on commit 54205c1

Please sign in to comment.