|
1 | 1 | import os |
| 2 | +import shutil |
2 | 3 | from typing import Any, Literal |
3 | 4 |
|
4 | 5 | import bgym |
5 | 6 | import datasets |
| 7 | +from pydantic import Field |
| 8 | +from tapeagents.core import Observation, StopStep, Thought |
6 | 9 | from tapeagents.environment import ContainerExecutor |
7 | 10 | from tapeagents.tools.browser import Browser |
8 | 11 | from tapeagents.tools.code_executor import CodeExecutor |
@@ -68,3 +71,60 @@ def init_code_sandbox(self) -> None: |
68 | 71 | stop_container=False, |
69 | 72 | no_deps=True, |
70 | 73 | ) |
| 74 | + |
| 75 | + |
| 76 | +class ExtractedFacts(Thought): |
| 77 | + """ |
| 78 | + Thought that contains the list of facts extracted from the document |
| 79 | + """ |
| 80 | + |
| 81 | + kind: Literal["extracted_facts_thought"] = "extracted_facts_thought" |
| 82 | + extracted_facts: list[str] | dict[str, Any] | str = Field( |
| 83 | + description="facts extracted from the observation" |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +class GaiaQuestion(Observation): |
| 88 | + kind: Literal["question"] = "question" |
| 89 | + content: str |
| 90 | + filename: str | None = None |
| 91 | + |
| 92 | + @classmethod |
| 93 | + def from_task(cls, question: dict): |
| 94 | + question_prompt = question["Question"] |
| 95 | + filename = None |
| 96 | + if question["file_name"]: |
| 97 | + basename = os.path.basename(question["file_name"]) |
| 98 | + tmp_fname = f"/tmp/{basename}" |
| 99 | + shutil.copyfile(question["file_name"], tmp_fname) |
| 100 | + assert os.path.exists(tmp_fname) |
| 101 | + filename = tmp_fname |
| 102 | + return cls(content=question_prompt, filename=filename) |
| 103 | + |
| 104 | + |
| 105 | +class GaiaAnswer(StopStep): |
| 106 | + """ |
| 107 | + Action that indicates the agent has finished the plan and contains the answer or description of failure. |
| 108 | + The answer should use already determined facts without additional conversion! |
| 109 | + Your final answer should be a number OR as few words as possible OR a comma-separated list of numbers and/or strings. |
| 110 | + ADDITIONALLY, your final answer MUST follow any formatting instructions specified in the original question (e.g., alphabetization, sequencing, units, rounding, decimal places, etc.) |
| 111 | + If asked for a number, express it numerically, don't use commas, do not add anything after the number, don't include units such as $ or percent signs unless specified otherwise in the question. |
| 112 | + If asked for a string, don't use articles or abbreviations (e.g. for cities), unless specified otherwise. Don't output any final sentence punctuation such as '.', '!', or '?'. |
| 113 | + If asked for a comma-separated list, apply the above rules depending on whether the elements are numbers or strings. |
| 114 | + If unable to determine the final answer, output an empty string. |
| 115 | + """ |
| 116 | + |
| 117 | + kind: Literal["gaia_answer_action"] = "gaia_answer_action" |
| 118 | + success: bool = Field( |
| 119 | + description="True if the task was successful, False otherwise" |
| 120 | + ) |
| 121 | + overview: str = Field( |
| 122 | + description="List of steps performed to answer the question. If the task was not successful, includes the reason for failure" |
| 123 | + ) |
| 124 | + answer_unit: str = Field( |
| 125 | + description="Unit of measurement for the answer, if applicable; otherwise an empty string" |
| 126 | + ) |
| 127 | + answer: Any = Field(description="Short final answer") |
| 128 | + long_answer: str = Field( |
| 129 | + description="Detailed final answer not restricted by format rules" |
| 130 | + ) |
0 commit comments