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 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) 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}. ---