File size: 1,110 Bytes
5dab16f
 
 
 
4e06fbd
4058833
2598edb
7bf48ef
4e06fbd
5dab16f
 
 
 
 
 
4e06fbd
5dab16f
 
4e06fbd
 
5dab16f
 
7bf48ef
1b6640a
92b0d2a
 
 
 
1b6640a
92b0d2a
5dab16f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from ctransformers import AutoModelForCausalLM
from fastapi import FastAPI, Form
from pydantic import BaseModel

#Model loading
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7B-Chat-GGUF",
model_type='llama',
max_new_tokens = 4096,
threads = 3,
)
   

#Pydantic object
class validation(BaseModel):
    prompt: str
    
#Fast API
app = FastAPI()

#Zephyr completion
@app.post("/llm_on_cpu")
async def stream(item: validation):
    system_prompt = "You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.  Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."
    prompt = f'''
    [INST] <<SYS>>
    {system_prompt}
    <</SYS>>
    {item.prompt.strip()}[/INST]
    '''
    
    return llm(prompt)