Skip to content

verdi llm cli, AiiDA users benefit from LLM; a proof of concept. #6834

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

khsrali
Copy link
Contributor

@khsrali khsrali commented Apr 24, 2025

For now, it only works with Groq, because it provides free API.
More backends will be added later.

First, configure for once:
verdi llm configure --backend groq --api-key <API-KEY> -- to generate a key see here

Now you can ask whatever you want, the limit is your imagination 🤞
$ verdi llm cli 'list all processes'

It will then, respond with a generated command and asks for a confirmation (e) before executing it.

$ verdi llm cli 'list all processes'
Generated command: `verdi process list`

Execute[e], Modify[m], or Cancel[c]:: e
$ verdi process list
Command output:

  PK  Created    Process label             ♻    Process State    Process status
----  ---------  ------------------------  ---  ---------------  -----------------------------------------------------------------------------------
7064  77D ago    ArithmeticAddCalculation       ⏵ Waiting        Waiting for transport task: stash

Alternatively the user has the option (m) to edit the command before executing, to fix mistakes:

$ verdi llm cli 'list all processes'
Generated command: `verdi process list`

Execute[e], Modify[m], or Cancel[c]:: m
Please modify the command:: `verdi group list` # my edit
$ verdi group list # my edit
Command output:

  PK  Created    Process label             ♻    Process State    Process status
----  ---------  ------------------------  ---  ---------------  -----------------------------------------------------------------------------------
7064  77D ago    ArithmeticAddCalculation       ⏵ Waiting        Waiting for transport task: stash

Groq is not trained on AiiDA so the outcome is not gonna be magnificent. This PR provide an interface, for future implementation of a trained model. See project: PLACEHOLER

An ideal model after training will be able to answer to such commands:

$ verdi llm cli 'delete are groups with label qe*'
Generated command: `verdi group delete --startswith qe`

OR

$ verdi llm cli 'list all processes I've created since 5 min ago'
Generated command: `verdi process list -p 1 -a | grep -E  '1m|2m|3m|4m|5m'`

The latest one is a nice example. Although the only supported flag for timely listing is --past-days; such a smart interface can first, find out there's no official command to support that, and second, would be able to suggest a workaround.

Although the interface is not finalized, early reviews and discussions are welcome.

UPDATE:

RAG added. Now it's able to answer to use more flags to response precisely:

$verdi llm cli 'list my latest process that finished, show only one result'
Generated command: `verdi process list -O id -D desc -S finished -l 1`

@khsrali khsrali changed the title An smart CLI, a proof of concept for LLM use-case in AiiDA smart cli, a proof of concept for LLM use-case in AiiDA Apr 24, 2025
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 27.10280% with 78 lines in your changes missing coverage. Please review.

Project coverage is 78.17%. Comparing base (48bd2ac) to head (d7cb3df).

Files with missing lines Patch % Lines
src/aiida/cmdline/commands/cmd_smart/cmd_smart.py 26.14% 65 Missing ⚠️
...rc/aiida/cmdline/commands/cmd_smart/llm_backend.py 23.53% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6834      +/-   ##
==========================================
- Coverage   78.29%   78.17%   -0.12%     
==========================================
  Files         566      569       +3     
  Lines       42764    42871     +107     
==========================================
+ Hits        33479    33508      +29     
- Misses       9285     9363      +78     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@khsrali khsrali changed the title smart cli, a proof of concept for LLM use-case in AiiDA verdi smart cli, AiiDA users benefit from LLM; a proof of concept. Apr 24, 2025
@edan-bainglass
Copy link
Member

edan-bainglass commented Apr 28, 2025

Proposed names:

  • verdi sebastiaan
  • verdi seb
  • verdi huber

@khsrali
Copy link
Contributor Author

khsrali commented May 1, 2025

@giovannipizzi
How about verdi chat?

@giovannipizzi
Copy link
Member

verdi chatbot? Makes more the sense it's a bot replying

@khsrali
Copy link
Contributor Author

khsrali commented May 1, 2025

Also verdi chatbot is also nice, only the command gets a bit lengthier though.
So one has to type more to get there.. in a sense 🙃

@khsrali khsrali changed the title verdi smart cli, AiiDA users benefit from LLM; a proof of concept. verdi llm cli, AiiDA users benefit from LLM; a proof of concept. May 8, 2025
Copy link
Contributor

@agoscinski agoscinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to create the verdi_cli.json when the command is first time invoked instead so we don't blow up the src code (for review it is great to see it). Then you could cache the embedding (maybe repository)?


Why don't you include the description of the options of the commands in the verdi_cli.json? For example, for verdi process kill --help:

-a, --all                       Kill all processes if no specific processes
                                  are specified.

Seems like useful information.


Maybe we instead of letting the user to create the embedding, we upload them for each aiida version so the user never needs any llm package, the user just needs to download it from an external resource. That would make the user's life easier. It behaves then more like RTD.

with open(self.json_path, 'r') as f:
self.data = json.load(f)

self.model = SentenceTransformer('all-MiniLM-L6-v2', device='cpu')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should try to detect gpu, if not then go to cpu

'chardet~=5.2.0;platform_system=="Windows"'
'chardet~=5.2.0;platform_system=="Windows"',
'faiss-cpu~=1.11',
'sentence_transformers~=4.1'
Copy link
Contributor

@agoscinski agoscinski May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be an optional dependencies! Or maybe we can completely remove it (see third point of my comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants