Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting MalformedMessageError from aviary #23

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ repos:
- id: mypy
additional_dependencies:
- fastapi>=0.109 # Match pyproject.toml
- fhaviary
- fhaviary>=0.6 # Match pyproject.toml
- httpx
- litellm>=1.40.9,<=1.40.12 # Match pyproject.toml
- numpy
Expand Down
3 changes: 1 addition & 2 deletions ldp/agent/react_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Any, Self, cast

from aviary.message import Message
from aviary.message import MalformedMessageError, Message
from aviary.tools import Tool, ToolRequestMessage, ToolResponseMessage
from pydantic import BaseModel, ConfigDict, Field
from tenacity import (
Expand All @@ -16,7 +16,6 @@
from ldp.graph.modules.react import (
ACT_DEFAULT_PROMPT_TEMPLATE,
REACT_DEFAULT_PROMPT_TEMPLATE,
MalformedMessageError,
ReActModule,
ToolDescriptionMethods,
)
Expand Down
2 changes: 0 additions & 2 deletions ldp/graph/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from .llm_call import ParsedLLMCallModule
from .react import (
MalformedMessageError,
ReActModule,
ToolDescriptionMethods,
parse_message,
Expand All @@ -15,7 +14,6 @@
from .thought import ThoughtModule

__all__ = [
"MalformedMessageError",
"ParsedLLMCallModule",
"ReActModule",
"ReflectModule",
Expand Down
22 changes: 1 addition & 21 deletions ldp/graph/modules/react.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import ast
import logging
import re
import textwrap
from collections.abc import Iterable
from enum import StrEnum
from typing import Any

from aviary.message import Message
from aviary.message import EMPTY_CONTENT_BASE_MSG, MalformedMessageError, Message
from aviary.tools import Tool, ToolCall, ToolRequestMessage

from ldp.graph.common_ops import FxnOp, PromptOp
Expand Down Expand Up @@ -59,25 +58,6 @@
)


class MalformedMessageError(ValueError):
"""Error to throw if some aspect of a ToolRequestMessage is malformed."""

@classmethod
def react_parser_log_filter(cls, record: logging.LogRecord) -> bool:
"""
Filter out common parsing failures not worth looking into from logs.

Returns:
False if the LogRecord should be filtered out, otherwise True to keep it.
"""
# NOTE: match both this Exception type's name and its content, to be robust
return not all(x in record.msg for x in (cls.__name__, EMPTY_CONTENT_BASE_MSG))


# Define separately so we can filter out this message type
EMPTY_CONTENT_BASE_MSG = "No content in message"


def parse_message(m: Message, tools: list[Tool]) -> ToolRequestMessage: # noqa: C901
"""
Parse an Act or ReAct Message into a ToolRequestMessage.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
dependencies = [
"aiofiles",
"dm-tree",
"fhaviary",
"fhaviary>=0.6", # For MalformedMessageError
"httpx",
"litellm",
"networkx[default]~=3.0", # Pin just to keep recent
Expand Down
Loading