Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Japanese HTP+OODAR example #289 #298

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions examples/japanese-easy-demo/main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
from pathlib import Path
from dotenv import load_dotenv
from openssa import OodaSSA, TaskDecompositionHeuristic

from openssa import Agent, FileResource

load_dotenv()


LOCAL_CACHE_DOCS_DIR_PATH: Path = Path(__file__).parent / '.data'
JAPANESE_DEMO_HEURISTICS: str = (
'Please answer in Japanese.'
'Pay attention to the total salt content, calories, and total vegetables.'
)


def get_or_create_ooda_ssa() -> OodaSSA:
ssa = OodaSSA(task_heuristics=TaskDecompositionHeuristic({}),
highest_priority_heuristic=JAPANESE_DEMO_HEURISTICS,
enable_generative=True)
ssa.activate_resources(LOCAL_CACHE_DOCS_DIR_PATH)
return ssa
def get_or_create_agent() -> Agent:
return Agent(
resources={FileResource(path=LOCAL_CACHE_DOCS_DIR_PATH)}
)


def solve(question) -> str:
ooda_ssa = get_or_create_ooda_ssa()
agent = get_or_create_agent()
try:
return ooda_ssa.solve(question)

return agent.solve(problem=question)
except Exception as err: # pylint: disable=broad-exception-caught
return f'ERROR: {err}'

Expand All @@ -35,6 +26,7 @@ def solve(question) -> str:
'Please tell me three dishes you recommend.'
'Please limit the total salt content of the three dishes to less than 21.5g.'
'Also, please make sure that the total amount of vegetables in the three dishes is at least 700g.'
'Please answer in Japanese.'
)
answer = solve(QUESTION)

Expand Down