mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
* Fix nested pydantic model issue * fix failing tests * add in vcr * cleanup * drop prints * Fix vcr issues * added new recordings * trying to fix vcr * add in fix from lorenze.
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Any, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class OutputConverter(BaseModel, ABC):
|
|
"""
|
|
Abstract base class for converting task results into structured formats.
|
|
|
|
This class provides a framework for converting unstructured text into
|
|
either Pydantic models or JSON, tailored for specific agent requirements.
|
|
It uses a language model to interpret and structure the input text based
|
|
on given instructions.
|
|
|
|
Attributes:
|
|
text (str): The input text to be converted.
|
|
llm (Any): The language model used for conversion.
|
|
model (Any): The target model for structuring the output.
|
|
instructions (str): Specific instructions for the conversion process.
|
|
max_attempts (int): Maximum number of conversion attempts (default: 3).
|
|
"""
|
|
|
|
text: str = Field(description="Text to be converted.")
|
|
llm: Any = Field(description="The language model to be used to convert the text.")
|
|
model: Any = Field(description="The model to be used to convert the text.")
|
|
instructions: str = Field(description="Conversion instructions to the LLM.")
|
|
max_attempts: int = Field(
|
|
description="Max number of attempts to try to get the output formatted.",
|
|
default=3,
|
|
)
|
|
|
|
@abstractmethod
|
|
def to_pydantic(self, current_attempt=1):
|
|
"""Convert text to pydantic."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def to_json(self, current_attempt=1):
|
|
"""Convert text to json."""
|
|
pass
|