Hacker News new | ask | show | jobs
by mempko 589 days ago
I use Raku in production. It's the best language to deal with text because building parsers so so damn nice. I'm shocked this isn't the top language to create an LLM text pipeline.
2 comments

Very late to the thread, but I was wondering if you knew of a good example of Raku calling an API over https, polling the API until it returns a specific value?
Here is one way:

    use HTTP::UserAgent;
    use JSON::Fast;

    my $url = 'https://api.coindesk.com/v1/bpi/currentprice.json';

    my $ua = HTTP::UserAgent.new;

    my $total-time = 0;
    loop {
        my $response = $ua.get($url);
        if $response.is-success {
            my $data = from-json $response.content;
            my $rate = $data<chartName>;
            say "Current chart name: $rate";
            #last if $rate eq 'Bitcoin';
            last if $total-time ≥ 16;
        }
        else {
            say "Failed to fetch data: {$response.status-line}";
        }
        sleep 3; # Poll every 3 seconds
        $total-time += 3;
    }
(Tweak / uncomment / rename the $rate variable assignments and checks.)
Wow, huge thanks, that's super helpful :)
Sure, good luck!
Do you use any of Raku's LLM packages? If yes, which ones?
I have not used any. What are some good ones to look at?