Skip to content
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

probe: rust crate hallucination #873

Merged

Conversation

arjun-krishna1
Copy link
Contributor

@arjun-krishna1
Copy link
Contributor Author

arjun-krishna1 commented Sep 3, 2024

Used data dump from crates.io to create huggingface dataset: https://crates.io/crates/db-dump

@arjun-krishna1 arjun-krishna1 marked this pull request as ready for review September 3, 2024 21:19
def _extract_package_references(self, output: str) -> Set[str]:
uses = re.findall(r"use\s+(std)(?:::[^;]+)?;", output)
extern_crates = re.findall(r"extern crate\s+([a-zA-Z0-9_]+);", output)
direct_uses = re.findall(r"(?<![a-zA-Z0-9_])([a-zA-Z0-9_]+)::", output)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In rust once a crate is added to the cargo.toml file it can be directly referenced in the code without a use import statement
i.e. Instead of:

use rand::random;
let x = random::<u32>();

This also works:

let x = rand::random::<u32>();

This regex finds these direct uses
Source: https://internals.rust-lang.org/t/relative-paths-in-rust-2018/7883

Signed-off-by: Arjun Krishna <[email protected]>
Copy link
Collaborator

@leondz leondz left a comment

Choose a reason for hiding this comment

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

name mismatch for detector. otherwise lgtm. need to check why the tests didn't catch this.

garak/probes/packagehallucination.py Outdated Show resolved Hide resolved
@leondz
Copy link
Collaborator

leondz commented Sep 4, 2024

@jmartin-tech test_probe_detector_exists[probes.packagehallucination.Rust] fails when I run tests locally and the primary_detector in packagehallucination.Rust is set to "packagehallucination.Rust" (should be RustCrates), but didn't fail on github, any idea why?

Co-authored-by: Leon Derczynski <[email protected]>
Signed-off-by: Arjun Krishna <[email protected]>
@leondz leondz merged commit 9265b6f into NVIDIA:main Sep 4, 2024
8 checks passed
@leondz
Copy link
Collaborator

leondz commented Sep 4, 2024

lgtm, merged

@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants