moraxgiga commited on
Commit
98498bd
1 Parent(s): 39b2182

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +42 -42
server.py CHANGED
@@ -1,43 +1,43 @@
1
-
2
- import litserve as ls
3
- from typing import List, Dict, Any
4
- from llama_cpp import Llama
5
- from fastapi import Depends, HTTPException
6
- from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
7
-
8
-
9
- class SimpleLitAPI(ls.LitAPI):
10
- def setup(self, device):
11
- self.llm = Llama(
12
- model_path="Llama-3.2-1B-Instruct-Q4_K_M.gguf",
13
- verbose=False
14
- )
15
- def decode_request(self, request):
16
- return request
17
-
18
- def predict(self, input):
19
- temperature = input.get("temperature", 1.0)
20
- max_tokens = input.get("max_tokens", 100)
21
- top_k = input.get("top_k", 50)
22
- top_p = input.get("top_p", 0.9)
23
- repeat_penalty = input.get("repeat_penalty", 1.0)
24
- return self.llm.create_chat_completion(
25
- messages=input["messages"],
26
- temperature=temperature,
27
- max_tokens=max_tokens,
28
- top_k=top_k,
29
- top_p=top_p,
30
- repeat_penalty=repeat_penalty,
31
- )
32
-
33
- def encode_response(self, output):
34
- return {"output": output}
35
-
36
- def authorize(self, auth: HTTPAuthorizationCredentials = Depends(HTTPBearer())):
37
- if auth.scheme != "Bearer" or auth.credentials != "1234":
38
- raise HTTPException(status_code=401, detail="Bad token")
39
-
40
- if __name__ == "__main__":
41
- api = SimpleLitAPI()
42
- server = ls.LitServer(api, accelerator="cpu", devices=2, workers_per_device=2)
43
  server.run(port=7860)
 
1
+
2
+ import litserve as ls
3
+ from typing import List, Dict, Any
4
+ from llama_cpp import Llama
5
+ from fastapi import Depends, HTTPException
6
+ from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
7
+
8
+
9
+ class SimpleLitAPI(ls.LitAPI):
10
+ def setup(self, device):
11
+ self.llm = Llama(
12
+ model_path="Llama-3.2-1B-Instruct-Q4_K_M.gguf",
13
+ verbose=False
14
+ )
15
+ def decode_request(self, request):
16
+ return request
17
+
18
+ def predict(self, input):
19
+ temperature = input.get("temperature", 1.0)
20
+ max_tokens = input.get("max_tokens", 100)
21
+ top_k = input.get("top_k", 50)
22
+ top_p = input.get("top_p", 0.9)
23
+ repeat_penalty = input.get("repeat_penalty", 1.0)
24
+ return self.llm.create_chat_completion(
25
+ messages=input["messages"],
26
+ temperature=temperature,
27
+ max_tokens=max_tokens,
28
+ top_k=top_k,
29
+ top_p=top_p,
30
+ repeat_penalty=repeat_penalty,
31
+ )
32
+
33
+ def encode_response(self, output):
34
+ return {"output": output}
35
+
36
+ def authorize(self, auth: HTTPAuthorizationCredentials = Depends(HTTPBearer())):
37
+ if auth.scheme != "Bearer" or auth.credentials != "1234":
38
+ raise HTTPException(status_code=401, detail="Bad token")
39
+
40
+ if __name__ == "__main__":
41
+ api = SimpleLitAPI()
42
+ server = ls.LitServer(api, accelerator="cpu")
43
  server.run(port=7860)