From 5e29fad15ab6a65a31b3cea166276d8db9a0f7a7 Mon Sep 17 00:00:00 2001 From: An Phan Date: Fri, 22 Nov 2024 12:25:21 -0800 Subject: [PATCH 1/3] fix: update DCPA & TCPA knowledge for overtaking --- examples/llamarine/expert-knowledge.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/llamarine/expert-knowledge.txt b/examples/llamarine/expert-knowledge.txt index 6e32aa82b..383ccc38d 100644 --- a/examples/llamarine/expert-knowledge.txt +++ b/examples/llamarine/expert-knowledge.txt @@ -33,7 +33,7 @@ In an overtaking situation, it is important to first identify whether the target --- -## **2. Mastering COLREGs Application combined with DCPA and/or TCPA consideration** +## **2. Mastering COLREGs Application combined with DCPA and TCPA considerations** 1. **“When in doubt, give way—always.”** - If you cannot assess risk or priority clearly, **assume the give-way role** to stay safe. @@ -50,8 +50,8 @@ In an overtaking situation, it is important to first identify whether the target - Meeting a left-crossing? **Stand-on is default**. 5. **"Meeting an overtaking? You must stay clear."** - - If the target ship is overtaking, **Stand-on is default**, unless the following conditions: the DCPA of the own ship and the target ship is shorter than the {safe distance to be overtaken}, and the TCPA of the own ship and the target ship is shorter than the {safe time to be overtaken}, then you must turn in the direction of separation. - - If the own ship is overtaking, **Stand-on is default** for the following conditions: The DCPA of the own ship and the target ship is longer than the {safe distance to overtake}, and the TCPA of the own ship and the target ship is longer than the {safe time to overtake}. + - If the target ship is overtaking, **Stand-on is default**, unless there is a reason not to. The only reason you must turn in the direction of separation in the situation that the target ship is overtaking is that the both following DCPA & TCPA conditions must meet: the DCPA of the own ship and the target ship is shorter than the {safe distance to be overtaken}, and the TCPA of the own ship and the target ship is shorter than the {safe time to be overtaken}. + - If the own ship is overtaking, **Stand-on is default** for both the following DCPA & TCPA conditions: The DCPA of the own ship and the target ship is longer than the {safe distance to overtake}, and the TCPA of the own ship and the target ship is longer than the {safe time to overtake}. --- From bf96672dcc2793177a6ebc2bc6b54b1a0885c3f4 Mon Sep 17 00:00:00 2001 From: An Phan Date: Fri, 22 Nov 2024 23:46:39 -0800 Subject: [PATCH 2/3] refactor: functionalize get solution & answer --- examples/llamarine/app.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/llamarine/app.py b/examples/llamarine/app.py index 0a56cb294..2e4435712 100644 --- a/examples/llamarine/app.py +++ b/examples/llamarine/app.py @@ -40,6 +40,24 @@ os.makedirs(OUTPUT_DIR, exist_ok=True) +def get_solution(problem: str, use_domain_lm: bool = False) -> str: + agent = get_or_create_agent(use_domain_lm) + return agent.solve(problem=problem, allow_reject=True) + + +def get_domain_response(response: str) -> str: + response = OpenAILM.from_defaults().get_response( + prompt=f"""Please respond the following text, with making sure there is a conclusion which is the main action item at the end of the response. + {response} + """, + history=[ + {"role": "system", "content": LLAMARINE_SYSTEM_PROMPT}, + {"role": "user", "content": LLAMARINE_USER_PROMPT}, + ] + ) + return response + + def main(use_domain_lm: bool = False): st.set_page_config(page_title=TITLE, page_icon=None, @@ -85,24 +103,14 @@ def main(use_domain_lm: bool = False): if not st.session_state.agent_solutions[st.session_state.typed_problem] or OVERWRITE: st.session_state.agent_solutions[st.session_state.typed_problem]: str = \ - get_or_create_agent(use_domain_lm).solve( - problem=st.session_state.typed_problem, allow_reject=True) + get_solution(problem=st.session_state.typed_problem, use_domain_lm=use_domain_lm) # write st.session_state.agent_solutions to JSON file with open(file=OUTPUT_FILE_PATH, mode='w', encoding='utf-8') as f: f.write(json.dumps(st.session_state.agent_solutions)) solution = st.session_state.agent_solutions[st.session_state.typed_problem] if use_domain_lm: - solution = OpenAILM.from_defaults().get_response( - prompt=f"""Please respond the following text, with making sure there is a conclusion which is the main action item at the end of the response. - {solution} - """, - history=[ - {"role": "system", "content": LLAMARINE_SYSTEM_PROMPT}, - {"role": "user", "content": LLAMARINE_USER_PROMPT}, - ] - ) - + solution = get_domain_response(response=solution) st.markdown(body=solution) From bac60deab00742299fab611a8b8d671615414f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=20Vinh=20LUONG=20=28L=C6=AF=C6=A0NG=20Th=E1=BA=BF=20Vi?= =?UTF-8?q?nh=29?= Date: Fri, 6 Dec 2024 20:17:30 -0800 Subject: [PATCH 3/3] update Ruff config --- .ruff.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.ruff.toml b/.ruff.toml index b009f3801..6cddee311 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -101,6 +101,7 @@ ignore = [ "PTH118", # `os.path.join()` should be replaced by `Path` with `/` operator "PTH119", # `os.path.basename()` should be replaced by `Path.name` "PTH123", # `open()` should be replaced by `Path.open()` + "PTH208", # use `pathlib.Path.iterdir()` instead "PLC0415", # `import` should be at the top-level of a file "PLR0904", # too many public methods "PLR0917", # too many positional arguments