Separated internal output model from suplied model, and fixed a parsing bug of Enum fields

This commit is contained in:
guybensimhon1
2025-03-06 19:40:28 +02:00
parent d5cab0a9e4
commit dc24574e7c

View File

@@ -1,5 +1,6 @@
import asyncio
import json
import enum
import logging
from typing import Dict, Generic, Optional, Type, TypeVar
@@ -44,8 +45,9 @@ class Controller(Generic[Context]):
if output_model is not None:
# Create a new model that extends the output model with success parameter
class ExtendedOutputModel(output_model): # type: ignore
class ExtendedOutputModel(BaseModel): # type: ignore
success: bool = True
data: output_model
@self.registry.action(
'Complete task - with return text and if the task is finished (success=True) or not yet completly finished (success=False), because last step is reached',
@@ -53,7 +55,13 @@ class Controller(Generic[Context]):
)
async def done(params: ExtendedOutputModel):
# Exclude success from the output JSON since it's an internal parameter
output_dict = params.model_dump(exclude={'success'})
output_dict = params.data.model_dump()
# Enums are not serializable, convert to string
for key, value in output_dict.items():
if isinstance(value, enum.Enum):
output_dict[key] = value.value
return ActionResult(is_done=True, success=params.success, extracted_content=json.dumps(output_dict))
else: