CoruNethron commited on
Commit
c72165a
·
verified ·
1 Parent(s): c0c5b08

Update olapp.py

Browse files
Files changed (1) hide show
  1. olapp.py +40 -2
olapp.py CHANGED
@@ -1,6 +1,37 @@
1
  from http.server import HTTPServer, BaseHTTPRequestHandler
2
  from urllib.parse import urlparse
3
  import json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  class OlHandler(BaseHTTPRequestHandler):
6
 
@@ -8,10 +39,17 @@ class OlHandler(BaseHTTPRequestHandler):
8
  query = urlparse(self.path).query
9
  query_components = dict(qc.split("=") for qc in query.split("&"))
10
  q = query_components["q"]
11
- message = '-=# ' + q + ' #=-'
 
 
 
 
 
 
 
12
  self.send_response(200)
13
  self.end_headers()
14
- self.wfile.write(message.encode('utf-8'))
15
  return
16
 
17
 
 
1
  from http.server import HTTPServer, BaseHTTPRequestHandler
2
  from urllib.parse import urlparse
3
  import json
4
+ from huggingface_hub.file_download import http_get
5
+ from llama_cpp import Llama
6
+
7
+
8
+ directory = "."
9
+ model_url = "https://huggingface.co/IlyaGusev/saiga_mistral_7b_gguf/resolve/main/model-q8_0.gguf"
10
+ model_name = "model-q8_0.gguf"
11
+ final_model_path = os.path.join(directory, model_name)
12
+
13
+ print("Downloading all files...")
14
+ rm_files = [os.path.join(directory, f) for f in os.listdir(directory)]
15
+ for f in rm_files:
16
+ if os.path.isfile(f):
17
+ os.remove(f)
18
+ else:
19
+ shutil.rmtree(f)
20
+
21
+ if not os.path.exists(final_model_path):
22
+ with open(final_model_path, "wb") as f:
23
+ http_get(model_url, f)
24
+ os.chmod(final_model_path, 0o777)
25
+ print("Files downloaded!")
26
+
27
+ model = Llama(
28
+ model_path=final_model_path,
29
+ n_ctx=4096,
30
+ n_parts=1,
31
+ )
32
+
33
+ print("Model loaded!")
34
+
35
 
36
  class OlHandler(BaseHTTPRequestHandler):
37
 
 
39
  query = urlparse(self.path).query
40
  query_components = dict(qc.split("=") for qc in query.split("&"))
41
  q = query_components["q"]
42
+ # message = '-=# ' + q + ' #=-'
43
+
44
+ output = llm(
45
+ q,
46
+ max_tokens=32, # Generate up to 32 tokens
47
+ echo=False
48
+ )
49
+
50
  self.send_response(200)
51
  self.end_headers()
52
+ self.wfile.write(output.encode('utf-8'))
53
  return
54
 
55