Skip to content

Commit

Permalink
use openssa.l2.resource.abstract.AbstractResource.present_full_answer…
Browse files Browse the repository at this point in the history
…(...) in openssa.l2.reasoning.ooda.OodaReasoner.observe(...)
  • Loading branch information
TheVinhLuong102 committed Apr 27, 2024
1 parent 4a0728f commit 0fe2086
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
22 changes: 7 additions & 15 deletions openssa/l2/reasoning/ooda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from openssa.l2.task.abstract import ATask
from openssa.l2.task.status import TaskStatus

from ._prompts import OBSERVE_PROMPT_TEMPLATE
from ._prompts import ORIENT_PROMPT_TEMPLATE


type Observation = tuple[str, str, str]
type Observation = str


class OrientResult(TypedDict):
Expand All @@ -33,7 +33,7 @@ def reason(self, task: ATask, n_words: int = 1000) -> str:
- Orient & Decide whether such results are adequate for confident answer/solution
- Act to update Task's status and result
"""
observations: list[Observation] = self.observe(task=task, n_words=n_words)
observations: set[Observation] = self.observe(task=task, n_words=n_words)

# note: Orient & Decide steps are practically combined to economize LM calls
orient_result: OrientResult = self.orient(task=task, observations=observations, n_words=n_words)
Expand All @@ -43,21 +43,13 @@ def reason(self, task: ATask, n_words: int = 1000) -> str:

return task.result

def observe(self, task: ATask, n_words: int = 1000) -> list[Observation]:
def observe(self, task: ATask, n_words: int = 1000) -> set[Observation]:
"""Observe results from available Informational Resources."""
return [(r.name, r.overview, r.answer(question=task.ask, n_words=n_words))
for r in task.resources]
return {r.present_full_answer(question=task.ask, n_words=n_words) for r in task.resources}

def orient(self, task: ATask, observations: list[Observation], n_words: int = 1000) -> OrientResult:
def orient(self, task: ATask, observations: set[Observation], n_words: int = 1000) -> OrientResult:
"""Orient whether observed results are adequate for directly resolving Task."""
prompt: str = OBSERVE_PROMPT_TEMPLATE.format(
question=task.ask, n_words=n_words,
resources_and_answers='\n\n'.join((f'INFORMATIONAL RESOURCE #{i + 1} (name: "{name}"):\n'
'\n'
f'INFORMATIONAL RESOURCE #{i + 1} OVERVIEW:\n{overview}\n'
'\n'
f'ANSWER/SOLUTION #{i + 1}:\n{answer}\n')
for i, (name, overview, answer) in enumerate(observations)))
prompt: str = ORIENT_PROMPT_TEMPLATE.format(question=task.ask, n_words=n_words, observations='\n\n'.join(observations)) # noqa: E501
logger.debug(prompt)

def is_valid(orient_result_dict: OrientResult) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions openssa/l2/reasoning/ooda/_prompts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
OBSERVE_PROMPT_TEMPLATE: str = \
ORIENT_PROMPT_TEMPLATE: str = \
"""Assuming that the following question/problem/task is posed
```
{question}
```
and you have received various answers/solutions from different informational resources as detailed below,
and you have observed various answers/solutions from different informational resources as detailed below,
please evaluate whether you can answer/solve the posed question/problem/task confidently with concrete results.
If the question/problem/task mentions any RIGOROUS BASES/CRITERIA/DEFINITIONS for judgement,
the concrete results MUST RESPOND TO SUCH BASES/CRITERIA/DEFINITIONS for the answer/solution to be considered confident.
Expand All @@ -24,6 +24,6 @@
```
{resources_and_answers}
{observations}
```
""" # noqa: E122

0 comments on commit 0fe2086

Please sign in to comment.