Just a Teaser: The Rust Fluent Code Utility

Just a Teaser: The Rust Fluent Code Utility

Rust Fluent Code Utility Exploration ??? 1 - Watch Video

In my previous article , I delved into the practical application of FluentCLI, a powerful tool for code generation. I shared how I used FluentCLI to build data analytics engines in Python, leveraging AI to write the shell script and generate the code.

For the past 6-8 weeks, I've been using this pattern with reasonable success. However, the limits of AI context and output tokens have always been a defining factor. There's only so much you can provide a LLM, and there's only so much they will output. The web chat interfaces have managed to address this issue to some extent with the 'continuation' button, which occasionally appears with a lengthy response. But the same clarity is yet to be achieved through CLI. This has piqued my curiosity, and I'm eager to explore how to incorporate this feature into FluentCLI.

While I'm sure the solution lies in the responses, I haven't yet explored incorporating it into FluentCLI . FluentCLI was my initial solution to the problem. Last year, I embarked on a journey to write full-length books through generative AI, relishing the complexity of the challenge. However, I often found myself resorting to long scripts that invoked multiple LLM calls and appended output to a Txt file through the shell, with results ranging from passable to laughable.

As I delved deeper into writing scaffolds with my AI coding companions, I encountered the inherent challenges of context and output length. These issues became more pronounced as the programs grew in size. At a certain point, the LLM, which was once a powerful tool, started to pose a threat to the effectiveness of the programs. The lost context would alter the outputs, leading to a loss of functionality in elements that were previously working. This was a stark reminder of the limitations of AI in code generation.

Not good. Not good at all. Anti-productive.

I realized early that because FluentCLI works from the shell in the pipeline, language models can be taught to work with it and used to build programs. The data analytics article is one such example. I also created maybe 10-12 crappy games through the process.

It works decently well; I had roughly a 40-50% success rate in just getting little programs to build.

The problem with this is it didn't scale, there weren't good coding practices (version control/linting), and it was press enter and prey, but it worked. It's not something you can do with a working program at all. It only served as an example of a rough scaffold from the system.

This bothered me, and I've devoted every waking minute since writing that article to overcoming this challenge with the Rust Fluent Code Utility (RFCU).

What is the rfcu? It's a wrapper around FluentCLI's amazing power to enhance user and AI coding.

Why? It provides a structured way for AI and Users to work with code structures from the CLI. And it does it in the safest way possible - It evaluates whether linting is successful after any change and then does a git commit if it is, and if not, rolls back the code. It is built to attempt several times (language models can give various results) if the linting fails. It's all built to protect the code's integrity.

Rfcu includes the ability to improve existing code structures. It functions on a structure block level, like functions and modules. It can create unit tests for functions. Add brand new functionality to the file. Document the entire file and individual structures.

If you don't like an output, you can rerun the same command, which will replace it with another response from the language model.

Rust Fluent Code Utility - Adding Functionality to a Program ?? - Watch Video

Rust Fluent Code Utility Overview ??? 3 - Structure Documentation - Watch Video

Let's Walk Through It

This is a basic Rust program that asks a user to enter a value, calculate the quantity of Fibonacci sequences, and quantify the prime numbers in each sequence.

Issuing this command will try to create some unit tests.

echo "create unit tests for this function" | \

rfcu --file_path src/main.rs --mode add_tests_function --structure_name main          

After running that command the following tests were added to the file.

I ran the cargo test on the file and it passed one but failed the other.

It didn't work because the core function Fibonacci wasn't written to deal with no entry or zero.

So we issue this command.

echo 'this doesnt handle 0 or no entry, fix it'  | \

rfcu --file_path src/main.rs --mode improvement --structure_name fibonacci        

The updated the function to this:

And now the tests pass.

Now, let's add some functionality to the little program.

echo 'add 2 ascii graphing functions to later integrate into main' | \

rfcu --file_path src/main.rs --mode add_functionality           

That created:

And then, we run one more command to ask for those functions to be integrated into the main.

echo 'integrate the 2 graphing functions into main' | \

rfcu --file_path src/main.rs --mode improvement --structure_name main          

That updated the main function and included the new functions.

Then, I wanted to document that function, so I ran the following.

echo 'add brief documentation for this function' | \

rfcu --file_path src/main.rs --mode documentation_structure --structure_name graph_fibonacci        

And that output the following.

This is just a teaser for what's to come. I wanted to give a structured way for LLM to work with code and FluentCLI. I've done it at least at the initial rudimentary level.

Wait until I show examples of language models writing scripts to write programs using rfcu and FluentCLI. This little tool set can overcome many of the limitations I've mentioned at the start of the article.

This is the first tool I've shown what's possible to do when wrapping FluentCLI's power and functionality. This could be easily injected into any pipeline or any CLI-invoked application.

It's amazing what's possible with structured LLM integration with the shell.

There are big things to come. The Rfcu works with RustLang right now. It is built using Tree Sitter . I plan to extend it to other supported languages, too. Python is next.


要查看或添加评论,请登录

社区洞察

其他会员也浏览了