Skip to content

Commit

Permalink
chore: fix get_next cypher (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
acazau authored Jul 11, 2024
1 parent 5c562ab commit 7c7a286
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hybridagi/hybridstores/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def get_next(self, content_index: str) -> str:
"""Method to return the next content index"""
params = {"index": content_index}
result = self.hybridstore.query(
'MATCH (:Content {name:index})-[:NEXT]->(n:Content) RETURN n',
'MATCH (:Content {name:$index})-[:NEXT]->(n:Content) RETURN n',
params = params,
)
if len(result.result_set) > 0:
Expand Down
53 changes: 53 additions & 0 deletions tests/tools/test_read_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import dspy
from hybridagi.tools import ReadFileTool
from dspy.utils.dummies import DummyLM
from hybridagi.hybridstores.filesystem.filesystem import FileSystem
from hybridagi.embeddings.fake import FakeEmbeddings
from hybridagi import AgentState

def test_read_file_tool():
# Set up the test environment
embeddings = FakeEmbeddings(dim=250)

# Create test files
test_files = {
"/home/user/test1.txt": "This is the content of test1.txt",
"/home/user/test2.txt": "This is the content of test2.txt",
}

filesystem = FileSystem(
index_name="test",
embeddings=embeddings,
wipe_on_start=True,
)

# Add test files to the filesystem
for filename, content in test_files.items():
filesystem.add_texts(
texts=[content],
ids=[filename],
)

agent_state = AgentState()

dspy.settings.configure(lm=DummyLM(answers=["/home/user/test1.txt", "/home/user/test2.txt"]))

# Create the ReadFileTool
tool = ReadFileTool(
filesystem=filesystem,
agent_state=agent_state,
)

# Test reading existing files
for filename, expected_content in test_files.items():
expected_content = f"{expected_content}\n\n{{'filename': '{filename}'}}"
prediction = tool(
objective="Read file content",
context="Testing ReadFileTool",
purpose="Verify file reading",
prompt=f"Read the file {filename}",
disable_inference=False,
)

assert prediction.filename == filename, f"Filename mismatch for {filename}"
assert prediction.content == expected_content, f"Content mismatch for {filename}"

0 comments on commit 7c7a286

Please sign in to comment.