mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* Updated documentation using ruff's autofix feature * Updated pyproject.toml to include docstring validations * Updated documentation using ruff's autofix feature * Updated pyproject.toml to include docstring validations * Updated docstrings using ruff's autfix feature * Deleted opendevin/runtime/utils/soource.py, Keeping in sync with main --------- Co-authored-by: Graham Neubig <neubig@gmail.com>
68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
from abc import ABC, abstractmethod
|
|
|
|
from opendevin.events.action import Action
|
|
|
|
|
|
class ResponseParser(ABC):
|
|
"""This abstract base class is a general interface for an response parser dedicated to
|
|
parsing the action from the response from the LLM.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
):
|
|
# Need pay attention to the item order in self.action_parsers
|
|
self.action_parsers = []
|
|
|
|
@abstractmethod
|
|
def parse(self, response: str) -> Action:
|
|
"""Parses the action from the response from the LLM.
|
|
|
|
Parameters:
|
|
- response (str): The response from the LLM.
|
|
|
|
Returns:
|
|
- action (Action): The action parsed from the response.
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def parse_response(self, response) -> str:
|
|
"""Parses the action from the response from the LLM.
|
|
|
|
Parameters:
|
|
- response (str): The response from the LLM.
|
|
|
|
Returns:
|
|
- action_str (str): The action str parsed from the response.
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def parse_action(self, action_str: str) -> Action:
|
|
"""Parses the action from the response from the LLM.
|
|
|
|
Parameters:
|
|
- action_str (str): The response from the LLM.
|
|
|
|
Returns:
|
|
- action (Action): The action parsed from the response.
|
|
"""
|
|
pass
|
|
|
|
|
|
class ActionParser(ABC):
|
|
"""This abstract base class is a general interface for an action parser dedicated to
|
|
parsing the action from the action str from the LLM.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def check_condition(self, action_str: str) -> bool:
|
|
"""Check if the action string can be parsed by this parser."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def parse(self, action_str: str) -> Action:
|
|
"""Parses the action from the action string from the LLM response."""
|
|
pass
|