CaiRou-Huang commited on
Commit
226d537
1 Parent(s): 9f7ef53

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -0
main.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ctransformers import AutoModelForCausalLM
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ llm = AutoModelForCausalLM.from_pretrained("zephyr-7b-beta.Q4_K_S.gguf",
5
+ model_type='mistral',
6
+ max_new_tokens = 1096,
7
+ threads = 3,
8
+ )
9
+ #Pydantic object
10
+ class validation(BaseModel):
11
+ prompt: str
12
+ #Fast API
13
+ app = FastAPI()
14
+ @app.post("/llm_on_cpu")
15
+ async def stream(item: validation):
16
+ system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
17
+ E_INST = "</s>"
18
+ user, assistant = "<|user|>", "<|assistant|>"
19
+ prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt}{E_INST}\n{assistant}\n"
20
+ return llm(prompt)