Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 20 additions & 12 deletions examples/llamarine/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions examples/llamarine/expert-knowledge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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}.

---

Expand Down