Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```python
|
2 |
+
from deepsparse import TextGeneration
|
3 |
+
prompt='### Instruction:\nWrite 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.\n\n### Response:\n'
|
4 |
+
model = TextGeneration(model="hf:neuralmagic/zephyr-7b-beta-pruned50-quant-ds")
|
5 |
+
print(model(prompt, max_new_tokens=200).generations[0].text)
|
6 |
+
"""
|
7 |
+
Here's a Perl script that meets the requirements:
|
8 |
+
|
9 |
+
```perl
|
10 |
+
use strict;
|
11 |
+
use warnings;
|
12 |
+
|
13 |
+
sub get_status_code {
|
14 |
+
my ($status) = ();
|
15 |
+
my ($match) = qr/\s*\d{3}\s*$/;
|
16 |
+
return $1 if ($status =~ $match);
|
17 |
+
}
|
18 |
+
|
19 |
+
sub count_occurrences {
|
20 |
+
my ($file) = shift;
|
21 |
+
my (%counts) = ();
|
22 |
+
open my $fh, '<', $file or die "Can't open $file: $!";
|
23 |
+
while (my $line = <$fh>) {
|
24 |
+
my ($status) = get_status_code($line);
|
25 |
+
$counts{$status}++;
|
26 |
+
}
|
27 |
+
close $fh;
|
28 |
+
return \%counts;
|
29 |
+
}
|
30 |
+
|
31 |
+
my ($file) = shift;
|
32 |
+
my (@codes) = qw(200 300 400 500);
|
33 |
+
my (@sorted) = ();
|
34 |
+
|
35 |
+
foreach my ($status, $count) (@codes, \%{ $status }->value()) {
|
36 |
+
push @sorted, [$count, $status];
|
37 |
+
}
|
38 |
+
|
39 |
+
foreach my ($code, $freq) (@sorted) {
|
40 |
+
print "$code\t$freq\n";
|
41 |
+
}
|
42 |
+
|
43 |
+
my ($results) = count_occurrences($file);
|
44 |
+
my (@sorted) = sort { $b[1] <=> $a[1] } @{$results};
|
45 |
+
foreach my ($code, $freq) (@sorted) {
|
46 |
+
print "$code\t$freq\n";
|
47 |
+
}
|
48 |
+
```
|
49 |
+
"""
|
50 |
+
```
|