jglowa commited on
Commit
a0be26c
verified
1 Parent(s): 282e004

Update prosty-rag.cmd

Browse files
Files changed (1) hide show
  1. prosty-rag.cmd +21 -21
prosty-rag.cmd CHANGED
@@ -1,50 +1,50 @@
1
- echo \" >/dev/null ">NUL "\" \`" <#"
2
- :; # Prosty RAG v0.3 - Jerzy G艂owacki na licencji Apache 2.0
 
 
 
 
 
 
 
 
 
 
3
  :; # *NIX:
4
- :; llamafile="prosty-rag.llamafile"
5
- :; embedfile="bge-m3.embedfile"
6
- :; dbfile="prosty-rag.db"
7
- :; indeksator="indeksator.cmd"
8
- :; logfile="prosty-rag.log"
9
- :; prompt="Jeste艣 pomocnym asystentem. Odpowiedz na pytania u偶ytkownika korzystaj膮c z podanego kontekstu, zawieraj膮cego wybrane fragmenty plik贸w. Na ko艅cu podaj odwo艂anie do pliku 藕r贸d艂a. Je艣li nie potrafisz odpowiedzie膰, to napisz to. Nie zmy艣laj."
10
  :; # Instalacja
11
  :; [ ! -f $llamafile ] && echo Pobieranie $llamafile... && curl -Lo $llamafile https://huggingface.co/jglowa/prosty-rag/resolve/main/prosty-rag.llamafile?download=true && chmod +x $llamafile && echo Gotowe!
 
12
  :; [ ! -f $embedfile ] && echo Pobieranie $embedfile... && curl -Lo $embedfile https://huggingface.co/asg017/embedfile/resolve/refs%2Fpr%2F2/bge-m3.embedfile?download=true && chmod +x $embedfile && echo Gotowe!
13
  :; [ ! -f $indeksator ] && echo Pobieranie $indeksator... && curl -Lo $indeksator https://huggingface.co/jglowa/prosty-rag/resolve/main/indeksator.cmd?download=true && chmod +x $indeksator && echo Gotowe!
14
  :; [ ! -f $dbfile ] && ./$indeksator
15
  :; # Uruchamianie
16
  :; >$logfile
17
  :; echo "Uruchamianie serwera embedfile na http://localhost:8081..."
18
- :; perl -MIO::Socket::INET -we 'my $topK=3; $SIG{INT}=$SIG{TERM}=sub { exit(0); }; my $s=IO::Socket::INET->new(LocalAddr=>"localhost",LocalPort=>8081,Proto=>"tcp",Listen=>1,ReuseAddr=>1) or die $!; while(my $c=$s->accept) { $c->autoflush(1); my $req=<$c>//""; my ($q)=$req=~/\?q=([^ ]+)/; if(defined $q && $q ne "") { $q=~s/%([0-9A-Fa-f]{2})/chr(hex $1)/eg; $q=~s/[\n+]/ /g; open my $fh, "-|", "./bge-m3.embedfile","search","prosty-rag.db",$q or die $!; my @out=<$fh>; close $fh; @out=@out[0..($topK-1)] if @out > $topK; print $c "HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n",@out; } else { print $c "HTTP/1.0 400 Bad Request\r\nAccess-Control-Allow-Origin: *\r\n\r\nBrak zapytania"; } close $c; }' &
19
  :; echo "Uruchamianie serwera llamafile na http://localhost:8080..."
20
- :; ./$llamafile --server --v2 --prompt "$prompt" --flash-attn 1 $@ 2>&1 | tee $logfile &
21
  :; (tail -f $logfile &) | grep -q "server listen" && echo "Uruchamianie czatu na stronie http://localhost:8080 w przegl膮darce..." && xdg-open "http://localhost:8080" || open "http://localhost:8080"; wait; exit $?
22
  :; # Windows:
23
  @echo off
24
  chcp 65001 >nul
 
25
  setlocal enabledelayedexpansion
26
- set llamafile=prosty-rag.llamafile
27
- set embedfile=bge-m3.embedfile
28
- set dbfile=prosty-rag.db
29
- set indeksator=indeksator.cmd
30
- set logfile=prosty-rag.log
31
- set "prompt=Jeste艣 pomocnym asystentem. Odpowiedz na pytania u偶ytkownika korzystaj膮c z podanego kontekstu, zawieraj膮cego wybrane fragmenty plik贸w. Na ko艅cu podaj odwo艂anie do pliku 藕r贸d艂a. Je艣li nie potrafisz odpowiedzie膰, to napisz to. Nie zmy艣laj."
32
  :; # Instalacja
33
  if not exist %llamafile% echo Pobieranie %llamafile%... && curl -Lo %llamafile% https://huggingface.co/jglowa/prosty-rag/resolve/main/prosty-rag.llamafile?download=true && echo Gotowe^^!
 
34
  if not exist %embedfile% echo Pobieranie %embedfile%... && curl -Lo %embedfile% https://huggingface.co/asg017/embedfile/resolve/refs%%2Fpr%%2F2/bge-m3.embedfile?download=true && echo Gotowe^^!
35
  if not exist %indeksator% echo Pobieranie %indeksator%... && curl -Lo %indeksator% https://huggingface.co/jglowa/prosty-rag/resolve/main/indeksator.cmd?download=true && echo Gotowe^^!
36
  if not exist %dbfile% call %indeksator%
37
  :; # Uruchamianie
38
  break>%logfile%
39
- start cmd /c "powershell -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))""
40
- start cmd /c "echo Uruchamianie serwera llamafile na http://localhost:8080... && %llamafile% --server --v2 --prompt "%prompt%" --flash-attn 1 %* 2>&1 | find /v "" >%logfile%"
41
  :waitForReady
42
  findstr /c:"server listen" %logfile% >nul && echo Uruchamianie czatu na http://localhost:8080 w przegl膮darce... && start http://localhost:8080 || (timeout 1 >nul & goto waitForReady)
43
  endlocal
44
  goto :eof
45
  :; # PowerShell
46
  #> | Out-Null
47
- $topK = 3
48
  Add-Type -AssemblyName System.Web
49
  $OutputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
50
  $listener = [System.Net.HttpListener]::new()
@@ -54,8 +54,8 @@ echo 'Uruchamianie serwera embedfile na http://localhost:8081...'
54
  try {
55
  while ($listener.IsListening) {
56
  $ctx = $listener.GetContext()
57
- $q = ([System.Web.HttpUtility]::ParseQueryString($ctx.Request.Url.Query))['q'] -replace '"', "'" -replace "`n", ' '
58
- $output = if ($q) { cmd /c bge-m3.embedfile search prosty-rag.db $q 2>&1 } else { @('Brak zapytania') }
59
  $response = $output | select-object -first $topK | out-string
60
  $bytes = [Text.Encoding]::UTF8.GetBytes($response)
61
  $ctx.Response.AddHeader('Access-Control-Allow-Origin', '*')
 
1
+ echo \" >/dev/null ">NUL "\" \`" <#"; shopt -s expand_aliases || setopt aliases; alias @set='' @echo='echo'
2
+ @echo Prosty RAG v0.4 - Jerzy Glowacki na licencji Apache 2.0
3
+ :; # Zmienne:
4
+ @set llamafile=prosty-rag.llamafile
5
+ @set modelfile="Prosty RAG - Bielik-4.5B-v3.0-Instruct.gguf"
6
+ @set modelURL=https://huggingface.co/gaianet/Bielik-4.5B-v3.0-Instruct-GGUF/resolve/main/Bielik-4.5B-v3.0-Instruct-Q6_K.gguf?download=true
7
+ @set embedfile=bge-m3.embedfile
8
+ @set dbfile=prosty-rag.db
9
+ @set indeksator=indeksator.cmd
10
+ @set logfile=prosty-rag.log
11
+ @set systemPrompt="Jeste艣 pomocnym asystentem. Odpowiedz szczeg贸艂owo na pytanie u偶ytkownika korzystaj膮c tylko z podanego kontekstu, zawieraj膮cego wybrane fragmenty plik贸w. Na ko艅cu odpowiedzi podaj odwo艂anie do pliku 藕r贸d艂a. Je艣li nie uda艂o ci si臋 odpowiedzie膰 na pytanie na podstawie kontekstu, to napisz to. Nie zmy艣laj."
12
+ @set topK=3
13
  :; # *NIX:
 
 
 
 
 
 
14
  :; # Instalacja
15
  :; [ ! -f $llamafile ] && echo Pobieranie $llamafile... && curl -Lo $llamafile https://huggingface.co/jglowa/prosty-rag/resolve/main/prosty-rag.llamafile?download=true && chmod +x $llamafile && echo Gotowe!
16
+ :; [ ! -f "$modelfile" ] && echo Pobieranie $modelfile... && curl -Lo "$modelfile" $modelURL && echo Gotowe!
17
  :; [ ! -f $embedfile ] && echo Pobieranie $embedfile... && curl -Lo $embedfile https://huggingface.co/asg017/embedfile/resolve/refs%2Fpr%2F2/bge-m3.embedfile?download=true && chmod +x $embedfile && echo Gotowe!
18
  :; [ ! -f $indeksator ] && echo Pobieranie $indeksator... && curl -Lo $indeksator https://huggingface.co/jglowa/prosty-rag/resolve/main/indeksator.cmd?download=true && chmod +x $indeksator && echo Gotowe!
19
  :; [ ! -f $dbfile ] && ./$indeksator
20
  :; # Uruchamianie
21
  :; >$logfile
22
  :; echo "Uruchamianie serwera embedfile na http://localhost:8081..."
23
+ :; perl -MIO::Socket::INET -e 'my $topK=shift; $SIG{INT}=$SIG{TERM}=sub { exit(0); }; my $s=IO::Socket::INET->new(LocalAddr=>"localhost",LocalPort=>8081,Proto=>"tcp",Listen=>1,ReuseAddr=>1) or die $!; while(my $c=$s->accept) { $c->autoflush(1); my $req=<$c>//""; my ($q)=$req=~/\?q=([^ ]+)/; if(defined $q && $q ne "") { $q=~s/%([0-9A-Fa-f]{2})/chr(hex $1)/eg; $q=~s/[\n+]/ /g; $q=~s/['\''"]//g; open my $fh, "-|", "./bge-m3.embedfile","sh","prosty-rag.db","-separator"," ",".param init",".param set :q '\''\"$q\"'\''",".param set :k $topK","WITH vm AS (SELECT rowid, ROW_NUMBER() OVER (ORDER BY distance) vec_rank FROM vec_items WHERE line_embedding MATCH lembed(:q) AND k=:k), fm AS (SELECT rowid, ROW_NUMBER() OVER (ORDER BY rank) fts_rank FROM fts_items WHERE fts_items MATCH :q LIMIT :k) SELECT items.rowid, COALESCE(1.0/(60+vm.vec_rank),0) + COALESCE(1.0/(60+fm.fts_rank),0) AS rrf_score, items.line FROM items LEFT JOIN vm ON items.rowid = vm.rowid LEFT JOIN fm ON items.rowid = fm.rowid ORDER BY rrf_score DESC LIMIT :k" or die $!; my @out=<$fh>; close $fh; print $c "HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n",@out; } else { print $c "HTTP/1.0 400 Bad Request\r\nAccess-Control-Allow-Origin: *\r\n\r\nBrak zapytania"; } close $c; }' $topK &
24
  :; echo "Uruchamianie serwera llamafile na http://localhost:8080..."
25
+ :; ./$llamafile --server --v2 -m "$modelfile" --prompt "$systemPrompt" --flash-attn 1 $@ 2>&1 | tee $logfile &
26
  :; (tail -f $logfile &) | grep -q "server listen" && echo "Uruchamianie czatu na stronie http://localhost:8080 w przegl膮darce..." && xdg-open "http://localhost:8080" || open "http://localhost:8080"; wait; exit $?
27
  :; # Windows:
28
  @echo off
29
  chcp 65001 >nul
30
+ title Prosty RAG
31
  setlocal enabledelayedexpansion
 
 
 
 
 
 
32
  :; # Instalacja
33
  if not exist %llamafile% echo Pobieranie %llamafile%... && curl -Lo %llamafile% https://huggingface.co/jglowa/prosty-rag/resolve/main/prosty-rag.llamafile?download=true && echo Gotowe^^!
34
+ if not exist %modelfile% echo Pobieranie %modelfile%... && curl -Lo %modelfile% %modelURL% && echo Gotowe^^!
35
  if not exist %embedfile% echo Pobieranie %embedfile%... && curl -Lo %embedfile% https://huggingface.co/asg017/embedfile/resolve/refs%%2Fpr%%2F2/bge-m3.embedfile?download=true && echo Gotowe^^!
36
  if not exist %indeksator% echo Pobieranie %indeksator%... && curl -Lo %indeksator% https://huggingface.co/jglowa/prosty-rag/resolve/main/indeksator.cmd?download=true && echo Gotowe^^!
37
  if not exist %dbfile% call %indeksator%
38
  :; # Uruchamianie
39
  break>%logfile%
40
+ start "Prosty RAG - embedfile" cmd /c "powershell -Command "$topK=%topK%; iex $([System.IO.File]::ReadAllText('%~f0'))""
41
+ start "Prosty RAG - llamafile" cmd /c "echo Uruchamianie serwera llamafile na http://localhost:8080... && %llamafile% --server --v2 -m %modelfile% --prompt %systemPrompt% --flash-attn 1 %* 2>&1 | find /v "" >%logfile%"
42
  :waitForReady
43
  findstr /c:"server listen" %logfile% >nul && echo Uruchamianie czatu na http://localhost:8080 w przegl膮darce... && start http://localhost:8080 || (timeout 1 >nul & goto waitForReady)
44
  endlocal
45
  goto :eof
46
  :; # PowerShell
47
  #> | Out-Null
 
48
  Add-Type -AssemblyName System.Web
49
  $OutputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
50
  $listener = [System.Net.HttpListener]::new()
 
54
  try {
55
  while ($listener.IsListening) {
56
  $ctx = $listener.GetContext()
57
+ $q = ([System.Web.HttpUtility]::ParseQueryString($ctx.Request.Url.Query))['q'] -replace "['`"]", '' -replace "`n", ' '
58
+ $output = if ($q) { cmd /c bge-m3.embedfile sh prosty-rag.db -separator " " ".param init" ".param set :q '\`"$q\`"'" ".param set :k $topK" "WITH vm AS (SELECT rowid, ROW_NUMBER() OVER (ORDER BY distance) vec_rank FROM vec_items WHERE line_embedding MATCH lembed(:q) AND k=:k), fm AS (SELECT rowid, ROW_NUMBER() OVER (ORDER BY rank) fts_rank FROM fts_items WHERE fts_items MATCH :q LIMIT :k) SELECT items.rowid, COALESCE(1.0/(60+vm.vec_rank),0) + COALESCE(1.0/(60+fm.fts_rank),0) AS rrf_score, items.line FROM items LEFT JOIN vm ON items.rowid = vm.rowid LEFT JOIN fm ON items.rowid = fm.rowid ORDER BY rrf_score DESC LIMIT :k" } else { @('Brak zapytania') }
59
  $response = $output | select-object -first $topK | out-string
60
  $bytes = [Text.Encoding]::UTF8.GetBytes($response)
61
  $ctx.Response.AddHeader('Access-Control-Allow-Origin', '*')