Update main.py
Browse files
main.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
from fastapi import FastAPI, Form
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from pydantic import BaseModel
|
4 |
-
from
|
5 |
|
6 |
-
#
|
7 |
-
llm = AutoModelForCausalLM.from_pretrained(
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
threads=3,
|
12 |
)
|
|
|
13 |
|
14 |
-
#
|
15 |
-
class
|
16 |
prompt: str
|
17 |
-
|
18 |
-
#
|
19 |
app = FastAPI()
|
20 |
|
21 |
# Set up CORS
|
@@ -32,11 +32,11 @@ app.add_middleware(
|
|
32 |
allow_headers=["*"],
|
33 |
)
|
34 |
|
35 |
-
#
|
36 |
@app.post("/llm_on_cpu")
|
37 |
-
async def stream(item:
|
38 |
system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
|
39 |
E_INST = "</s>"
|
40 |
-
user, assistant = "", ""
|
41 |
prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
|
42 |
return llm(prompt)
|
|
|
1 |
from fastapi import FastAPI, Form
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from pydantic import BaseModel
|
4 |
+
from ctransformers import AutoModelForCausalLM
|
5 |
|
6 |
+
#Model loading
|
7 |
+
llm = AutoModelForCausalLM.from_pretrained("zephyr-7b-beta.Q4_K_S.gguf",
|
8 |
+
model_type='mistral',
|
9 |
+
max_new_tokens = 1096,
|
10 |
+
threads = 3,
|
|
|
11 |
)
|
12 |
+
|
13 |
|
14 |
+
#Pydantic object
|
15 |
+
class validation(BaseModel):
|
16 |
prompt: str
|
17 |
+
|
18 |
+
#Fast API
|
19 |
app = FastAPI()
|
20 |
|
21 |
# Set up CORS
|
|
|
32 |
allow_headers=["*"],
|
33 |
)
|
34 |
|
35 |
+
#Zephyr completion
|
36 |
@app.post("/llm_on_cpu")
|
37 |
+
async def stream(item: validation):
|
38 |
system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
|
39 |
E_INST = "</s>"
|
40 |
+
user, assistant = "<|user|>", "<|assistant|>"
|
41 |
prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
|
42 |
return llm(prompt)
|