Skip to content

Commit

Permalink
fix block creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahwooders committed Jan 9, 2025
1 parent dc6bf06 commit 8e325c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
11 changes: 7 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ repos:
- id: check-yaml
exclude: 'docs/.*|tests/data/.*|configs/.*'
- id: end-of-file-fixer
exclude: 'docs/.*|tests/data/.*|letta/server/static_files/.*|.*/.*\.(scss|css|html)'
exclude: 'docs/.*|tests/data/.*|letta/server/static_files/.*'
- id: trailing-whitespace
exclude: 'docs/.*|tests/data/.*|letta/server/static_files/.*'

- repo: local
hooks:
- id: autoflake
name: autoflake
entry: bash -c 'cd apps/core && poetry run autoflake --remove-all-unused-imports --remove-unused-variables --in-place --recursive --ignore-init-module-imports .'
entry: poetry run autoflake
language: system
types: [python]
args: ['--remove-all-unused-imports', '--remove-unused-variables', '--in-place', '--recursive', '--ignore-init-module-imports']
- id: isort
name: isort
entry: bash -c 'cd apps/core && poetry run isort --profile black .'
entry: poetry run isort
language: system
types: [python]
args: ['--profile', 'black']
exclude: ^docs/
- id: black
name: black
entry: bash -c 'cd apps/core && poetry run black --line-length 140 --target-version py310 --target-version py311 .'
entry: poetry run black
language: system
types: [python]
args: ['--line-length', '140', '--target-version', 'py310', '--target-version', 'py311']
exclude: ^docs/
46 changes: 34 additions & 12 deletions tests/integration_test_offline_memory_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from letta import BasicBlockMemory
from letta.client.client import Block, create_client
from letta.client.client import create_client
from letta.constants import DEFAULT_HUMAN, DEFAULT_PERSONA
from letta.offline_memory_agent import (
finish_rethinking_memory,
Expand Down Expand Up @@ -37,14 +37,14 @@ def test_ripple_edit(client, mock_e2b_api_key_none):
trigger_rethink_memory_tool = client.create_or_update_tool(trigger_rethink_memory)
send_message = client.server.tool_manager.get_tool_by_name(tool_name="send_message", actor=client.user)

conversation_human_block = Block(name="human", label="human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
conversation_persona_block = Block(name="persona", label="persona", value=get_persona_text(DEFAULT_PERSONA), limit=2000)
offline_human_block = Block(name="human", label="human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
offline_persona_block = Block(name="persona", label="persona", value=get_persona_text("offline_memory_persona"), limit=2000)
conversation_human_block = client.create_block(label="human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
conversation_persona_block = client.create_block(label="persona", value=get_persona_text(DEFAULT_PERSONA), limit=2000)
offline_human_block = client.create_block(label="human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
offline_persona_block = client.create_block(label="persona", value=get_persona_text("offline_memory_persona"), limit=2000)

# Figure 1. from Evaluating the Ripple Effects of Knowledge Editing in Language Models (Cohen et al., 2023)
# https://arxiv.org/pdf/2307.12976
fact_block = Block(
fact_block = client.create_block(
name="fact_block",
label="fact_block",
value="""Messi resides in the Paris.
Expand All @@ -55,8 +55,27 @@ def test_ripple_edit(client, mock_e2b_api_key_none):
Victor Ulloa plays for Inter Miami""",
limit=2000,
)

new_memory = Block(name="rethink_memory_block", label="rethink_memory_block", value="[empty]", limit=2000)
new_memory = client.create_block(name="rethink_memory_block", label="rethink_memory_block", value="[empty]", limit=2000)

# conversation_human_block = Block(name="human", label="human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
# conversation_persona_block = Block(name="persona", label="persona", value=get_persona_text(DEFAULT_PERSONA), limit=2000)
# offline_human_block = Block(name="human", label="human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
# offline_persona_block = Block(name="persona", label="persona", value=get_persona_text("offline_memory_persona"), limit=2000)

## Figure 1. from Evaluating the Ripple Effects of Knowledge Editing in Language Models (Cohen et al., 2023)
## https://arxiv.org/pdf/2307.12976
# fact_block = Block(
# name="fact_block",
# label="fact_block",
# value="""Messi resides in the Paris.
# Messi plays in the league Ligue 1.
# Messi plays for the team Paris Saint-Germain.
# The national team Messi plays for is the Argentina team.
# Messi is also known as Leo Messi
# Victor Ulloa plays for Inter Miami""",
# limit=2000,
# )
# new_memory = Block(name="rethink_memory_block", label="rethink_memory_block", value="[empty]", limit=2000)
conversation_memory = BasicBlockMemory(blocks=[conversation_persona_block, conversation_human_block, fact_block, new_memory])
offline_memory = BasicBlockMemory(blocks=[offline_persona_block, offline_human_block, fact_block, new_memory])

Expand Down Expand Up @@ -107,10 +126,13 @@ def test_chat_only_agent(client, mock_e2b_api_key_none):
rethink_memory = client.create_or_update_tool(rethink_memory_convo)
finish_rethinking_memory = client.create_or_update_tool(finish_rethinking_memory_convo)

conversation_human_block = Block(name="chat_agent_human", label="chat_agent_human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
conversation_persona_block = Block(
name="chat_agent_persona", label="chat_agent_persona", value=get_persona_text(DEFAULT_PERSONA), limit=2000
)
# conversation_human_block = Block(name="chat_agent_human", label="chat_agent_human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
# conversation_persona_block = Block(
# name="chat_agent_persona", label="chat_agent_persona", value=get_persona_text(DEFAULT_PERSONA), limit=2000
# )

conversation_human_block = client.create_block(label="chat_agent_human", value=get_human_text(DEFAULT_HUMAN), limit=2000)
conversation_persona_block = client.create_block(label="chat_agent_persona", value=get_persona_text(DEFAULT_PERSONA), limit=2000)
conversation_memory = BasicBlockMemory(blocks=[conversation_persona_block, conversation_human_block])

send_message = client.server.tool_manager.get_tool_by_name(tool_name="send_message", actor=client.user)
Expand Down

0 comments on commit 8e325c4

Please sign in to comment.