Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
waleko committed Jul 10, 2024
1 parent 392c745 commit 13080a8
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions code_editing/utils/file_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
class MyFileCallbackHandler(BaseCallbackHandler):
"""Callback Handler that writes to a file."""

def __init__(
self, filename: str, mode: str = "a", color: Optional[str] = None
) -> None:
def __init__(self, filename: str, mode: str = "a", color: Optional[str] = None) -> None:
"""Initialize callback handler."""
self.file = cast(TextIO, open(filename, mode, encoding="utf-8"))
self.color = color
Expand All @@ -21,9 +19,7 @@ def __del__(self) -> None:
"""Destructor to cleanup when done."""
self.file.close()

def on_chain_start(
self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any
) -> None:
def on_chain_start(self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) -> None:
"""Print out that we are entering a chain."""
class_name = serialized.get("name", serialized.get("id", ["<unknown>"])[-1])
print_text(
Expand All @@ -41,9 +37,7 @@ def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None:
outputs_str = pprint_dict(outputs)
print_text(outputs_str, file=self.file, end="\n")

def on_agent_action(
self, action: AgentAction, color: Optional[str] = None, **kwargs: Any
) -> Any:
def on_agent_action(self, action: AgentAction, color: Optional[str] = None, **kwargs: Any) -> Any:
"""Run on agent action."""
print_text(action.log, color=color or self.color, file=self.file)

Expand All @@ -62,15 +56,11 @@ def on_tool_end(
if llm_prefix is not None:
print_text(f"\n{llm_prefix}", file=self.file)

def on_text(
self, text: str, color: Optional[str] = None, end: str = "", **kwargs: Any
) -> None:
def on_text(self, text: str, color: Optional[str] = None, end: str = "", **kwargs: Any) -> None:
"""Run when agent ends."""
print_text(text, color=color or self.color, end=end, file=self.file)

def on_agent_finish(
self, finish: AgentFinish, color: Optional[str] = None, **kwargs: Any
) -> None:
def on_agent_finish(self, finish: AgentFinish, color: Optional[str] = None, **kwargs: Any) -> None:
"""Run on agent end."""
print_text(finish.log, color=color or self.color, end="\n", file=self.file)

Expand All @@ -79,11 +69,11 @@ def pprint_dict(d, indent=0, step=2) -> str:
res = ""
if isinstance(d, dict):
for key, value in d.items():
res += (' ' * indent + str(key) + ':') + '\n'
res += (" " * indent + str(key) + ":") + "\n"
res += pprint_dict(value, indent + step)
elif isinstance(d, list):
for item in d:
res += pprint_dict(item, indent + step)
else:
res += (' ' * indent + str(d)) + '\n'
res += (" " * indent + str(d)) + "\n"
return res

0 comments on commit 13080a8

Please sign in to comment.