-
Notifications
You must be signed in to change notification settings - Fork 18
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
docs&refactor: clarity improvements #267
Changes from all commits
60bcd75
a6b115a
1c0d8c0
05b943c
7265c7e
f30f3c9
e7dfe17
06bf923
d80105b
27071bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,24 +38,20 @@ def parse_whoami_package(): | |
description="Parse robot whoami package. Script builds a vector store, creates a robot identity and a URDF description." | ||
) | ||
parser.add_argument( | ||
"documentation_root", type=str, help="Path to the root of the documentation" | ||
) | ||
parser.add_argument( | ||
"--output", | ||
type=str, | ||
required=False, | ||
default=None, | ||
help="Path to the output directory", | ||
"whoami_package_root", type=str, help="Path to the root of the whoami package" | ||
) | ||
|
||
args = parser.parse_args() | ||
save_dir = args.output if args.output is not None else args.documentation_root | ||
save_dir = Path(args.whoami_package_root) / "description" / "generated" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, this should adhere to the source / build divide and land in the installation /share folder. I understand there's an issue of cost and, to a lesser degree, build time. But this should not be in sources most likely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually think otherwise. User should be able to modify the generated files to fine-tune them. Creating new identity/vector database every run could increase non-deterministic behaviors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping it as a build artifact does not mean creating a new identity vector database every run, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. Either way I would like to give the users ability to view, modify and git these files. I can agree to a certain point that these files could be seen as build artifacts but I believe, that the current solution is better. Adhering to ROS 2 standard in this case reduces the user friendliness. |
||
description_path = Path(args.whoami_package_root) / "description" | ||
save_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
llm = get_llm_model(model_type="simple_model") | ||
embeddings_model = get_embeddings_model() | ||
|
||
def calculate_urdf_tokens(): | ||
combined_urdf = "" | ||
xacro_files = glob.glob(args.documentation_root + "/urdf/*.xacro") | ||
xacro_files = glob.glob(str(description_path / "urdf" / "*.xacro")) | ||
for xacro_file in xacro_files: | ||
combined_urdf += f"# {xacro_file}\n" | ||
combined_urdf += open(xacro_file, "r").read() | ||
|
@@ -65,26 +61,31 @@ def calculate_urdf_tokens(): | |
def build_urdf_description(): | ||
logger.info("Building the URDF description...") | ||
combined_urdf = "" | ||
xacro_files = glob.glob(args.documentation_root + "/urdf/*.xacro") | ||
xacro_files = glob.glob(str(description_path / "urdf" / "*.xacro")) | ||
for xacro_file in xacro_files: | ||
combined_urdf += f"# {xacro_file}\n" | ||
combined_urdf += open(xacro_file, "r").read() | ||
combined_urdf += "\n\n" | ||
|
||
prompt = "You will be given a URDF file. Your task is to create a short and detailed description of links and joints. " | ||
parsed_urdf = llm.invoke( | ||
[SystemMessage(content=prompt), HumanMessage(content=str(combined_urdf))] | ||
).content | ||
|
||
with open(save_dir + "/robot_description.urdf.txt", "w") as f: | ||
parsed_urdf = "" | ||
if len(combined_urdf): | ||
parsed_urdf = llm.invoke( | ||
[ | ||
SystemMessage(content=prompt), | ||
HumanMessage(content=str(combined_urdf)), | ||
] | ||
).content | ||
|
||
with open(str(save_dir / "robot_description.urdf.txt"), "w") as f: | ||
f.write(parsed_urdf) | ||
logger.info("Done") | ||
|
||
def build_docs_vector_store(): | ||
logger.info("Building the robot docs vector store...") | ||
faiss_index = FAISS.from_documents(docs, embeddings_model) | ||
faiss_index.add_documents(docs) | ||
faiss_index.save_local(save_dir) | ||
faiss_index.save_local(str(save_dir)) | ||
|
||
def build_robot_identity(): | ||
logger.info("Building the robot identity...") | ||
|
@@ -98,7 +99,7 @@ def build_robot_identity(): | |
"Your reply should start with I am a ..." | ||
) | ||
|
||
images = glob.glob(args.documentation_root + "/images/*") | ||
images = glob.glob(str(description_path / "images" / "*")) | ||
|
||
messages = [SystemMessage(content=prompt)] + [ | ||
HumanMultimodalMessage( | ||
|
@@ -109,12 +110,12 @@ def build_robot_identity(): | |
output = llm.invoke(messages) | ||
assert isinstance(output.content, str), "Malformed output" | ||
|
||
with open(save_dir + "/robot_identity.txt", "w") as f: | ||
with open(str(save_dir / "robot_identity.txt"), "w") as f: | ||
f.write(output.content) | ||
logger.info("Done") | ||
|
||
docs = ingest_documentation( | ||
documentation_root=args.documentation_root + "/documentation" | ||
documentation_root=str(description_path / "documentation") | ||
) | ||
documentation = str([doc.page_content for doc in docs]) | ||
n_tokens = len(documentation) // 4.0 | ||
|
@@ -189,15 +190,16 @@ def create_rai_ws(): | |
|
||
(package_path / "documentation").mkdir(exist_ok=True) | ||
(package_path / "images").mkdir(exist_ok=True) | ||
(package_path / "robot_constitution.txt").touch() | ||
(package_path / "generated").mkdir(exist_ok=True) | ||
(package_path / "generated" / "robot_constitution.txt").touch() | ||
|
||
default_constitution_path = ( | ||
"src/rai/rai/cli/resources/default_robot_constitution.txt" | ||
) | ||
with open(default_constitution_path, "r") as file: | ||
default_constitution = file.read() | ||
|
||
with open(f"{package_path}/robot_constitution.txt", "w") as file: | ||
with open(f"{package_path}/generated/robot_constitution.txt", "w") as file: | ||
file.write(default_constitution) | ||
|
||
# Modify setup.py file | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest maybe even getting Create your own robot at top level, followed by developers resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea, let me introduce these changes in the next week, during docs refactoring 🙇🏼♂️