adding support for input interpolation for tasks and agents

This commit is contained in:
João Moura
2024-02-28 02:59:58 -03:00
parent 45ea5ccef0
commit 38ceb9d409
4 changed files with 49 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import threading
import uuid
from typing import Any, List, Optional, Type
from typing import Any, Dict, List, Optional, Type
from langchain_openai import ChatOpenAI
from pydantic import UUID4, BaseModel, Field, field_validator, model_validator
@@ -173,6 +173,12 @@ class Task(BaseModel):
tasks_slices = [self.description, output]
return "\n".join(tasks_slices)
def interpolate_inputs(self, inputs: Dict[str, Any]) -> None:
"""Interpolate inputs into the task description and expected output."""
self.description = self.description.format(**inputs)
if self.expected_output:
self.expected_output = self.expected_output.format(**inputs)
def increment_tools_errors(self) -> None:
"""Increment the tools errors counter."""
self.tools_errors += 1