increase memory limit
This commit is contained in:
parent
bd42c115b4
commit
dd0e4ed573
|
@ -1,10 +1,12 @@
|
||||||
import atexit
|
import atexit
|
||||||
|
from functools import partial
|
||||||
from logging.config import dictConfig
|
from logging.config import dictConfig
|
||||||
from os import environ, path
|
from os import environ, path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from packit.agent import Agent, agent_easy_connect
|
from packit.agent import Agent, agent_easy_connect
|
||||||
|
from packit.memory import make_limited_memory
|
||||||
from packit.utils import logger_with_colors
|
from packit.utils import logger_with_colors
|
||||||
|
|
||||||
from adventure.utils.file import load_yaml
|
from adventure.utils.file import load_yaml
|
||||||
|
@ -43,8 +45,12 @@ if True:
|
||||||
from adventure.models.files import PromptFile, WorldPrompt
|
from adventure.models.files import PromptFile, WorldPrompt
|
||||||
from adventure.plugins import load_plugin
|
from adventure.plugins import load_plugin
|
||||||
from adventure.simulate import simulate_world
|
from adventure.simulate import simulate_world
|
||||||
from adventure.state import create_agents, save_world, save_world_state
|
from adventure.state import (
|
||||||
|
MEMORY_LIMIT,
|
||||||
|
create_agents,
|
||||||
|
save_world,
|
||||||
|
save_world_state,
|
||||||
|
)
|
||||||
|
|
||||||
# start the debugger, if needed
|
# start the debugger, if needed
|
||||||
if environ.get("DEBUG", "false").lower() == "true":
|
if environ.get("DEBUG", "false").lower() == "true":
|
||||||
|
@ -55,6 +61,9 @@ if environ.get("DEBUG", "false").lower() == "true":
|
||||||
debugpy.wait_for_client()
|
debugpy.wait_for_client()
|
||||||
|
|
||||||
|
|
||||||
|
memory_factory = partial(make_limited_memory, limit=MEMORY_LIMIT)
|
||||||
|
|
||||||
|
|
||||||
def int_or_inf(value: str) -> float | int:
|
def int_or_inf(value: str) -> float | int:
|
||||||
if value == "inf":
|
if value == "inf":
|
||||||
return float("inf")
|
return float("inf")
|
||||||
|
@ -224,6 +233,7 @@ def load_or_generate_world(
|
||||||
f"{world_prompt.flavor}. The theme is: {world_prompt.theme}.",
|
f"{world_prompt.flavor}. The theme is: {world_prompt.theme}.",
|
||||||
{},
|
{},
|
||||||
llm,
|
llm,
|
||||||
|
memory_factory=memory_factory,
|
||||||
)
|
)
|
||||||
|
|
||||||
if path.exists(world_state_file):
|
if path.exists(world_state_file):
|
||||||
|
@ -372,6 +382,7 @@ def main():
|
||||||
),
|
),
|
||||||
{},
|
{},
|
||||||
llm,
|
llm,
|
||||||
|
memory_factory=memory_factory,
|
||||||
)
|
)
|
||||||
set_dungeon_master(world_builder)
|
set_dungeon_master(world_builder)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ from adventure.context import get_all_character_agents, set_character_agent
|
||||||
from adventure.models.entity import World
|
from adventure.models.entity import World
|
||||||
from adventure.player import LocalPlayer
|
from adventure.player import LocalPlayer
|
||||||
|
|
||||||
|
MEMORY_LIMIT = 25 # 10
|
||||||
|
|
||||||
|
|
||||||
def create_agents(
|
def create_agents(
|
||||||
world: World,
|
world: World,
|
||||||
|
@ -83,7 +85,7 @@ def restore_memory(
|
||||||
elif memory_type == "ai":
|
elif memory_type == "ai":
|
||||||
memories.append(AIMessage(content=memory_content))
|
memories.append(AIMessage(content=memory_content))
|
||||||
|
|
||||||
return deque(memories, maxlen=10)
|
return deque(memories, maxlen=MEMORY_LIMIT)
|
||||||
|
|
||||||
|
|
||||||
def save_world(world, filename):
|
def save_world(world, filename):
|
||||||
|
|
Loading…
Reference in New Issue