File size: 1,029 Bytes
e8be1d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
tags:
- deepsparse
---

```python
from deepsparse import TextGeneration
model = TextGeneration(model="hf:mgoin/Nous-Hermes-llama-2-7b-ds")
prompt="""### Instruction:
Write a Perl script that processes a log file and counts the occurrences of different HTTP status codes. The script should accept the log file path as a command-line argument and print the results to the console in descending order of frequency.

### Response:
"""
print(model(prompt, max_new_tokens=500).generations[0].text)
```

Output: 
```
#!/usr/bin/perl

use strict;
use warnings;

my $log_file = $ARGV[0];

open(my $fh, '<', $log_file) or die "Could not open file '$log_file' $!";

my %status_count;

while (my $line = <$fh>) {
    chomp $line;

    my @status_codes = split(/\s+/, $line);

    for my $status_code (@status_codes) {
        $status_count{$status_code}++;
    }
}

close($fh);

foreach my $status_code (sort { $status_count{$b} <=> $status_count{$a} } keys %status_count) {
    print "$status_code: $status_count{$status_code}\n";
}
```