Menu
in

Exploring my journey with Chat GPT and Speckle technology #AI

Summarise this content to 300 words

Last time, I demonstrated how to use AI and basic programming skills to write a functional, albeit simple, program. This time, I will not dive as deeply into the code but will focus more on the process and the main challenges I encountered. Let’s start with the basics — scalability.

“Think First, Then Write”

Writing code with the help of AI is more challenging than it may seem at first glance. At some point, you get tired of composing or correcting requests, and end up writing the code yourself because the machine doesn’t understand you or your requests. The issue often isn’t just the complexity of the task you’re addressing with AI. More frequently, the problem lies in the fact that your code is no longer a single function or module but rather includes dozens of modules and various libraries. In such a situation, it’s challenging to delegate everything to the machine to solve and correct on your behalf. Simply put, AI has limitations in the amount of information it can process. This is exactly what happened in my case.

Realizing that my code, written in a single script, had become unreadable, I began breaking it down into modules, applying the “clean architecture” approach. This allowed me to distribute the application logic in a way that made it easier for the AI to understand and work with requests to add “functions.” AI needs specific parts of the code for specific tasks, avoiding unnecessary code not related to the current request.

Names Matter

There’s a saying, “A ship will sail as you name it.” In our case, this applies to arguments, functions, classes, and so on. Names indeed influence the code. Honestly, I consider it a separate art to name variables correctly. At some point, I started getting confused with the names. The reason is simple: in the early stages, I didn’t pay enough attention to this, resulting in what can be called a semantic inconsistency. What a function did or what an argument contained did not match its name. In other words, it turned into a mess.

Here’s an example from my code: I have a function check_last_commit_section_names that checks the names of elements based on specified parameters. Another function, check_option, also performs checks. Instead of options, it verifies what kind of check the user wants to perform. This is straightforward: if it says check, it means something is being verified. But this logic falls apart when we get to another function, check_start. Can you guess what it does? The answer is simple: it marks a word with a checkmark if it passes the validation.

Why check? Why start? This was how the AI decided based on my code, and I simply copied and pasted the suggested parts. I’m sure there was a reason behind it, but these small inconsistencies accumulated, and the code became unreadable. I had to refactor everything, and the process was far from quick.

This peak represents the number of commits I made in just one week. A significant portion of these commits was solely related to renaming functions and arguments.

How It All Works and What It Can Do

But I digress from the main topic. What can my solution do, and why is it needed?

Initially, the program, as I mentioned earlier, was created to solve a very specific task. The task was so specialized that it would be understood by very few. Nevertheless, I’ll share and explain what it is about.

To begin with, let’s look at the overall architecture of Checker_AI.

The program update includes a database and authentication with Speckle, as well as a user interaction menu. Since I chose the command line as the main interface, I needed an external library. I selected the rich library, which helped me create a more user-friendly menu than if I had tried to display it myself.

Here’s the project menu that appears when I start the program. It’s a standard menu displaying all the projects connected to my account. By the way, there’s no need to log in manually: if you’re logged into Speckle using the Speckle Connector, authorization is automatic.

Project Information Display

After selecting a project, the user is greeted with a menu of verification modules. As I mentioned before, the modular design allows me to flexibly expand this part of the menu according to my needs.

To be honest, I enjoy the menu created in the CLI. It makes you feel like Hackerman from Kung Fury in the eyes of others, especially when you say, “Let me check your object now.”

Sure, go ahead and provide the text or the specific information you want to be translated and adapted for an English-speaking audience.

Here is the information I need. By slightly editing the code, I can change and expand the output data as desired. Here is an example:

I’ve now added the ability to display all branches in the project, as well as the ability to display general information and apartment types.

def print_total_summary(all_commits_data):  
total_elements = sum(
commit_data['object_count'] for commit_data in all_commits_data)
total_rooms = sum(
commit_data['room_count'] for commit_data in all_commits_data)

total_room_types = {}
for commit_data in all_commits_data:
for room_type, count in commit_data['room_types'].items():
total_room_types[room_type] = total_room_types.get(room_type,
0) + count

print(f"{'Overall Total:':-^35}")
print(f"{'Number of elements:':<25} {total_elements}")
print(f"{'Number of rooms:':<25} {total_rooms}")
print(f"{'Apartment Types':-^35}")
for room_type, count in total_room_types.items():
print(f"{room_type} - {count}")
print("******************************")

The code is far from perfect; I would say there’s a lot to improve, but it gets the job done. For instance, it would be better to store the data instead of making a request every time. Maybe I’ll fix it someday.

Checks for Potential Matches

In my opinion, this is the most interesting and simultaneously the most challenging check. The term “potential match” might not be immediately clear from the name. Here, I’ll try to explain the issue.

There is a concept known as “homoglyphs” — these are characters that look identical or very similar to each other but have different meanings. Visually, you might see one symbol, but in reality, it could belong to a different alphabet or set of characters.

Here is a table with letters resembling the Cyrillic “Х” from alphabets used in the 21st century, along with their Unicode codes and examples of countries that use these alphabets:

| Alphabet      | Letter | Unicode | Countries                     |
| ------------- | ------ | ------- | ----------------------------- |
| Cyrillic | Х | U+0425 | Russia, Bulgaria, Kazakhstan |
| Greek | Χ | U+03A7 | Greece |
| Latin | X | U+0058 | USA, UK, Germany |

These characters look similar to the Cyrillic letter “Х” and are used in modern languages and alphabets. However, they have different Unicode codes, which can cause issues later on.

Let’s move on to examples:

Suppose a designer names a room “3М”. Imagine this person is from a country that uses Cyrillic or Latin script. Meanwhile, another person (possibly from another country) in a different building of the same project labels a similar room as “3M”. And here’s where the fun begins. For Revit and all other programs, these will be different rooms. Why? In the first case, Unicode U+041C (Cyrillic М) is used, and in the second case, Unicode U+004D (Latin M) is used.

For this reason, I wrote simple checks that validate the Unicode of the characters entered by the user. Here’s what this validation looks like:

As you can see, it’s easy to get confused. One might mistakenly use Cyrillic instead of Latin characters, and vice versa. In a unique case, I even had a space recorded in the name, which displayed as “Undefined.”

Rounding Check

To understand the need for this check, you first need to grasp the problem within Revit itself. If you examine the list of rooms, you may notice that, in some cases, the rounded values presented in Revit’s specifications do not match the total sums. This discrepancy can lead to inconsistencies in some values, which may cause issues in subsequent stages of the design process.

Now, let’s take a look at rounding and calculations:

More details about this paradox are explained here.

To solve this issue, we developed our own “rounding tool.” However, it needs to be run every time, and the user might forget to do so. In such cases, we need to check whether the user has run our “rounding” script or not.

Here is an example: the script highlights a room that the designer forgot to “update” through it.

Area in Revit is the system-calculated area in Revit, while Rounded Area is the updated area calculated by the script. My check verifies each room for rounding. If the rounding has not been performed, an error is displayed, as shown above.

What’s Next

At this point, I need to pause. I’ve written numerous other specific checks, and the program has become an indispensable assistant in daily work. From now on, I can identify calculation errors at any given moment.

This small script was a first step toward more comprehensive checks, which we have already implemented. However, I’m sharing my journey into the world of automation with you piece by piece.

Thank you for reading!

Source link

Source link: https://medium.com/@Eleron/behind-the-screens-my-journey-with-chat-gpt-and-speckle-99449d053bd9?source=rss——ai-5

Leave a Reply

Exit mobile version